-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
220 lines (212 loc) · 9.17 KB
/
on-pr-closed.yml
File metadata and controls
220 lines (212 loc) · 9.17 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: On PR closed
on:
pull_request_target:
types: [ closed ]
# Manual trigger to unassign a contributor and take necessary follow-up actions
# Do not call if PR was successfully merged
workflow_dispatch:
inputs:
pr_number:
description: PR number to process
required: true
type: number
jobs:
collect_parameters:
name: Collect parameters
runs-on: ubuntu-slim
if: >
github.repository == 'JabRef/jabref' &&
(
github.event_name == 'workflow_dispatch' ||
!(
github.event.pull_request.user.login == 'dependabot[bot]' ||
startsWith(github.event.pull_request.title, '[Bot] ') ||
startsWith(github.event.pull_request.title, 'Bump ') ||
startsWith(github.event.pull_request.title, 'New Crowdin updates') ||
startsWith(github.event.pull_request.title, 'Update Gradle Wrapper from')
)
)
permissions:
pull-requests: read
outputs:
pr_number: ${{ steps.pick.outputs.pr_number }}
pr_url: ${{ steps.pick.outputs.pr_url }}
pr_body: ${{ steps.pick.outputs.pr_body }}
pr_user: ${{ steps.pick.outputs.pr_user }}
steps:
- id: from_dispatch
name: Collect from dispatch
if: github.event_name == 'workflow_dispatch'
env:
PR_NUMBER: ${{ inputs.pr_number }}
uses: actions/github-script@v8
with:
script: |
const {owner, repo} = context.repo;
const prNumber = Number(process.env.PR_NUMBER);
const {data: pr} = await github.rest.pulls.get({ owner, repo, pull_number: prNumber });
core.setOutput("pr_number", String(pr.number));
core.setOutput("pr_url", pr.html_url ?? "");
core.setOutput("pr_body", pr.body ?? "");
core.setOutput("pr_user", pr.user?.login ?? "");
- name: Pick outputs
id: pick
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "pr_number=${{ steps.from_dispatch.outputs.pr_number }}" >> "$GITHUB_OUTPUT"
echo "pr_url=${{ steps.from_dispatch.outputs.pr_url }}" >> "$GITHUB_OUTPUT"
echo "pr_user=${{ steps.from_dispatch.outputs.pr_user }}" >> "$GITHUB_OUTPUT"
cat >> "$GITHUB_OUTPUT" <<'EOF'
pr_body<<BODY
${{ steps.from_dispatch.outputs.pr_body }}
BODY
EOF
else
echo "pr_number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
echo "pr_url=${{ github.event.pull_request.html_url }}" >> "$GITHUB_OUTPUT"
echo "pr_user=${{ github.event.pull_request.user.login }}" >> "$GITHUB_OUTPUT"
cat >> "$GITHUB_OUTPUT" <<'EOF'
pr_body<<BODY
${{ github.event.pull_request.body }}
BODY
EOF
fi
determine_issue_number:
name: Determine issue number
needs: collect_parameters
runs-on: ubuntu-slim
permissions:
contents: read
outputs:
issue_number: ${{ steps.get_issue_number.outputs.ticketNumber }}
steps:
- name: Determine issue number
id: get_issue_number
env:
PR_NUMBER: ${{ needs.collect_parameters.outputs.pr_number }}
PR_URL: ${{ needs.collect_parameters.outputs.pr_url }}
PR_BODY: ${{ needs.collect_parameters.outputs.pr_body }}
run: |
echo "PR Number: $PR_NUMBER"
echo "PR URL: $PR_URL"
echo "PR [#$PR_NUMBER]($PR_URL)" >> $GITHUB_STEP_SUMMARY
cat <<EOF
PR Body:
$PR_BODY
EOF
ticketNumber=$(printf '%s\n' "$PR_BODY" \
| grep -Eio '(fixes|closes|resolves)\s+(https://github.com/JabRef/jabref/issues/)?#?[0-9]+' \
| grep -Eo '[0-9]+' \
| grep -Ev '^13109$' \
| head -n1 || true)
echo "ticketNumber=$ticketNumber" >> "$GITHUB_OUTPUT"
echo "Determined issue [#$ticketNumber](https://github.com/JabRef/jabref/issues/$ticketNumber)" >> $GITHUB_STEP_SUMMARY
unassign_issue:
name: Mark issue as available
runs-on: ubuntu-slim
needs: [ collect_parameters, determine_issue_number ]
if: >
(needs.determine_issue_number.outputs.issue_number != '') &&
(github.event_name == 'workflow_dispatch' || !github.event.pull_request.merged)
permissions:
contents: read
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v6
- name: Remove assignee
run: |
set -euo pipefail
set -x
# "brute force" remove assignee - it might happen that the contributor was unassinged, but the PR closed later; therefore we need " || true" to ignore any error
gh issue edit ${{ needs.determine_issue_number.outputs.issue_number }} --remove-assignee ${{ needs.collect_parameters.outputs.pr_user }} || true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq
version: 1.0
- name: Check assignees
id: check_assignee
run: |
issue=$(gh issue view ${{ needs.determine_issue_number.outputs.issue_number }} --json assignees)
count=$(echo "$issue" | jq '.assignees | length')
if [ "$count" -gt 0 ]; then
echo "assigned=yes" >> $GITHUB_OUTPUT
else
echo "assigned=no" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove labels assigned, reminder-sent, pinned, and "FirstTimeCodeContribution"
if: steps.check_assignee.outputs.assigned == 'no'
run: |
gh issue edit ${{ needs.determine_issue_number.outputs.issue_number }} --remove-label "📍 Assigned,🔔 reminder-sent,📌 Pinned,FirstTimeCodeContribution"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Move issue to "Free to take" in "Good First Issues"
if: steps.check_assignee.outputs.assigned == 'no'
uses: m7kvqbe1/github-action-move-issues/@main
with:
github-token: ${{ secrets.GH_TOKEN_ACTION_MOVE_ISSUE }}
project-url: "https://github.com/orgs/JabRef/projects/5"
target-labels: "📍 Assigned"
target-column: "Assigned"
ignored-columns: ""
default-column: "Free to take"
issue-number: ${{ needs.determine_issue_number.outputs.issue_number }}
skip-if-not-in-project: true
- name: Move issue to "Free to take" in "Candidates for University Projects"
if: steps.check_assignee.outputs.assigned == 'no'
uses: m7kvqbe1/github-action-move-issues/@main
with:
github-token: ${{ secrets.GH_TOKEN_ACTION_MOVE_ISSUE }}
project-url: "https://github.com/orgs/JabRef/projects/3"
target-labels: "📍 Assigned"
target-column: "Assigned"
ignored-columns: ""
default-column: "Free to take"
issue-number: ${{ needs.determine_issue_number.outputs.issue_number }}
skip-if-not-in-project: true
- name: Comment on PR that unassigned
if: steps.check_assignee.outputs.assigned == 'no'
run: |
echo "Commenting on PR..."
gh issue comment "${{ needs.collect_parameters.outputs.pr_number }}" -b "This pull requests was closed without merging. You have been unassigned from the respective issue #${{ needs.determine_issue_number.outputs.issue_number }}. In case you closed the PR for yourself, you can re-open it. Please also check [After submission of a pull request](https://github.com/JabRef/jabref/blob/main/CONTRIBUTING.md#after-submission-of-a-pull-request) in [CONTRIBUTING.md](https://github.com/JabRef/jabref/blob/main/CONTRIBUTING.md)."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
comment_on_resolved_issue:
name: Comment on resolved issue
runs-on: ubuntu-slim
needs: determine_issue_number
if: >
(needs.determine_issue_number.outputs.issue_number != '') &&
(github.event_name != 'workflow_dispatch' && github.event.pull_request.merged)
permissions:
contents: read
issues: write
steps:
- name: Comment on issue
uses: thollander/actions-comment-pull-request@v3
with:
pr-number: ${{ needs.determine_issue_number.outputs.issue_number }}
message: |
We think that this issue was fixed. Please head to <https://builds.jabref.org/main> to download a development build and try it out.
For any feedback, add a comment to the pull request at ${{ github.event.pull_request.html_url }}.
remove_download_hint:
name: Remove download hint
runs-on: ubuntu-slim
needs: determine_issue_number
# Link is removed in both cases (merged and closed)
if: needs.determine_issue_number.outputs.issue_number != ''
permissions:
contents: read
issues: write
steps:
- name: Delete download comment
uses: thollander/actions-comment-pull-request@v3
with:
pr-number: ${{ needs.determine_issue_number.outputs.issue_number }}
comment-tag: download-link
mode: delete