-
Notifications
You must be signed in to change notification settings - Fork 538
102 lines (92 loc) · 3.69 KB
/
assign_release_conductor.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Assign Release Conductor
on:
pull_request:
workflow_dispatch:
inputs:
pull-request:
type: number
description: Pull Request Number
required: true
jobs:
assign-release-conductor:
if: github.head_ref == 'changeset-release/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- uses: ./.github/actions/pagerduty
id: pagerduty
with:
schedule-id: 'P3IIVC4'
token: ${{ secrets.PAGERDUTY_API_KEY_SID }}
- run: echo ${{ steps.pagerduty.outputs.user }} is release conductor
- name: Add user as assignee and reviewer
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ github.event.inputs.pull-request || github.event.pull_request.number }}
RELEASE_CONDUCTOR: ${{ steps.pagerduty.outputs.user }}
PREV_RELEASE_CONDUCTOR: ${{ steps.pagerduty.outputs.previous-schedule-user }}
with:
script: |
const { PR_NUMBER, RELEASE_CONDUCTOR, PREV_RELEASE_CONDUCTOR } = process.env;
const { data: pull } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: PR_NUMBER,
});
// If the previous release conductor was added as an assignee, remove them
const hasPreviousAssignee = pull.assignees.find((assignee) => {
return assignee.login === PREV_RELEASE_CONDUCTOR;
});
if (hasPreviousAssignee) {
await github.rest.issues.removeAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: PR_NUMBER,
assignees: [PREV_RELEASE_CONDUCTOR],
});
}
// If the previous release conductor was added as a reviewer, remove them
const { data: requestedReviewers } = await github.rest.pulls.listRequestedReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: PR_NUMBER,
});
const hasPreviousReviewer = requestedReviewers.users.find((user) => {
return user.login === PREV_RELEASE_CONDUCTOR;
});
if (hasPreviousReviewer) {
await github.rest.pulls.removeRequestedReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: PR_NUMBER,
reviewers: [PREV_RELEASE_CONDUCTOR],
});
}
// Add the current release conductor as an assignee if they are not currently assigned
const hasAssignee = pull.assignees.find((assignee) => {
return assignee.login === RELEASE_CONDUCTOR;
});
if (!hasAssignee) {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: PR_NUMBER,
assignees: [RELEASE_CONDUCTOR]
})
}
// Request the current release conductor as a reviewer if they are not currently requested
const hasReviewer = requestedReviewers.users.find((user) => {
return user.login === RELEASE_CONDUCTOR;
});
if (!hasReviewer) {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: PR_NUMBER,
reviewers: [RELEASE_CONDUCTOR]
})
}