Browse Source

Basic github check_suite webhook

tags/v0.4.4
Russ Garrett 4 years ago
parent
commit
a02072e9f4
No account linked to committer's email address
3 changed files with 234 additions and 1 deletions
  1. 8
    1
      httplistener/github.go
  2. 1
    0
      httplistener/templates.go
  3. 225
    0
      webhook_test_data/github/check_suite.json

+ 8
- 1
httplistener/github.go View File

@@ -31,7 +31,7 @@ func (hl *HTTPListener) githubHandler(w http.ResponseWriter, request *http.Reque
31 31
 	// All valid events we want to receive need to be listed here.
32 32
 	payload, err := hook.Parse(request,
33 33
 		github.ReleaseEvent, github.PushEvent, github.IssuesEvent, github.IssueCommentEvent,
34
-		github.PullRequestEvent)
34
+		github.PullRequestEvent, github.CheckSuiteEvent)
35 35
 
36 36
 	if err != nil {
37 37
 		if err == github.ErrEventNotFound {
@@ -81,6 +81,13 @@ func (hl *HTTPListener) githubHandler(w http.ResponseWriter, request *http.Reque
81 81
 			msgs, err = hl.renderTemplate("github.pullrequest", payload)
82 82
 			repo = pl.Repository.Name
83 83
 		}
84
+	case github.CheckSuitePayload:
85
+		pl := payload.(github.CheckSuitePayload)
86
+		if pl.CheckSuite.Status == "completed" && pl.CheckSuite.Conclusion == "failure" {
87
+			send = true
88
+			msgs, err = hl.renderTemplate("github.checksuite", payload)
89
+			repo = pl.Repository.Name
90
+		}
84 91
 	}
85 92
 
86 93
 	if err != nil {

+ 1
- 0
httplistener/templates.go View File

@@ -18,6 +18,7 @@ var defaultTemplates = map[string]string{
18 18
 	"github.issue":        "[{{b .Repository.Name}}] {{g .Sender.Login}} {{.Action}} issue #{{.Issue.Number}}: {{.Issue.Title}} {{.Issue.HTMLURL}}",
19 19
 	"github.issuecomment": "[{{b .Repository.Name}}] {{g .Comment.User.Login}} commented on issue #{{.Issue.Number}}: {{trunc .Comment.Body 150}} {{.Comment.HTMLURL}}",
20 20
 	"github.pullrequest":  "[{{b .Repository.Name}}] {{g .Sender.Login}} {{if .PullRequest.Merged}}merged{{else}}{{.Action}}{{end}} pull request #{{.PullRequest.Number}} (\x0303{{.PullRequest.Base.Ref}}…{{.PullRequest.Head.Ref}}\x0f): {{.PullRequest.Title}} {{.PullRequest.HTMLURL}}",
21
+	"github.checksuite":   "[{{b .Repository.Name}}] check suite {{b .CheckSuite.Conclusion}}",
21 22
 	"prometheus.alert": `{{range .Alerts}}[{{b "Prometheus"}}] {{if (eq .Status "firing")}}{{b "alerting"}}{{else}}{{h "resolved"}}{{end}}: {{.Annotations.summary}}
22 23
 {{end}}`,
23 24
 }

+ 225
- 0
webhook_test_data/github/check_suite.json View File

@@ -0,0 +1,225 @@
1
+{
2
+  "action": "completed",
3
+  "check_suite": {
4
+    "id": 118578147,
5
+    "node_id": "MDEwOkNoZWNrU3VpdGUxMTg1NzgxNDc=",
6
+    "head_branch": "changes",
7
+    "head_sha": "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
8
+    "status": "completed",
9
+    "conclusion": "failure",
10
+    "url": "https://api.github.com/repos/Codertocat/Hello-World/check-suites/118578147",
11
+    "before": "6113728f27ae82c7b1a177c8d03f9e96e0adf246",
12
+    "after": "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
13
+    "pull_requests": [
14
+      {
15
+        "url": "https://api.github.com/repos/Codertocat/Hello-World/pulls/2",
16
+        "id": 279147437,
17
+        "number": 2,
18
+        "head": {
19
+          "ref": "changes",
20
+          "sha": "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
21
+          "repo": {
22
+            "id": 186853002,
23
+            "url": "https://api.github.com/repos/Codertocat/Hello-World",
24
+            "name": "Hello-World"
25
+          }
26
+        },
27
+        "base": {
28
+          "ref": "master",
29
+          "sha": "f95f852bd8fca8fcc58a9a2d6c842781e32a215e",
30
+          "repo": {
31
+            "id": 186853002,
32
+            "url": "https://api.github.com/repos/Codertocat/Hello-World",
33
+            "name": "Hello-World"
34
+          }
35
+        }
36
+      }
37
+    ],
38
+    "app": {
39
+      "id": 29310,
40
+      "node_id": "MDM6QXBwMjkzMTA=",
41
+      "owner": {
42
+        "login": "Octocoders",
43
+        "id": 38302899,
44
+        "node_id": "MDEyOk9yZ2FuaXphdGlvbjM4MzAyODk5",
45
+        "avatar_url": "https://avatars1.githubusercontent.com/u/38302899?v=4",
46
+        "gravatar_id": "",
47
+        "url": "https://api.github.com/users/Octocoders",
48
+        "html_url": "https://github.com/Octocoders",
49
+        "followers_url": "https://api.github.com/users/Octocoders/followers",
50
+        "following_url": "https://api.github.com/users/Octocoders/following{/other_user}",
51
+        "gists_url": "https://api.github.com/users/Octocoders/gists{/gist_id}",
52
+        "starred_url": "https://api.github.com/users/Octocoders/starred{/owner}{/repo}",
53
+        "subscriptions_url": "https://api.github.com/users/Octocoders/subscriptions",
54
+        "organizations_url": "https://api.github.com/users/Octocoders/orgs",
55
+        "repos_url": "https://api.github.com/users/Octocoders/repos",
56
+        "events_url": "https://api.github.com/users/Octocoders/events{/privacy}",
57
+        "received_events_url": "https://api.github.com/users/Octocoders/received_events",
58
+        "type": "Organization",
59
+        "site_admin": false
60
+      },
61
+      "name": "octocoders-linter",
62
+      "description": "",
63
+      "external_url": "https://octocoders.io",
64
+      "html_url": "https://github.com/apps/octocoders-linter",
65
+      "created_at": "2019-04-19T19:36:24Z",
66
+      "updated_at": "2019-04-19T19:36:56Z",
67
+      "permissions": {
68
+        "administration": "write",
69
+        "checks": "write",
70
+        "contents": "write",
71
+        "deployments": "write",
72
+        "issues": "write",
73
+        "members": "write",
74
+        "metadata": "read",
75
+        "organization_administration": "write",
76
+        "organization_hooks": "write",
77
+        "organization_plan": "read",
78
+        "organization_projects": "write",
79
+        "organization_user_blocking": "write",
80
+        "pages": "write",
81
+        "pull_requests": "write",
82
+        "repository_hooks": "write",
83
+        "repository_projects": "write",
84
+        "statuses": "write",
85
+        "team_discussions": "write",
86
+        "vulnerability_alerts": "read"
87
+      },
88
+      "events": [
89
+
90
+      ]
91
+    },
92
+    "created_at": "2019-05-15T15:20:31Z",
93
+    "updated_at": "2019-05-15T15:21:14Z",
94
+    "latest_check_runs_count": 1,
95
+    "check_runs_url": "https://api.github.com/repos/Codertocat/Hello-World/check-suites/118578147/check-runs",
96
+    "head_commit": {
97
+      "id": "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
98
+      "tree_id": "31b122c26a97cf9af023e9ddab94a82c6e77b0ea",
99
+      "message": "Update README.md",
100
+      "timestamp": "2019-05-15T15:20:30Z",
101
+      "author": {
102
+        "name": "Codertocat",
103
+        "email": "21031067+Codertocat@users.noreply.github.com"
104
+      },
105
+      "committer": {
106
+        "name": "Codertocat",
107
+        "email": "21031067+Codertocat@users.noreply.github.com"
108
+      }
109
+    }
110
+  },
111
+  "repository": {
112
+    "id": 186853002,
113
+    "node_id": "MDEwOlJlcG9zaXRvcnkxODY4NTMwMDI=",
114
+    "name": "Hello-World",
115
+    "full_name": "Codertocat/Hello-World",
116
+    "private": false,
117
+    "owner": {
118
+      "login": "Codertocat",
119
+      "id": 21031067,
120
+      "node_id": "MDQ6VXNlcjIxMDMxMDY3",
121
+      "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
122
+      "gravatar_id": "",
123
+      "url": "https://api.github.com/users/Codertocat",
124
+      "html_url": "https://github.com/Codertocat",
125
+      "followers_url": "https://api.github.com/users/Codertocat/followers",
126
+      "following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
127
+      "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
128
+      "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
129
+      "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
130
+      "organizations_url": "https://api.github.com/users/Codertocat/orgs",
131
+      "repos_url": "https://api.github.com/users/Codertocat/repos",
132
+      "events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
133
+      "received_events_url": "https://api.github.com/users/Codertocat/received_events",
134
+      "type": "User",
135
+      "site_admin": false
136
+    },
137
+    "html_url": "https://github.com/Codertocat/Hello-World",
138
+    "description": null,
139
+    "fork": false,
140
+    "url": "https://api.github.com/repos/Codertocat/Hello-World",
141
+    "forks_url": "https://api.github.com/repos/Codertocat/Hello-World/forks",
142
+    "keys_url": "https://api.github.com/repos/Codertocat/Hello-World/keys{/key_id}",
143
+    "collaborators_url": "https://api.github.com/repos/Codertocat/Hello-World/collaborators{/collaborator}",
144
+    "teams_url": "https://api.github.com/repos/Codertocat/Hello-World/teams",
145
+    "hooks_url": "https://api.github.com/repos/Codertocat/Hello-World/hooks",
146
+    "issue_events_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/events{/number}",
147
+    "events_url": "https://api.github.com/repos/Codertocat/Hello-World/events",
148
+    "assignees_url": "https://api.github.com/repos/Codertocat/Hello-World/assignees{/user}",
149
+    "branches_url": "https://api.github.com/repos/Codertocat/Hello-World/branches{/branch}",
150
+    "tags_url": "https://api.github.com/repos/Codertocat/Hello-World/tags",
151
+    "blobs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/blobs{/sha}",
152
+    "git_tags_url": "https://api.github.com/repos/Codertocat/Hello-World/git/tags{/sha}",
153
+    "git_refs_url": "https://api.github.com/repos/Codertocat/Hello-World/git/refs{/sha}",
154
+    "trees_url": "https://api.github.com/repos/Codertocat/Hello-World/git/trees{/sha}",
155
+    "statuses_url": "https://api.github.com/repos/Codertocat/Hello-World/statuses/{sha}",
156
+    "languages_url": "https://api.github.com/repos/Codertocat/Hello-World/languages",
157
+    "stargazers_url": "https://api.github.com/repos/Codertocat/Hello-World/stargazers",
158
+    "contributors_url": "https://api.github.com/repos/Codertocat/Hello-World/contributors",
159
+    "subscribers_url": "https://api.github.com/repos/Codertocat/Hello-World/subscribers",
160
+    "subscription_url": "https://api.github.com/repos/Codertocat/Hello-World/subscription",
161
+    "commits_url": "https://api.github.com/repos/Codertocat/Hello-World/commits{/sha}",
162
+    "git_commits_url": "https://api.github.com/repos/Codertocat/Hello-World/git/commits{/sha}",
163
+    "comments_url": "https://api.github.com/repos/Codertocat/Hello-World/comments{/number}",
164
+    "issue_comment_url": "https://api.github.com/repos/Codertocat/Hello-World/issues/comments{/number}",
165
+    "contents_url": "https://api.github.com/repos/Codertocat/Hello-World/contents/{+path}",
166
+    "compare_url": "https://api.github.com/repos/Codertocat/Hello-World/compare/{base}...{head}",
167
+    "merges_url": "https://api.github.com/repos/Codertocat/Hello-World/merges",
168
+    "archive_url": "https://api.github.com/repos/Codertocat/Hello-World/{archive_format}{/ref}",
169
+    "downloads_url": "https://api.github.com/repos/Codertocat/Hello-World/downloads",
170
+    "issues_url": "https://api.github.com/repos/Codertocat/Hello-World/issues{/number}",
171
+    "pulls_url": "https://api.github.com/repos/Codertocat/Hello-World/pulls{/number}",
172
+    "milestones_url": "https://api.github.com/repos/Codertocat/Hello-World/milestones{/number}",
173
+    "notifications_url": "https://api.github.com/repos/Codertocat/Hello-World/notifications{?since,all,participating}",
174
+    "labels_url": "https://api.github.com/repos/Codertocat/Hello-World/labels{/name}",
175
+    "releases_url": "https://api.github.com/repos/Codertocat/Hello-World/releases{/id}",
176
+    "deployments_url": "https://api.github.com/repos/Codertocat/Hello-World/deployments",
177
+    "created_at": "2019-05-15T15:19:25Z",
178
+    "updated_at": "2019-05-15T15:21:14Z",
179
+    "pushed_at": "2019-05-15T15:20:57Z",
180
+    "git_url": "git://github.com/Codertocat/Hello-World.git",
181
+    "ssh_url": "git@github.com:Codertocat/Hello-World.git",
182
+    "clone_url": "https://github.com/Codertocat/Hello-World.git",
183
+    "svn_url": "https://github.com/Codertocat/Hello-World",
184
+    "homepage": null,
185
+    "size": 0,
186
+    "stargazers_count": 0,
187
+    "watchers_count": 0,
188
+    "language": "Ruby",
189
+    "has_issues": true,
190
+    "has_projects": true,
191
+    "has_downloads": true,
192
+    "has_wiki": true,
193
+    "has_pages": true,
194
+    "forks_count": 0,
195
+    "mirror_url": null,
196
+    "archived": false,
197
+    "disabled": false,
198
+    "open_issues_count": 2,
199
+    "license": null,
200
+    "forks": 0,
201
+    "open_issues": 2,
202
+    "watchers": 0,
203
+    "default_branch": "master"
204
+  },
205
+  "sender": {
206
+    "login": "Codertocat",
207
+    "id": 21031067,
208
+    "node_id": "MDQ6VXNlcjIxMDMxMDY3",
209
+    "avatar_url": "https://avatars1.githubusercontent.com/u/21031067?v=4",
210
+    "gravatar_id": "",
211
+    "url": "https://api.github.com/users/Codertocat",
212
+    "html_url": "https://github.com/Codertocat",
213
+    "followers_url": "https://api.github.com/users/Codertocat/followers",
214
+    "following_url": "https://api.github.com/users/Codertocat/following{/other_user}",
215
+    "gists_url": "https://api.github.com/users/Codertocat/gists{/gist_id}",
216
+    "starred_url": "https://api.github.com/users/Codertocat/starred{/owner}{/repo}",
217
+    "subscriptions_url": "https://api.github.com/users/Codertocat/subscriptions",
218
+    "organizations_url": "https://api.github.com/users/Codertocat/orgs",
219
+    "repos_url": "https://api.github.com/users/Codertocat/repos",
220
+    "events_url": "https://api.github.com/users/Codertocat/events{/privacy}",
221
+    "received_events_url": "https://api.github.com/users/Codertocat/received_events",
222
+    "type": "User",
223
+    "site_admin": false
224
+  }
225
+}

Loading…
Cancel
Save