Skip to content

Commit

Permalink
Use label.yml to determine required labels (#1063)
Browse files Browse the repository at this point in the history
Co-authored-by: Dhruv Bhanushali <[email protected]>
  • Loading branch information
Tomvth and dhruvkb authored Mar 31, 2023
1 parent 1a58c9c commit 184cac6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions automations/data/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ groups:
color: "006b75"
emoji: "🧱"
is_required: true
apply_all_available: true
labels:
- name: frontend
description: Related to the Nuxt frontend
Expand Down
20 changes: 13 additions & 7 deletions automations/python/label_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@

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(
Expand Down Expand Up @@ -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}")
Expand All @@ -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}")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion automations/python/shared/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

0 comments on commit 184cac6

Please sign in to comment.