Skip to content

Commit 44552b6

Browse files
Hugo Thiessardwafflespeanut
Hugo Thiessard
authored andcommitted
Add S-needs-code-changes if travis build fails
1 parent 4397201 commit 44552b6

File tree

5 files changed

+250
-3
lines changed

5 files changed

+250
-3
lines changed

eventhandler.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
'synchronize': 'on_pr_updated',
1111
'created': 'on_new_comment',
1212
'closed': 'on_pr_closed',
13-
'labeled': 'on_issue_labeled'
13+
'labeled': 'on_issue_labeled',
14+
'status': 'on_build_status'
1415
}
1516

1617

@@ -30,10 +31,14 @@ def on_pr_closed(self, api, payload):
3031
def on_issue_labeled(self, api, payload):
3132
pass
3233

34+
def on_build_status(self, api, payload):
35+
pass
36+
3337
def handle_payload(self, api, payload):
3438
def callback(action):
3539
getattr(self, _payload_actions[action])(api, payload)
36-
payload_action = payload['action']
40+
payload_action = 'status' if 'context' in payload \
41+
else payload['action']
3742
linear_search(_payload_actions, payload_action, callback)
3843

3944
def warn(self, msg):

handlers/status_update/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ def on_pr_closed(self, api, payload):
4545
if payload['pull_request']['merged']:
4646
api.remove_label("S-awaiting-merge")
4747

48+
def on_build_status(self, api, payload):
49+
if payload['context'] == 'continuous-integration/travis-ci/pr':
50+
if payload['state'] == 'failure' or payload['state'] == 'error':
51+
api.add_label("S-needs-code-changes")
52+
4853
handler_interface = StatusUpdateHandler
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
{
2+
"initial": {
3+
"labels": []
4+
},
5+
"expected": {
6+
"labels": ["S-needs-code-changes"]
7+
},
8+
"payload": {
9+
"id": 510996575,
10+
"sha": "650aae0ca9be912021c0d21e30e4cedf67135a78",
11+
"name": "servo/servo",
12+
"target_url": "https://travis-ci.org/servo/servo/builds/120670455",
13+
"context": "continuous-integration/travis-ci/pr",
14+
"description": "The Travis CI build failed",
15+
"state": "failure",
16+
"commit": {
17+
"sha": "650aae0ca9be912021c0d21e30e4cedf67135a78",
18+
"commit": {
19+
"author": {
20+
"name": "Alan Jeffrey",
21+
"email": "[email protected]",
22+
"date": "2016-04-04T16:47:29Z"
23+
},
24+
"committer": {
25+
"name": "Alan Jeffrey",
26+
"email": "[email protected]",
27+
"date": "2016-04-04T16:47:29Z"
28+
},
29+
"message": "Responding to reviewer comments.",
30+
"tree": {
31+
"sha": "c74649f3b0d52b932a19cfb3ce47415fb6439680",
32+
"url": "https://api.github.com/repos/servo/servo/git/trees/c74649f3b0d52b932a19cfb3ce47415fb6439680"
33+
},
34+
"url": "https://api.github.com/repos/servo/servo/git/commits/650aae0ca9be912021c0d21e30e4cedf67135a78",
35+
"comment_count": 0
36+
},
37+
"url": "https://api.github.com/repos/servo/servo/commits/650aae0ca9be912021c0d21e30e4cedf67135a78",
38+
"html_url": "https://github.com/servo/servo/commit/650aae0ca9be912021c0d21e30e4cedf67135a78",
39+
"comments_url": "https://api.github.com/repos/servo/servo/commits/650aae0ca9be912021c0d21e30e4cedf67135a78/comments",
40+
"author": {
41+
"login": "asajeffrey",
42+
"id": 403333,
43+
"avatar_url": "https://avatars.githubusercontent.com/u/403333?v=3",
44+
"gravatar_id": "",
45+
"url": "https://api.github.com/users/asajeffrey",
46+
"html_url": "https://github.com/asajeffrey",
47+
"followers_url": "https://api.github.com/users/asajeffrey/followers",
48+
"following_url": "https://api.github.com/users/asajeffrey/following{/other_user}",
49+
"gists_url": "https://api.github.com/users/asajeffrey/gists{/gist_id}",
50+
"starred_url": "https://api.github.com/users/asajeffrey/starred{/owner}{/repo}",
51+
"subscriptions_url": "https://api.github.com/users/asajeffrey/subscriptions",
52+
"organizations_url": "https://api.github.com/users/asajeffrey/orgs",
53+
"repos_url": "https://api.github.com/users/asajeffrey/repos",
54+
"events_url": "https://api.github.com/users/asajeffrey/events{/privacy}",
55+
"received_events_url": "https://api.github.com/users/asajeffrey/received_events",
56+
"type": "User",
57+
"site_admin": false
58+
},
59+
"committer": {
60+
"login": "asajeffrey",
61+
"id": 403333,
62+
"avatar_url": "https://avatars.githubusercontent.com/u/403333?v=3",
63+
"gravatar_id": "",
64+
"url": "https://api.github.com/users/asajeffrey",
65+
"html_url": "https://github.com/asajeffrey",
66+
"followers_url": "https://api.github.com/users/asajeffrey/followers",
67+
"following_url": "https://api.github.com/users/asajeffrey/following{/other_user}",
68+
"gists_url": "https://api.github.com/users/asajeffrey/gists{/gist_id}",
69+
"starred_url": "https://api.github.com/users/asajeffrey/starred{/owner}{/repo}",
70+
"subscriptions_url": "https://api.github.com/users/asajeffrey/subscriptions",
71+
"organizations_url": "https://api.github.com/users/asajeffrey/orgs",
72+
"repos_url": "https://api.github.com/users/asajeffrey/repos",
73+
"events_url": "https://api.github.com/users/asajeffrey/events{/privacy}",
74+
"received_events_url": "https://api.github.com/users/asajeffrey/received_events",
75+
"type": "User",
76+
"site_admin": false
77+
},
78+
"parents": [
79+
{
80+
"sha": "7f6cc24145dda4f056f70add7154fd3a416bb0d6",
81+
"url": "https://api.github.com/repos/servo/servo/commits/7f6cc24145dda4f056f70add7154fd3a416bb0d6",
82+
"html_url": "https://github.com/servo/servo/commit/7f6cc24145dda4f056f70add7154fd3a416bb0d6"
83+
}
84+
]
85+
},
86+
"branches": [
87+
88+
],
89+
"created_at": "2016-04-04T17:06:05Z",
90+
"updated_at": "2016-04-04T17:06:05Z",
91+
"repository": {
92+
"id": 3390243,
93+
"name": "servo",
94+
"full_name": "servo/servo",
95+
"owner": {
96+
"login": "servo",
97+
"id": 2566135,
98+
"avatar_url": "https://avatars.githubusercontent.com/u/2566135?v=3",
99+
"gravatar_id": "",
100+
"url": "https://api.github.com/users/servo",
101+
"html_url": "https://github.com/servo",
102+
"followers_url": "https://api.github.com/users/servo/followers",
103+
"following_url": "https://api.github.com/users/servo/following{/other_user}",
104+
"gists_url": "https://api.github.com/users/servo/gists{/gist_id}",
105+
"starred_url": "https://api.github.com/users/servo/starred{/owner}{/repo}",
106+
"subscriptions_url": "https://api.github.com/users/servo/subscriptions",
107+
"organizations_url": "https://api.github.com/users/servo/orgs",
108+
"repos_url": "https://api.github.com/users/servo/repos",
109+
"events_url": "https://api.github.com/users/servo/events{/privacy}",
110+
"received_events_url": "https://api.github.com/users/servo/received_events",
111+
"type": "Organization",
112+
"site_admin": false
113+
},
114+
"private": false,
115+
"html_url": "https://github.com/servo/servo",
116+
"description": "The Servo Browser Engine",
117+
"fork": false,
118+
"url": "https://api.github.com/repos/servo/servo",
119+
"forks_url": "https://api.github.com/repos/servo/servo/forks",
120+
"keys_url": "https://api.github.com/repos/servo/servo/keys{/key_id}",
121+
"collaborators_url": "https://api.github.com/repos/servo/servo/collaborators{/collaborator}",
122+
"teams_url": "https://api.github.com/repos/servo/servo/teams",
123+
"hooks_url": "https://api.github.com/repos/servo/servo/hooks",
124+
"issue_events_url": "https://api.github.com/repos/servo/servo/issues/events{/number}",
125+
"events_url": "https://api.github.com/repos/servo/servo/events",
126+
"assignees_url": "https://api.github.com/repos/servo/servo/assignees{/user}",
127+
"branches_url": "https://api.github.com/repos/servo/servo/branches{/branch}",
128+
"tags_url": "https://api.github.com/repos/servo/servo/tags",
129+
"blobs_url": "https://api.github.com/repos/servo/servo/git/blobs{/sha}",
130+
"git_tags_url": "https://api.github.com/repos/servo/servo/git/tags{/sha}",
131+
"git_refs_url": "https://api.github.com/repos/servo/servo/git/refs{/sha}",
132+
"trees_url": "https://api.github.com/repos/servo/servo/git/trees{/sha}",
133+
"statuses_url": "https://api.github.com/repos/servo/servo/statuses/{sha}",
134+
"languages_url": "https://api.github.com/repos/servo/servo/languages",
135+
"stargazers_url": "https://api.github.com/repos/servo/servo/stargazers",
136+
"contributors_url": "https://api.github.com/repos/servo/servo/contributors",
137+
"subscribers_url": "https://api.github.com/repos/servo/servo/subscribers",
138+
"subscription_url": "https://api.github.com/repos/servo/servo/subscription",
139+
"commits_url": "https://api.github.com/repos/servo/servo/commits{/sha}",
140+
"git_commits_url": "https://api.github.com/repos/servo/servo/git/commits{/sha}",
141+
"comments_url": "https://api.github.com/repos/servo/servo/comments{/number}",
142+
"issue_comment_url": "https://api.github.com/repos/servo/servo/issues/comments{/number}",
143+
"contents_url": "https://api.github.com/repos/servo/servo/contents/{+path}",
144+
"compare_url": "https://api.github.com/repos/servo/servo/compare/{base}...{head}",
145+
"merges_url": "https://api.github.com/repos/servo/servo/merges",
146+
"archive_url": "https://api.github.com/repos/servo/servo/{archive_format}{/ref}",
147+
"downloads_url": "https://api.github.com/repos/servo/servo/downloads",
148+
"issues_url": "https://api.github.com/repos/servo/servo/issues{/number}",
149+
"pulls_url": "https://api.github.com/repos/servo/servo/pulls{/number}",
150+
"milestones_url": "https://api.github.com/repos/servo/servo/milestones{/number}",
151+
"notifications_url": "https://api.github.com/repos/servo/servo/notifications{?since,all,participating}",
152+
"labels_url": "https://api.github.com/repos/servo/servo/labels{/name}",
153+
"releases_url": "https://api.github.com/repos/servo/servo/releases{/id}",
154+
"deployments_url": "https://api.github.com/repos/servo/servo/deployments",
155+
"created_at": "2012-02-08T19:07:25Z",
156+
"updated_at": "2016-04-04T15:48:28Z",
157+
"pushed_at": "2016-04-04T17:04:27Z",
158+
"git_url": "git://github.com/servo/servo.git",
159+
"ssh_url": "[email protected]:servo/servo.git",
160+
"clone_url": "https://github.com/servo/servo.git",
161+
"svn_url": "https://github.com/servo/servo",
162+
"homepage": "https://servo.org/",
163+
"size": 214000,
164+
"stargazers_count": 6429,
165+
"watchers_count": 6429,
166+
"language": null,
167+
"has_issues": true,
168+
"has_downloads": true,
169+
"has_wiki": true,
170+
"has_pages": false,
171+
"forks_count": 1055,
172+
"mirror_url": null,
173+
"open_issues_count": 1417,
174+
"forks": 1055,
175+
"open_issues": 1417,
176+
"watchers": 6429,
177+
"default_branch": "master"
178+
},
179+
"organization": {
180+
"login": "servo",
181+
"id": 2566135,
182+
"url": "https://api.github.com/orgs/servo",
183+
"repos_url": "https://api.github.com/orgs/servo/repos",
184+
"events_url": "https://api.github.com/orgs/servo/events",
185+
"hooks_url": "https://api.github.com/orgs/servo/hooks",
186+
"issues_url": "https://api.github.com/orgs/servo/issues",
187+
"members_url": "https://api.github.com/orgs/servo/members{/member}",
188+
"public_members_url": "https://api.github.com/orgs/servo/public_members{/member}",
189+
"avatar_url": "https://avatars.githubusercontent.com/u/2566135?v=3",
190+
"description": null
191+
},
192+
"sender": {
193+
"login": "asajeffrey",
194+
"id": 403333,
195+
"avatar_url": "https://avatars.githubusercontent.com/u/403333?v=3",
196+
"gravatar_id": "",
197+
"url": "https://api.github.com/users/asajeffrey",
198+
"html_url": "https://github.com/asajeffrey",
199+
"followers_url": "https://api.github.com/users/asajeffrey/followers",
200+
"following_url": "https://api.github.com/users/asajeffrey/following{/other_user}",
201+
"gists_url": "https://api.github.com/users/asajeffrey/gists{/gist_id}",
202+
"starred_url": "https://api.github.com/users/asajeffrey/starred{/owner}{/repo}",
203+
"subscriptions_url": "https://api.github.com/users/asajeffrey/subscriptions",
204+
"organizations_url": "https://api.github.com/users/asajeffrey/orgs",
205+
"repos_url": "https://api.github.com/users/asajeffrey/repos",
206+
"events_url": "https://api.github.com/users/asajeffrey/events{/privacy}",
207+
"received_events_url": "https://api.github.com/users/asajeffrey/received_events",
208+
"type": "User",
209+
"site_admin": false
210+
}
211+
}
212+
}

newpr.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from StringIO import StringIO
1616
import urllib2
1717

18+
from travisciapiprovider import TravisCiApiProvider
1819
import eventhandler
1920

2021

@@ -215,7 +216,14 @@ def get_page_content(self, url):
215216

216217

217218
def extract_globals_from_payload(payload):
218-
if payload["action"] == "created" or payload["action"] == "labeled":
219+
if 'context' in payload:
220+
owner = payload['repository']['owner']['login']
221+
repo = payload['repository']['name']
222+
travisCiApiProvider = TravisCiApiProvider()
223+
build_number = payload['target_url'].split('/')[-1]
224+
build = travisCiApiProvider.get_build(build_number)
225+
issue = travisCiApiProvider.get_pull_request_number(build)
226+
elif payload['action'] == 'created' or payload['action'] == 'labeled':
219227
owner = payload['repository']['owner']['login']
220228
repo = payload['repository']['name']
221229
issue = str(payload['issue']['number'])

travisciapiprovider.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import urllib
2+
import json
3+
4+
5+
# If more functionality is needed from this class, it might be a
6+
# better decision to use travispy
7+
class TravisCiApiProvider():
8+
host_url = 'https://api.travis-ci.org'
9+
build_url = host_url + '/builds/{build_id}'
10+
log_url = host_url + '/jobs/{job_id}/log'
11+
12+
def get_build(self, build_id):
13+
url = self.build_url.format(build_id=build_id)
14+
return json.loads(urllib.urlopen(url).read())
15+
16+
def get_pull_request_number(self, build_data):
17+
return int(build_data['compare_url'].split('/')[-1])

0 commit comments

Comments
 (0)