|
| 1 | +--- |
| 2 | +name: Assign issue owners |
| 3 | + |
| 4 | +on: |
| 5 | + issues: |
| 6 | + types: [labeled] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + assign-owners: |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + issues: write |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: startsWith(github.event.label.name, 'component:') |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 21 | + |
| 22 | + - name: Parse component label and assign owners |
| 23 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + const fs = require('fs'); |
| 27 | + const yaml = require('js-yaml'); |
| 28 | +
|
| 29 | + // Extract component name from label |
| 30 | + const labelName = context.payload.label.name; |
| 31 | +
|
| 32 | + if (!labelName.startsWith('component:')) { |
| 33 | + core.setFailed('Label does not match expected pattern'); |
| 34 | + return; |
| 35 | + } |
| 36 | +
|
| 37 | + const componentName = labelName.replace('component:', ''); |
| 38 | + console.log(`Processing component: ${componentName}`); |
| 39 | +
|
| 40 | + // Read and parse component_owners.yml |
| 41 | + const yamlContent = fs.readFileSync('.github/component_owners.yml', 'utf8'); |
| 42 | + const data = yaml.load(yamlContent); |
| 43 | +
|
| 44 | + if (!data || !data.components) { |
| 45 | + core.setFailed('Invalid component_owners.yml structure'); |
| 46 | + return; |
| 47 | + } |
| 48 | +
|
| 49 | + const components = data.components; |
| 50 | +
|
| 51 | + if (!(componentName in components)) { |
| 52 | + core.setFailed(`Component '${componentName}' not found in component_owners.yml`); |
| 53 | + return; |
| 54 | + } |
| 55 | +
|
| 56 | + const owners = components[componentName]; |
| 57 | +
|
| 58 | + if (!owners || owners.length === 0) { |
| 59 | + core.setFailed(`No owners found for component '${componentName}'`); |
| 60 | + return; |
| 61 | + } |
| 62 | +
|
| 63 | + console.log(`Found owners: ${owners.join(', ')}`); |
| 64 | +
|
| 65 | + // Assign the issue to the owners |
| 66 | + const issueNumber = context.payload.issue.number; |
| 67 | +
|
| 68 | + await github.rest.issues.addAssignees({ |
| 69 | + owner: context.repo.owner, |
| 70 | + repo: context.repo.repo, |
| 71 | + issue_number: issueNumber, |
| 72 | + assignees: owners |
| 73 | + }); |
| 74 | +
|
| 75 | + console.log(`Successfully assigned issue #${issueNumber} to ${owners.join(', ')}`); |
0 commit comments