Skip to content

Commit 9d1a79b

Browse files
committed
non-whitespace character
1 parent 51acfaf commit 9d1a79b

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

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

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

21-
# Extract linked issue(s)
22-
- name: Extract linked issue(s) from PR
21+
# Step 1: Extract linked issue(s) from PR
22+
- name: Extract linked issue(s)
2323
id: extract-issues
2424
uses: actions/github-script@v7
2525
with:
2626
github-token: ${{ secrets.GITHUB_TOKEN }}
2727
script: |
28+
const core = require('@actions/core');
29+
2830
const prNumber = context.payload.pull_request.number;
2931
const prTitle = context.payload.pull_request.title || '';
3032
const prBody = context.payload.pull_request.body || '';
3133
32-
// Regex patterns for issue references
3334
const patterns = [
3435
/(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)/gi,
3536
/#(\d+)/g
@@ -44,10 +45,10 @@ jobs:
4445
}
4546
}
4647
47-
// Return valid JSON
48-
return { issues: Array.from(issueNumbers), pr: prNumber };
48+
// ✅ Set output safely as JSON string
49+
core.setOutput('result', JSON.stringify({ issues: Array.from(issueNumbers), pr: prNumber }));
4950
50-
# Sync metadata safely
51+
# Step 2: Sync metadata to PR
5152
- name: Sync Issue Metadata to PR
5253
uses: actions/github-script@v7
5354
env:
@@ -57,26 +58,26 @@ jobs:
5758
script: |
5859
const core = require('@actions/core');
5960
60-
// Safely parse the previous step’s JSON
61+
// Safely parse JSON
6162
let data;
6263
try {
6364
data = JSON.parse(process.env.RESULT_JSON);
65+
if (typeof data === 'string') data = JSON.parse(data);
6466
} catch (err) {
65-
core.setFailed(`Invalid JSON from extract-issues: ${err.message}`);
67+
core.setFailed(`Failed to parse JSON: ${err.message}\nRaw: ${process.env.RESULT_JSON}`);
6668
return;
6769
}
6870
6971
const prNumber = data.pr;
7072
const issueNumbers = data.issues || [];
7173
7274
if (!issueNumbers.length) {
73-
console.log("No linked issues found.");
75+
console.log("No linked issues found");
7476
return;
7577
}
7678
7779
for (const issueNumber of issueNumbers) {
7880
try {
79-
// Fetch issue
8081
const { data: issue } = await github.rest.issues.get({
8182
owner: context.repo.owner,
8283
repo: context.repo.repo,
@@ -114,22 +115,6 @@ jobs:
114115
console.log(`Milestone synced: ${issue.milestone.title}`);
115116
}
116117
117-
// --- Sync Projects (optional, GitHub Projects v2 is different API) ---
118-
if (issue.project_cards_url) {
119-
const cardsResponse = await github.rest.projects.listCards({
120-
column_id: issue.project_cards_url.split('/').pop()
121-
}).catch(() => ({ data: [] }));
122-
123-
for (const card of cardsResponse.data || []) {
124-
await github.rest.projects.createCard({
125-
column_id: card.column_id,
126-
content_id: prNumber,
127-
content_type: 'PullRequest'
128-
});
129-
console.log(`Added PR #${prNumber} to project card in column ${card.column_id}`);
130-
}
131-
}
132-
133118
// --- Optional: Add a comment on PR ---
134119
await github.rest.issues.createComment({
135120
owner: context.repo.owner,

0 commit comments

Comments
 (0)