-
Notifications
You must be signed in to change notification settings - Fork 35
69 lines (61 loc) · 2.58 KB
/
sync_issue_metadata.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Sync Issue Labels and Assignees to PR
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
sync-labels-assignees:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Sync Labels and Assignees
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
const prBody = pr.body || '';
// Regular expressions to match "fixes #123", "closes #123", or "fix #123" (case insensitive)
const issueRefs = prBody.match(/(?:fixes|closes|fix)\s*#(\d+)/gi);
if (!issueRefs) {
console.log('No issue references found in PR description');
return;
}
// Extract issue numbers
const issueNumbers = issueRefs.map(ref =>
parseInt(ref.match(/\d+/)[0])
);
for (const issueNumber of issueNumbers) {
try {
// Get issue details
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
// Sync labels
if (issue.data.labels && issue.data.labels.length > 0) {
const labels = issue.data.labels.map(label => label.name);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: labels
});
console.log(`Synced labels from issue #${issueNumber} to PR #${pr.number}`);
}
// Sync assignees
if (issue.data.assignees && issue.data.assignees.length > 0) {
const assignees = issue.data.assignees.map(assignee => assignee.login);
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
assignees: assignees
});
console.log(`Synced assignees from issue #${issueNumber} to PR #${pr.number}`);
}
} catch (error) {
console.error(`Error processing issue #${issueNumber}:`, error);
}
}