-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (41 loc) · 1.38 KB
/
sync-labels.yaml
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
name: Sync Labels from Issue to PR
on:
pull_request:
types: [opened, reopened]
jobs:
sync-labels:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Sync Labels
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
if (context.payload.pull_request.body) {
const issueNumberMatch = context.payload.pull_request.body.match(/#(\d+)/);
if (issueNumberMatch && issueNumberMatch[1]) {
const issue_number = issueNumberMatch[1];
const issue = await github.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const labels = issue.data.labels.map(label => label.name);
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labels
});
} else {
console.log("No issue number found in the pull request body.");
}
} else {
console.log("Pull request body is null or undefined.");
}