1- name : Sync PR Metadata from Linked Issues
1+ name : Sync PR data from Linked Issues
22
33on :
44 pull_request :
@@ -21,16 +21,21 @@ jobs:
2121 script : |
2222 const body = context.payload.pull_request.body || "";
2323 const issuePattern = /#(\d+)/g;
24- const matches = [...body.matchAll(issuePattern)];
25- const issueNumbers = matches.map(m => parseInt(m[1]));
26- core.setOutput("issues", JSON.stringify(issueNumbers));
24+ let matches = [];
25+ let m;
26+ while ((m = issuePattern.exec(body)) !== null) {
27+ matches.push(parseInt(m[1]));
28+ }
29+ // Ensure output is always a valid JSON array
30+ core.setOutput("issues", JSON.stringify(matches));
2731
2832 - name : Sync Metadata into PR Body
29- if : steps.extract.outputs.issues != '[]'
33+ if : steps.extract.outputs.issues && steps.extract.outputs.issues != '[]'
3034 uses : actions/github-script@v7
3135 with :
3236 script : |
33- const issues = JSON.parse(core.getInput("issues"));
37+ const issuesInput = core.getInput("issues") || "[]";
38+ const issues = JSON.parse(issuesInput);
3439 const pr = context.payload.pull_request;
3540
3641 let combinedLabels = [];
7277 let newBody = pr.body || "";
7378
7479 // Remove old metadata block if exists
75- newBody = newBody.replace(/---\n### Synced Metadata [\s\S]*$/, "");
80+ newBody = newBody.replace(/---\n### Synced data [\s\S]*$/, "");
7681
7782 // Append fresh metadata block
7883 newBody += metadataBlock;
0 commit comments