-
Notifications
You must be signed in to change notification settings - Fork 75
88 lines (80 loc) · 2.74 KB
/
draft-pr-converter.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
name: "Convert stale PR's to drafts"
on:
schedule:
- cron: '0 */1 * * *' # At minute 0 past every hour.
workflow_dispatch:
env:
DRAFT_PROTECT_LABEL: "draft-protect"
jobs:
convert_stale_prs:
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: hmarr/[email protected]
- id: get_timestamp
name: Get timestamp
shell: bash
run: echo "ts=$(date -d '10 hours ago' +"%Y-%m-%dT%H:%M:%S")" >> $GITHUB_OUTPUT
- uses: octokit/[email protected]
name: Get PR older than 10 hours
id: get_stale_prs
env:
GITHUB_TOKEN: ${{ secrets.GIT_PAT }}
with:
query: |
{
search(query: "repo:${{ github.repository }} is:pr is:open draft:false -label:${{ env.DRAFT_PROTECT_LABEL }} updated:<=${{ steps.get_timestamp.outputs.ts }}", type: ISSUE, first: 100) {
issueCount
edges {
node {
... on PullRequest {
number
url
id
updatedAt
}
}
}
}
}
- name: Stale PRs data
run: "echo '${{ steps.get_stale_prs.outputs.data }}'"
- name: Convert to draft
id: mutation_step
shell: bash
env:
GIT_PAT: ${{ secrets.GIT_PAT }}
run: |
set -eux
echo '${{ steps.get_stale_prs.outputs.data }}' > /tmp/stale_pr.json
_pr_list=$(jq -r '.search.edges | map(.node.url) | join("\\n")' < /tmp/stale_pr.json)
if [ -n "$_pr_list" ]; then
echo "pr_list=$_pr_list" >> $GITHUB_OUTPUT
echo "exec=true" >> $GITHUB_OUTPUT
echo "$GIT_PAT" | gh auth login --with-token
for pr_id in $(jq -r '.search.edges[].node.id' < /tmp/stale_pr.json); do
gh api graphql -F id="${pr_id}" -f query='
mutation($id: ID!) {
convertPullRequestToDraft(input: { pullRequestId: $id }) {
pullRequest {
id
number
isDraft
}
}
}
'
done
fi
- name: Post to a Slack channel
id: slack
if: ${{ steps.mutation_step.outputs.exec == 'true' }}
uses: slackapi/[email protected]
with:
channel-id: 'C02LMULF4NA'
payload: '{ "type": "mrkdwn", "text": "${{ env.SLACK_MESSAGE }}" }'
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_LSE_BOT_TOKEN }}
SLACK_MESSAGE: >-
*Drafted PR's*\n
${{ steps.mutation_step.outputs.pr_list }}