-
Notifications
You must be signed in to change notification settings - Fork 71
134 lines (118 loc) · 4.84 KB
/
review.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
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
name: Review triggered by comment
on:
issue_comment:
types: [created]
jobs:
check:
runs-on: ubuntu-latest
outputs:
triggered: ${{ steps.check.outputs.triggered }}
steps:
- uses: carrotIndustries/pull-request-comment-trigger@master
id: check
with:
trigger: 'Bot!'
reaction: rocket
prefix_only: true
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
review:
runs-on: ubuntu-latest
needs: check
if: needs.check.outputs.triggered == 'true'
steps:
- name: setup git
run: |
mkdir ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
echo $SSH_PRIVKEY > ~/.ssh/id_rsa
git config --global user.email "[email protected]"
git config --global user.name "Horizon EDA Poolbot"
env:
SSH_PRIVKEY: ${{ secrets.secrets.SSH_PRIVKEY }}
- name: checkout media
uses: actions/checkout@v2
with:
repository: horizon-eda/poolbot-media
ssh-key: ${{ secrets.SSH_PRIVKEY }}
path: media
- name: remove old media dir
run: rm -rf media/pr-${{ github.event.issue.number }}
- name: set media dir
run: echo "media_dir=pr-${{ github.event.issue.number }}/${{ github.event.comment.id }}" >> $GITHUB_ENV
- name: create media dir
run: mkdir -p media/${{ env.media_dir }}
- name: checkout pr
uses: actions/checkout@v2
with:
ref: refs/pull/${{ github.event.issue.number }}/merge
path: pool
- name: fetch master
run: git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin master:master
working-directory: pool
- name: get versions.json from master
run: git show master:versions.json > ../versions.json
working-directory: pool
- name: create review
uses: docker://ghcr.io/horizon-eda/horizon-pr-review:latest
with:
args: >-
/github/workspace/pool -u -o /github/workspace/comment.md
-l /github/workspace/labels.json
-i /github/workspace/media/${{ env.media_dir }}
-v /github/workspace/versions.json
-p https://raw.githubusercontent.com/horizon-eda/poolbot-media/master/${{ env.media_dir }}/
- name: print comment
run: cat comment.md
- name: commit & push media
working-directory: media
run: |
git add .
git diff-index --quiet HEAD || git commit -m 'review pr ${{ github.event.issue.number }}'
git pull --rebase
git push
- name: minimize old comments
run: |
IFS='/' read -r OWNER REPOSITORY <<< "${{github.repository}}"
echo $OWNER $REPOSITORY
jq -R --slurp '{query: .}' << EOF |
{
repository(name: "$REPOSITORY", owner: "$OWNER") {
pullRequest(number: ${{ github.event.issue.number }}) {
id
comments(last: 100) {
nodes {
author {
login
}
id
isMinimized
}
}
}
}
}
EOF
curl -H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
-X POST ${{ github.graphql_url }} -d @- | \
jq '.data.repository.pullRequest.comments.nodes[] | select(.author.login=="github-actions" and .isMinimized == false) | .id' | \
xargs -I xx curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN}}" -X POST ${{ github.graphql_url }} \
-d "{\"query\":\"mutation { minimizeComment(input: {subjectId: \\"\"xx\\"\", classifier: OUTDATED}){clientMutationId}}\"}"
- name: comment
run: |
jq -R --slurp '{body: .}' comment.md | curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header "Accept: application/vnd.github.v3+json" \
--data @-
- name: add labels
run: |
curl https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header "Accept: application/vnd.github.v3+json" \
> existing_labels.json
jq --slurp '[.[0][].name | select(startswith("bot:") | not)]+.[1]' existing_labels.json labels.json | \
curl --request PUT --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header "Accept: application/vnd.github.v3+json" \
--data @-