Skip to content

Commit a536322

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

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

eventhandler.py

Lines changed: 7 additions & 2 deletions
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

Lines changed: 5 additions & 0 deletions
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"expected": {
3+
"labels": [
4+
"S-needs-code-changes"
5+
]
6+
},
7+
"initial": {
8+
"labels": []
9+
},
10+
"payload": {
11+
"target_url": "https://travis-ci.org/servo/servo/builds/120670455",
12+
"context": "continuous-integration/travis-ci/pr",
13+
"repository": {
14+
"owner": {
15+
"login": "servo"
16+
},
17+
"name": "servo"
18+
},
19+
"state": "failure"
20+
}
21+
}

json_cleanup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def __str__(self):
7070
def __int__(self):
7171
return int(self._node)
7272

73+
def split(self, sep):
74+
return self._node.split(sep)
75+
7376

7477
class JsonCleaner(object):
7578
def __init__(self, json_obj):

newpr.py

Lines changed: 9 additions & 1 deletion
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+
travis = TravisCiApiProvider()
223+
build_number = payload['target_url'].split('/')[-1]
224+
build = travis.get_build(build_number)
225+
issue = travis.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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import urllib
2+
import json
3+
4+
5+
class TravisCiApiProvider():
6+
host_url = 'https://api.travis-ci.org'
7+
build_url = host_url + '/builds/{build_id}'
8+
log_url = host_url + '/jobs/{job_id}/log'
9+
10+
def get_build(self, build_id):
11+
url = self.build_url.format(build_id=build_id)
12+
return json.loads(urllib.urlopen(url).read())
13+
14+
def get_pull_request_number(self, build_data):
15+
return int(build_data['compare_url'].split('/')[-1])

0 commit comments

Comments
 (0)