Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Use label.yml to determine required labels (#1063)

Tomvth184cac6c446c
diff --git a/automations/data/labels.yml b/automations/data/labels.yml
index b0a3b9ba6..7eca917aa 100644
--- a/automations/data/labels.yml
+++ b/automations/data/labels.yml
@@ -86,6 +86,7 @@ groups:
color: "006b75"
emoji: "🧱"
is_required: true
+ apply_all_available: true
labels:
- name: frontend
description: Related to the Nuxt frontend
diff --git a/automations/python/label_pr.py b/automations/python/label_pr.py
index af1bfc04c..16a502eb2 100644
--- a/automations/python/label_pr.py
+++ b/automations/python/label_pr.py
@@ -22,10 +22,6 @@ from shared.log import configure_logger
log = logging.getLogger(__name__)
-REQUIRED_LABEL_CATEGORIES = ["aspect", "priority", "goal", "stack"]
-# Categories where all labels should be retrieved rather than first only
-GET_ALL_LABEL_CATEGORIES = {"stack"}
-
# region argparse
parser = argparse.ArgumentParser(description="")
parser.add_argument(
@@ -182,6 +178,16 @@ def main():
log.debug(f"PR URL: {args.pr_url}")
+ label_info = get_data("labels.yml")
+ label_groups = label_info["groups"]
+ required_label_categories = [
+ i.get("name") for i in label_groups if i.get("is_required")
+ ]
+ # Categories where all labels should be retrieved rather than first only
+ categories_with_all_labels = [
+ i.get("name") for i in label_groups if i.get("apply_all_available")
+ ]
+
github_info = get_data("github.yml")
org_handle = github_info["org"]
log.info(f"Organization handle: {org_handle}")
@@ -203,8 +209,8 @@ def main():
labels = issue.labels
labels_to_add = []
- for category in REQUIRED_LABEL_CATEGORIES:
- if category in GET_ALL_LABEL_CATEGORIES and (
+ for category in required_label_categories:
+ if category in categories_with_all_labels and (
available_labels := get_all_labels_of_cat(category, labels)
):
log.info(f"Found labels for category {category}: {available_labels}")
@@ -218,7 +224,7 @@ def main():
# Only break when all labels are applied, if we're missing any
# then continue to the else to apply the awaiting triage label.
# Stack can have more than one label so this is not an exact check
- if len(labels_to_add) >= len(REQUIRED_LABEL_CATEGORIES):
+ if len(labels_to_add) >= len(required_label_categories):
break
else:
log.info("Could not find properly labelled issue")
diff --git a/automations/python/shared/data.py b/automations/python/shared/data.py
index 844564ae5..3430a5ae1 100644
--- a/automations/python/shared/data.py
+++ b/automations/python/shared/data.py
@@ -24,4 +24,4 @@ def get_data(file_name: str) -> dict:
data_file: str = str(ROOT_DIR.joinpath("data", file_name))
log.info(f"Reading file {data_file}")
- return yaml.safe_load(open(data_file))
+ return yaml.safe_load(open(data_file, encoding="utf-8"))