-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_dispatch.py
More file actions
executable file
·117 lines (102 loc) · 3.97 KB
/
github_dispatch.py
File metadata and controls
executable file
·117 lines (102 loc) · 3.97 KB
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
#!/usr/bin/python3
import argparse
import os.path
import requests
import sys
import yaml
class GitHubEventDispatcher(object):
def __init__(self, owner, repo, gh_auth):
self.owner = owner
self.repo = repo
self.gh_auth = gh_auth
def dispatch(self, event_type, client_payload=None):
event_data = {
'event_type': event_type,
}
if client_payload is not None:
event_data['client_payload'] = client_payload
return requests.post(
'https://api.github.com/repos/{owner}/{repo}/dispatches'.format(
owner=self.owner,
repo=self.repo),
auth=(self.gh_auth['user'], self.gh_auth['oauth_token']),
json=event_data,
headers={
'Accept': "application/vnd.github.v3+json",
'User-Agent': "geschenkerbauer-event-dispatch",
})
parser = argparse.ArgumentParser(
description="Use GitHub Actions to perform package-related actions")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--build', action='store_true',
help="Build the specified package(s)")
group.add_argument('--check-updates', action='store_true',
help="Check the AUR for package updates")
group.add_argument('--check-upstream-updates', action='store_true',
help="Check upstream for package updates")
group.add_argument('--update-from-aur', action='store_true',
help="Update the specified packages from the AUR")
parser.add_argument('--nodeps', action='store_true',
help="Skip dependency checks when building")
parser.add_argument('pkgname', nargs='*')
args = parser.parse_args()
try:
import xdg.BaseDirectory
configpath = xdg.BaseDirectory.load_first_config('hub')
except ImportError:
configpath = os.path.expanduser('~/.config/hub')
with open(configpath) as f:
config = yaml.safe_load(f)
gh_auth = config['github.com'][0]
dispatcher = GitHubEventDispatcher('mutantmonkey', 'aur', gh_auth)
if args.build:
for pkgname in args.pkgname:
data = {'pkgname': pkgname}
if args.nodeps:
data['nodeps'] = "1"
r = dispatcher.dispatch('build-package', data)
if r.status_code == 204:
print("Build for {0} triggered".format(pkgname), file=sys.stderr)
else:
print(
"Build for {0} returned unknown status code {1}".format(
pkgname, r.status_code),
file=sys.stderr)
elif args.check_updates:
if len(args.pkgname) > 0:
print(
"Limiting the update check by package name is not supported; all "
"packages will be checked.",
file=sys.stderr)
r = dispatcher.dispatch('check-aur-for-updates')
if r.status_code == 204:
print("Update check triggered", file=sys.stderr)
else:
print(
"Update check returned unknown status code {0}".format(
r.status_code),
file=sys.stderr)
elif args.check_upstream_updates:
if len(args.pkgname) > 0:
print(
"Limiting the update check by package name is not supported; all "
"packages will be checked.",
file=sys.stderr)
r = dispatcher.dispatch('check-upstream-for-updates')
if r.status_code == 204:
print("Update check triggered", file=sys.stderr)
else:
print(
"Update check returned unknown status code {0}".format(
r.status_code),
file=sys.stderr)
elif args.update_from_aur:
for pkgname in args.pkgname:
r = dispatcher.dispatch('update-from-aur', {"pkgbase": pkgname})
if r.status_code == 204:
print("Update for {0} triggered".format(pkgname), file=sys.stderr)
else:
print(
"Update for {0} returned unknown status code {1}".format(
pkgname, r.status_code),
file=sys.stderr)