forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (67 loc) · 2.39 KB
/
assign-milestone-on-close.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
70
71
72
73
name: Assign Milestone on Close
env:
MILESTONE_ID: 1
on:
issues:
types: [closed]
pull_request_target:
types: [closed]
permissions:
issues: write
pull-requests: write
jobs:
assign-milestone:
runs-on: ubuntu-latest
steps:
- name: Get payload content
id: payload-content
uses: actions/github-script@v7
with:
script: console.log(JSON.stringify(context.payload));
# result-encoding: string
# - name: Print payload content
# id: print-payload
# run: |
# echo "${{steps.get-payload.outputs.result}}" >> payload.txt
- name: Check if milestone is set
id: check-milestone
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueOrPr = context.payload.issue || context.payload.pull_request;
if (!issueOrPr.milestone) {
core.setOutput('milestoneNotSet', 'true');
console.log("Milestone not set");
} else {
core.setOutput('milestoneNotSet', 'false');
console.log("Milestone already set.");
}
- name: Check completed or merged
id: check-done
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// No need to check if this is a merged PR, as pull_request_target takes care of that for us.
if (context.payload.issue && context.payload.issue.state_reason === "completed") {
core.setOutput('isDone', 'true');
console.log("Done.");
} else {
core.setOutput('isDone', 'false');
console.log("Not done.");
}
console.log(context.payload.pull_request.merged)
- name: Assign default milestone
if: steps.check-milestone.outputs.milestoneNotSet == 'true' && steps.check-done.outputs.isDone== 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueOrPrNumber = (context.payload.issue || context.payload.pull_request).number;
const repository = context.repo;
await github.rest.issues.update({
...repository,
issue_number: issueOrPrNumber,
milestone: process.env.MILESTONE_ID
});