Skip to content

Commit 5e72fab

Browse files
committed
ci/templates: properly propagate error
1 parent c2168a2 commit 5e72fab

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

.github/workflows/issue-linker.yml

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ jobs:
3232
with:
3333
script: |
3434
let issueNumber, issueData;
35-
35+
3636
if (context.eventName === 'workflow_dispatch') {
3737
issueNumber = '${{ inputs.issue_number }}';
38-
39-
38+
39+
4040
const response = await github.rest.issues.get({
4141
owner: context.repo.owner,
4242
repo: context.repo.repo,
@@ -47,52 +47,45 @@ jobs:
4747
issueData = context.payload.issue;
4848
issueNumber = issueData?.number;
4949
}
50-
50+
5151
const body = issueData.body || '';
5252
const childId = issueData.node_id;
53-
53+
5454
const parentMatch = body.match(/Parent Story[\s\S]*?#(\d+)/i)
5555
|| body.match(/Parent Epic[\s\S]*?#(\d+)/i);
56-
57-
if (!parentMatch) {
58-
console.log('No parent story found, skipping.');
59-
return;
56+
57+
const inputParentNumber = '${{ inputs.parent_number }}';
58+
59+
if (!parentMatch && !inputParentNumber) {
60+
throw new Error('No parent issue found in body and no parent_number input provided');
6061
}
61-
62-
const parentNumber = '${{ inputs.parent_number }}' || parseInt(parentMatch[1]);
62+
63+
const parentNumber = inputParentNumber || parseInt(parentMatch[1]);
6364
const owner = context.repo.owner;
6465
const repo = context.repo.repo;
65-
66+
6667
console.log(`Linking task #${issueNumber} to parent #${parentNumber}`);
67-
68-
try {
69-
const parentResponse = await github.rest.issues.get({
70-
owner,
71-
repo,
72-
issue_number: parentNumber
73-
});
74-
const parentNodeId = parentResponse.data.node_id;
75-
76-
const mutation = `
77-
mutation {
78-
addSubIssue(input: {
79-
issueId: "${parentNodeId}"
80-
subIssueId: "${childId}"
81-
}) {
82-
issue {
83-
number
84-
}
68+
69+
const parentResponse = await github.rest.issues.get({
70+
owner,
71+
repo,
72+
issue_number: parentNumber
73+
});
74+
const parentNodeId = parentResponse.data.node_id;
75+
76+
const mutation = `
77+
mutation {
78+
addSubIssue(input: {
79+
issueId: "${parentNodeId}"
80+
subIssueId: "${childId}"
81+
}) {
82+
issue {
83+
number
8584
}
8685
}
87-
`;
88-
89-
await github.graphql(mutation);
90-
91-
console.log(`Successfully linked #${issueNumber} as sub-issue of #${parentNumber}`);
92-
} catch (error) {
93-
console.error(`Error linking to parent: ${error.message}`);
94-
95-
if (error.status === 404) {
96-
console.error(`Parent issue #${parentNumber} not found`);
9786
}
98-
}
87+
`;
88+
89+
await github.graphql(mutation);
90+
91+
console.log(`Successfully linked #${issueNumber} as sub-issue of #${parentNumber}`);

0 commit comments

Comments
 (0)