-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.xsh
47 lines (37 loc) · 900 Bytes
/
action.xsh
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
# Baseline stuff for actions
import json
$GITHUB_EVENT = json.loads(p"$GITHUB_EVENT_PATH".read_text())
$INPUT = {
k[len('INPUT_'):]: v
for k, v in ${...}.items()
if k.startswith('INPUT_')
}
# Set up a GitHub API client, based on what's installed.
# Supported:
# - PyGithub
# - gqlmod-github
if 'GITHUB_TOKEN' in $INPUT:
token = $INPUT['GITHUB_TOKEN']
elif 'GITHUB_TOKEN' in ${...}:
token = $GITHUB_TOKEN
else:
token = None
try:
import github
except ImportError:
pass
else:
$GITHUB = github.Github(token)
try:
import gqlmod
except ImportError:
pass
else:
gqlmod.enable_gql_import()
cm = gqlmod.with_provider('github', token=token)
cm.__enter__()
# This is only to avoid warnings at exit
# (Odd construction to allow scope cleanup)
events.on_exit(lambda _func=cm.__exit__, **_: _func(None, None, None))
del cm
del token