-
Notifications
You must be signed in to change notification settings - Fork 2
/
github.bass
72 lines (60 loc) · 2.4 KB
/
github.bass
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
(def stub-client
(module [start-check]
(defn start-check [thunk name sha]
(start thunk null?))))
(provide [check-hook]
(defop check-hook [event clone checks] scope
(eval [check-hook-fn event (:*loop* scope stub-client) clone checks] scope))
(defn check-hook-fn [{:event event :payload payload} client clone checks]
(case event
"check_suite"
(case payload
{:action "requested"
:repository {:clone_url clone-url}
:check_suite {:head_sha sha}}
(start-checks client sha (checks (clone clone-url sha)))
{:action "rerequested"
:repository {:clone_url clone-url}
:check_suite {:head_sha sha}}
(start-checks client sha (checks (clone clone-url sha)))
_
(log "ignoring action" :event event :action payload:action))
"check_run"
(case payload
{:action "rerequested"
:repository {:clone_url clone-url}
:check_run {:name name
:head_sha sha}}
(let [selector (string->symbol name)
src (clone clone-url sha)
thunk (selector (checks src))]
(client:start-check thunk name sha))
_
(log "ignoring action" :event event :action payload:action))
"pull_request"
(case payload
{:action "opened"
:pull_request {:head {:sha sha
:repo {:clone_url clone-url}}}}
(start-checks client sha (checks (clone clone-url sha)))
{:action "reopened"
:pull_request {:head {:sha sha
:repo {:clone_url clone-url}}}}
(start-checks client sha (checks (clone clone-url sha)))
{:action "synchronize"
:pull_request {:base {:repo {:clone_url upstream-url}}
:head {:sha sha
:repo {:clone_url clone-url}}}}
(when (not (= upstream-url clone-url))
; only run checks for external PRs, otherwise they're redundant with
; the check suites created by pushing
(start-checks client sha (checks (clone clone-url sha))))
_
(log "ignoring action" :event event :action payload:action))
_
(log "ignoring event" :event event :payload (keys payload))))
(defn start-checks [client sha checks]
(map-pairs
(fn [name thunk] (client:start-check thunk (str name) sha))
(scope->list checks)))
)