From 0d4e5f48e91a7ca5d28f4efef8d16936beaa3ec1 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 4 Aug 2025 12:57:44 -0700 Subject: [PATCH] Auto assign issues based on `component:*` label (#2063) --- .github/component_owners.yml | 6 +- .github/workflows/assign-issue-owners.yml | 75 +++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/assign-issue-owners.yml diff --git a/.github/component_owners.yml b/.github/component_owners.yml index d732f3e0..1e4c90e1 100644 --- a/.github/component_owners.yml +++ b/.github/component_owners.yml @@ -1,14 +1,14 @@ -# this file is used by .github/workflows/assign-reviewers.yml +# this file is used by .github/workflows/assign-reviewers.yml and .github/workflows/assign-issue-owners.yml # # NOTE component owners must be members of the GitHub OpenTelemetry organization # so that they can be added to @open-telemetry/java-contrib-triagers -# which in turn is required for them to be auto-assigned as reviewers by the automation +# which in turn is required for them to be auto-assigned as reviewers and issue assignees by the automation # # NOTE when updating this file, don't forget to update the README.md files in the associated # components also # # NOTE when adding/updating one of the component names, don't forget to update the associated -# `comp:*` labels +# `component:*` labels (used for both PR reviews and issue assignment) components: aws-resources: - wangzlei diff --git a/.github/workflows/assign-issue-owners.yml b/.github/workflows/assign-issue-owners.yml new file mode 100644 index 00000000..085eeb6f --- /dev/null +++ b/.github/workflows/assign-issue-owners.yml @@ -0,0 +1,75 @@ +--- +name: Assign issue owners + +on: + issues: + types: [labeled] + +permissions: + contents: read + +jobs: + assign-owners: + permissions: + contents: read + issues: write + runs-on: ubuntu-latest + if: startsWith(github.event.label.name, 'component:') + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + + - name: Parse component label and assign owners + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + const fs = require('fs'); + const yaml = require('js-yaml'); + + // Extract component name from label + const labelName = context.payload.label.name; + + if (!labelName.startsWith('component:')) { + core.setFailed('Label does not match expected pattern'); + return; + } + + const componentName = labelName.replace('component:', ''); + console.log(`Processing component: ${componentName}`); + + // Read and parse component_owners.yml + const yamlContent = fs.readFileSync('.github/component_owners.yml', 'utf8'); + const data = yaml.load(yamlContent); + + if (!data || !data.components) { + core.setFailed('Invalid component_owners.yml structure'); + return; + } + + const components = data.components; + + if (!(componentName in components)) { + core.setFailed(`Component '${componentName}' not found in component_owners.yml`); + return; + } + + const owners = components[componentName]; + + if (!owners || owners.length === 0) { + core.setFailed(`No owners found for component '${componentName}'`); + return; + } + + console.log(`Found owners: ${owners.join(', ')}`); + + // Assign the issue to the owners + const issueNumber = context.payload.issue.number; + + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + assignees: owners + }); + + console.log(`Successfully assigned issue #${issueNumber} to ${owners.join(', ')}`);