-
Notifications
You must be signed in to change notification settings - Fork 18
54 lines (48 loc) · 1.52 KB
/
pr-update.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
name: Update PR
on:
workflow_run:
workflows: [PR Build]
types:
- completed
jobs:
postbuild:
name: Update PR
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: Install Python modules
run: pip install PyGithub
- name: Update PR
run: |
from github import Auth, Github
import json
from urllib.request import Request, urlopen
from zipfile import ZipFile
tok = "${{ secrets.GITHUB_TOKEN }}"
gh = Github(auth=Auth.Token(tok))
repo = gh.get_repo("${{ github.repository }}")
run = repo.get_workflow_run(${{ github.event.workflow_run.id }})
info = None
for artifact in run.get_artifacts():
if artifact.name == "build-info":
info = artifact
req = Request(info.archive_download_url, None, {
"Authorization": f"Bearer {tok}",
"Accept": "application/vnd.github+json"
})
with urlopen(req) as info:
zip = ZipFile(info)
with zip.open("build-info.json") as info:
info = json.load(info)
author = info["author"];
head = info["head"]
cmp = repo.compare(info["base"], f"{author}:{head}")
if cmp.status != "behind":
pull = repo.get_pull(info["pr"])
ready = False
for label in pull.labels:
if label.name == "S-ready":
ready = True
if not ready:
pull.add_to_labels("S-ready")
shell: python