-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatchset-created
executable file
·75 lines (66 loc) · 2 KB
/
patchset-created
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
#!/usr/bin/env python
import sys
import click
import requests
from github import Github, Auth
from config import Config
gh = Github(auth=Auth.Token(Config.GITHUB_TOKEN))
buildkite = {
"LineageOS/www": "https://api.buildkite.com/v2/organizations/lineageos/pipelines/www-preview/builds",
"LineageOS/lineage_wiki": "https://api.buildkite.com/v2/organizations/lineageos/pipelines/wiki-preview/builds",
}
@click.command()
@click.option("--change")
@click.option("--kind")
@click.option("--change-url")
@click.option("--change-owner")
@click.option("--change-owner-username")
@click.option("--project")
@click.option("--branch")
@click.option("--topic")
@click.option("--uploader")
@click.option("--uploader-username")
@click.option("--commit")
@click.option("--patchset")
def main(
change,
kind,
change_url,
change_owner,
change_owner_username,
project,
branch,
topic,
uploader,
uploader_username,
commit,
patchset,
):
with open("/data/gerrit/review/logs/hook_logs", "a") as f:
f.write(f"hook received: {' '.join(sys.argv)}\n")
if kind == "NO_CHANGE" or kind == "NO_CODE_CHANGE":
return
change_id = change_url.split("/")[-1]
repo = gh.get_repo(project)
workflows = repo.get_workflows()
# we want to trigger anything starting with the string `gerrit`
filtered = [x for x in workflows if x.name.lower().startswith("gerrit")]
for wf in filtered:
inputs = {
"change": change,
"gerrit-ref": f"refs/changes/{change_id[-2:]}/{change_id}/{patchset}",
"ref": commit,
}
res = wf.create_dispatch(branch, inputs)
# previews launch buildkite jobs
if project in buildkite.keys():
data = {
"commit": commit,
"branch": branch,
"env": {
"CHANGE_NUMBER": change_url.split("/")[-1],
"CHANGE": change,
},
}
requests.post(buildkite[project], headers=Config.BUILDKITE_HEADERS, json=data)
main()