Skip to content

Commit 51acfaf

Browse files
committed
test pr sync
1 parent 700cf93 commit 51acfaf

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

.github/workflows/autolabel-pr-issue.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- name: Checkout
1919
uses: actions/checkout@v4
2020

21+
# Extract linked issue(s)
2122
- name: Extract linked issue(s) from PR
2223
id: extract-issues
2324
uses: actions/github-script@v7
@@ -43,19 +44,33 @@ jobs:
4344
}
4445
}
4546
46-
return JSON.stringify({ issues: Array.from(issueNumbers), pr: prNumber });
47+
// Return valid JSON
48+
return { issues: Array.from(issueNumbers), pr: prNumber };
4749
50+
# Sync metadata safely
4851
- name: Sync Issue Metadata to PR
4952
uses: actions/github-script@v7
53+
env:
54+
RESULT_JSON: ${{ steps.extract-issues.outputs.result }}
5055
with:
5156
github-token: ${{ secrets.GITHUB_TOKEN }}
5257
script: |
53-
const data = JSON.parse('${{ steps.extract-issues.outputs.result }}');
58+
const core = require('@actions/core');
59+
60+
// Safely parse the previous step’s JSON
61+
let data;
62+
try {
63+
data = JSON.parse(process.env.RESULT_JSON);
64+
} catch (err) {
65+
core.setFailed(`Invalid JSON from extract-issues: ${err.message}`);
66+
return;
67+
}
68+
5469
const prNumber = data.pr;
5570
const issueNumbers = data.issues || [];
5671
57-
if (issueNumbers.length === 0) {
58-
console.log("No linked issues found");
72+
if (!issueNumbers.length) {
73+
console.log("No linked issues found.");
5974
return;
6075
}
6176
@@ -99,14 +114,13 @@ jobs:
99114
console.log(`Milestone synced: ${issue.milestone.title}`);
100115
}
101116
102-
// --- Sync Projects (GitHub Projects v2) ---
103-
if(issue.project_cards_url) {
104-
// Fetch project cards of issue
117+
// --- Sync Projects (optional, GitHub Projects v2 is different API) ---
118+
if (issue.project_cards_url) {
105119
const cardsResponse = await github.rest.projects.listCards({
106-
column_id: issue.project_cards_url.split('/').pop() // last part is column_id
107-
}).catch(()=>({data:[]}));
108-
109-
for(const card of cardsResponse.data || []) {
120+
column_id: issue.project_cards_url.split('/').pop()
121+
}).catch(() => ({ data: [] }));
122+
123+
for (const card of cardsResponse.data || []) {
110124
await github.rest.projects.createCard({
111125
column_id: card.column_id,
112126
content_id: prNumber,
@@ -116,7 +130,7 @@ jobs:
116130
}
117131
}
118132
119-
// --- Optionally: Add a comment on PR ---
133+
// --- Optional: Add a comment on PR ---
120134
await github.rest.issues.createComment({
121135
owner: context.repo.owner,
122136
repo: context.repo.repo,

0 commit comments

Comments
 (0)