forked from open-eats/OpenEats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.py
executable file
·98 lines (86 loc) · 2.41 KB
/
release.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
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
#!/usr/bin/env python
# encoding: utf-8
import json
import requests
from requests.auth import HTTPBasicAuth
from secrets import username, password
def release(_repo, _tag, _name, _target, _body, _draft, _prerelease):
"""
Send a post request to github to log a release.
Then print out the response status and message.
"""
response = requests.post(
'https://api.github.com/repos/open-eats/%s/releases' % _repo,
json={
"tag_name": _tag,
"target_commitish": _target,
"name": _name,
"body": _body,
"draft": _draft,
"prerelease": _prerelease
},
auth=HTTPBasicAuth(username, password)
)
print('Status: %s' % response)
print('Response: %s' % response.text)
# Define some help test that the json file should follow.
help_text = '''
A JSON file with release info in it. See below for an example.
{
"tag": "1.1.1",
"name": "Release Test",
"body": "the is a test release!",
"target": "master",
"draft": false,
"prerelease": false
}
'''
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(
description='OpenEats release script.'
)
# Require a json file as part of the script
parser.add_argument(
'release',
type=str,
help=help_text
)
# Open the json file and try and parse it into a json file
with open(parser.parse_args().release, 'r') as fp:
args = json.loads(fp.read())
# All json files should have this format.
json_format = [
'tag',
'name',
'target',
'body',
'draft',
'prerelease',
]
# Iterate through the `json_format` array and
# make sure the json file supplied has all the required fields.
for key in json_format:
try:
tmp = args[key]
except (IndexError, KeyError):
print("$s missing! Please add it." % key)
exit(1)
# The list of repos we want to push a release to.
repos = [
'openeats-nginx',
'openeats-api',
'openeats-web',
'OpenEats'
]
# Run a release for all the repos with the data from json file.
for r in repos:
release(
r,
args.get('tag'),
args.get('name'),
args.get('target'),
args.get('body'),
args.get('draft'),
args.get('prerelease')
)