Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add stack label if available, make get-changes composite action (#786)
Madison Swain-Bowdenbc60edc64fe3
diff --git a/.github/actions/get-changes/action.yml b/.github/actions/get-changes/action.ymlnew file mode 100644index 000000000..99c551d6c--- /dev/null+++ b/.github/actions/get-changes/action.yml@@ -0,0 +1,25 @@+name: openverse/get-changes+description: Determine where changes happened in the repository++outputs:+ api:+ description: "'true' if API changes are present"+ value: ${{ steps.paths-filter.outputs.api }}+ ingestion_server:+ description: "'true' if ingestion server changes are present"+ value: ${{ steps.paths-filter.outputs.ingestion_server }}+ frontend:+ description: "'true' if frontend changes are present"+ value: ${{ steps.paths-filter.outputs.frontend }}++runs:+ using: "composite"+ steps:+ - name: Checkout repository+ uses: actions/checkout@v3++ - id: paths-filter+ name: Check changed paths+ uses: dorny/paths-filter@v2+ with:+ filters: ./.github/filters.ymldiff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex 98256f177..22bf673af 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -36,16 +36,12 @@ jobs:api: ${{ steps.paths-filter.outputs.api }}ingestion_server: ${{ steps.paths-filter.outputs.ingestion_server }}frontend: ${{ steps.paths-filter.outputs.frontend }}-steps:- name: Checkout repositoryuses: actions/checkout@v3-- - id: paths-filter- name: Check changed paths- uses: dorny/paths-filter@v2- with:- filters: ./.github/filters.yml+ - name: Get changes+ uses: ./.github/actions/get-changes+ id: paths-filterget-image-tag:name: Get image tag@@ -97,6 +93,34 @@ jobs:just precommitjust lint+ add-stack-label:+ name: Add stack label+ runs-on: ubuntu-latest+ needs:+ - get-changes++ steps:+ - name: Checkout repository+ uses: actions/checkout@v3++ - name: Add API stack label+ uses: actions-ecosystem/action-add-labels@v1+ if: ${{ needs.get-changes.outputs.api == 'true' }}+ with:+ labels: "🧱 stack: api"++ - name: Add ingestion server stack label+ uses: actions-ecosystem/action-add-labels@v1+ if: ${{ needs.get-changes.outputs.ingestion_server == 'true' }}+ with:+ labels: "🧱 stack: ingestion server"++ - name: Add frontend stack label+ uses: actions-ecosystem/action-add-labels@v1+ if: ${{ needs.get-changes.outputs.frontend == 'true' }}+ with:+ labels: "🧱 stack: frontend"+############################# API and ingestion server #############################diff --git a/.github/workflows/pr_label_check.yml b/.github/workflows/pr_label_check.ymlindex 3338d5ebc..bab1a5e0d 100644--- a/.github/workflows/pr_label_check.yml+++ b/.github/workflows/pr_label_check.yml@@ -43,3 +43,13 @@ jobs:with:one_of: "🟩 priority: low,🟨 priority: medium,🟧 priority: high,🟥 priority: critical"repo_token: ${{ secrets.GITHUB_TOKEN }}++ check_stack_label:+ name: Check stack label+ runs-on: ubuntu-latest+ steps:+ - name: Check stack label+ uses: docker://agilepathway/pull-request-label-checker:v1.2.13+ with:+ any_of: "🧱 stack: backend,🧱 stack: frontend,🧱 stack: mgmt,🧱 stack: api,🧱 stack: catalog,🧱 stack: ingestion server"+ repo_token: ${{ secrets.GITHUB_TOKEN }}diff --git a/automations/python/label_pr.py b/automations/python/label_pr.pyindex 2b08cf201..6bea6d33f 100644--- a/automations/python/label_pr.py+++ b/automations/python/label_pr.py@@ -22,6 +22,10 @@ from shared.log import configure_loggerlog = logging.getLogger(__name__)+REQUIRED_LABEL_CATEGORIES = ["aspect", "priority", "goal", "stack"]+# Categories where all labels should be retrievd rather than first only+GET_ALL_LABEL_CATEGORIES = {"stack"}+# region argparseparser = argparse.ArgumentParser(description="")parser.add_argument(@@ -144,6 +148,22 @@ def get_linked_issues(url: str) -> list[str]:return [a["href"] for a in form.find_all("a")]+def get_all_labels_of_cat(cat: str, labels: list[Label]) -> list[Label]:+ """+ Get all of the available labels from a category from a given list of+ labels.++ :param cat: the category to which the label should belong+ :param labels: the list of labels to choose from+ :return: the labels matching the given category+ """+ available_labels = []+ for label in labels:+ if cat in label.name:+ available_labels.append(label)+ return available_labels++def get_label_of_cat(cat: str, labels: list[Label]) -> Label | None:"""Get the label of a particular category from the given list of labels.@@ -152,11 +172,7 @@ def get_label_of_cat(cat: str, labels: list[Label]) -> Label | None::param labels: the list of labels to choose from:return: the label matching the given category"""-- for label in labels:- if cat in label.name:- return label- return None+ return next(iter(get_all_labels_of_cat(cat, labels)), None)def main():@@ -185,18 +201,25 @@ def main():for issue in linked_issues:issue = get_issue(gh, issue)labels = issue.labels- if all(- [- (aspect := get_label_of_cat("aspect", labels)),- (priority := get_label_of_cat("priority", labels)),- (goal := get_label_of_cat("goal", labels)),- ]- ):- log.info(f"Aspect label: {aspect}")- log.info(f"Priority label: {priority}")- log.info(f"Goal label: {goal}")- pr.set_labels(aspect, priority, goal)- break+ labels_to_add = []++ for category in REQUIRED_LABEL_CATEGORIES:+ if category in GET_ALL_LABEL_CATEGORIES and (+ available_labels := get_all_labels_of_cat(category, labels)+ ):+ log.info(f"Found labels for category {category}: {available_labels}")+ labels_to_add.extend(available_labels)+ elif label := get_label_of_cat(category, labels):+ log.info(f"Found label for category {category}: {label}")+ labels_to_add.append(label)++ if labels_to_add:+ pr.set_labels(*labels_to_add)+ # 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):+ breakelse:log.info("Could not find properly labelled issue")pr.set_labels("🚦 status: awaiting triage")