-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-gh-releases.py
executable file
·66 lines (53 loc) · 1.62 KB
/
create-gh-releases.py
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
#!/usr/bin/env python3
import os
import sys
import requests
# Usage: ./create-gh-releases.py [tag] [release-notes-link]
# Generate a token at https://github.com/settings/tokens
GITHUB_API_TOKEN = os.environ['GITHUB_API_TOKEN']
def run(tag: str, release_notes_link: str):
create_release_endpoint = (
'https://api.github.com/repos/kobotoolbox/{repo}/releases'
)
repos = [
'kobo-docker',
'kobo-install',
'kpi',
'kobocat',
]
headers = {
'Accept': 'application/vnd.github.groot-preview+json',
'Authorization': f'Bearer {GITHUB_API_TOKEN}',
'X-GitHub-Api-Version': '2022-11-28'
}
payload = {
'tag_name': tag,
'name': tag,
'body': f'For more information, please see {release_notes_link}',
'draft': False,
'prerelease': False,
'generate_release_notes': False
}
for repo in repos:
resp = requests.post(
create_release_endpoint.format(repo=repo),
json=payload,
headers=headers,
)
if resp.status_code != 201:
print(resp.text)
else:
print(f'GH release for {repo} is created')
if __name__ == '__main__':
try:
tag_ = sys.argv[1]
release_notes_link_ = sys.argv[2]
except IndexError:
print('Usage: ./create-gh-releases.py [tag] [release-notes-link]')
sys.exit(1)
try:
GITHUB_API_TOKEN = os.environ['GITHUB_API_TOKEN']
except KeyError:
print('`GITHUB_API_TOKEN` is missing, run `source ./env` first!')
sys.exit(1)
run(tag_, release_notes_link_)