ci/templates: properly propagate error #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto-link sub-issue to parent issue | ||
|
Check failure on line 1 in .github/workflows/issue-linker.yml
|
||
| on: | ||
| issues: | ||
| types: [opened, labeled] | ||
| workflow_dispatch: | ||
| inputs: | ||
| issue_number: | ||
| description: 'Issue number to link to parent' | ||
| required: true | ||
| type: number | ||
| parent_number: | ||
| description: 'Parent issue number' | ||
| required: false | ||
| type: number | ||
| jobs: | ||
| link-to-parent: | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| (github.event_name == 'workflow_dispatch') | ||
| || (github.event_name == 'issues' && ( | ||
| contains(toJson(github.event.issue.labels.*.name), '"0. layer: task"') | ||
| contains(toJson(github.event.issue.labels.*.name), '"0. layer: story"') | ||
| )) | ||
| permissions: | ||
| issues: write | ||
| steps: | ||
| - name: Link to Parent issue as Sub-issue | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| let issueNumber, issueData; | ||
| if (context.eventName === 'workflow_dispatch') { | ||
| issueNumber = '${{ inputs.issue_number }}'; | ||
| const response = await github.rest.issues.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueNumber | ||
| }); | ||
| issueData = response.data; | ||
| } else { | ||
| issueData = context.payload.issue; | ||
| issueNumber = issueData?.number; | ||
| } | ||
| const body = issueData.body || ''; | ||
| const childId = issueData.node_id; | ||
| const parentMatch = body.match(/Parent Story[\s\S]*?#(\d+)/i) | ||
| || body.match(/Parent Epic[\s\S]*?#(\d+)/i); | ||
| const inputParentNumber = '${{ inputs.parent_number }}'; | ||
| if (!parentMatch && !inputParentNumber) { | ||
| throw new Error('No parent issue found in body and no parent_number input provided'); | ||
| } | ||
| const parentNumber = inputParentNumber || parseInt(parentMatch[1]); | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| console.log(`Linking task #${issueNumber} to parent #${parentNumber}`); | ||
| const parentResponse = await github.rest.issues.get({ | ||
| owner, | ||
| repo, | ||
| issue_number: parentNumber | ||
| }); | ||
| const parentNodeId = parentResponse.data.node_id; | ||
| const mutation = ` | ||
| mutation { | ||
| addSubIssue(input: { | ||
| issueId: "${parentNodeId}" | ||
| subIssueId: "${childId}" | ||
| }) { | ||
| issue { | ||
| number | ||
| } | ||
| } | ||
| } | ||
| `; | ||
| await github.graphql(mutation); | ||
| console.log(`Successfully linked #${issueNumber} as sub-issue of #${parentNumber}`); | ||