Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add S-needs-code-changes if travis build fails #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add S-needs-code-changes if travis build fails
Hugo Thiessard authored and wafflespeanut committed May 28, 2016
commit a536322a719bb421950c799aa31499d91df8a8dd
9 changes: 7 additions & 2 deletions eventhandler.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@
'synchronize': 'on_pr_updated',
'created': 'on_new_comment',
'closed': 'on_pr_closed',
'labeled': 'on_issue_labeled'
'labeled': 'on_issue_labeled',
'status': 'on_build_status'
}


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

def on_build_status(self, api, payload):
pass

def handle_payload(self, api, payload):
def callback(action):
getattr(self, _payload_actions[action])(api, payload)
payload_action = payload['action']
payload_action = 'status' if 'context' in payload \
else payload['action']
linear_search(_payload_actions, payload_action, callback)

def warn(self, msg):
5 changes: 5 additions & 0 deletions handlers/status_update/__init__.py
Original file line number Diff line number Diff line change
@@ -45,4 +45,9 @@ def on_pr_closed(self, api, payload):
if payload['pull_request']['merged']:
api.remove_label("S-awaiting-merge")

def on_build_status(self, api, payload):
if payload['context'] == 'continuous-integration/travis-ci/pr':
if payload['state'] == 'failure' or payload['state'] == 'error':
api.add_label("S-needs-code-changes")

handler_interface = StatusUpdateHandler
21 changes: 21 additions & 0 deletions handlers/status_update/tests/build_status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"expected": {
"labels": [
"S-needs-code-changes"
]
},
"initial": {
"labels": []
},
"payload": {
"target_url": "https://travis-ci.org/servo/servo/builds/120670455",
"context": "continuous-integration/travis-ci/pr",
"repository": {
"owner": {
"login": "servo"
},
"name": "servo"
},
"state": "failure"
}
}
3 changes: 3 additions & 0 deletions json_cleanup.py
Original file line number Diff line number Diff line change
@@ -70,6 +70,9 @@ def __str__(self):
def __int__(self):
return int(self._node)

def split(self, sep):
return self._node.split(sep)


class JsonCleaner(object):
def __init__(self, json_obj):
10 changes: 9 additions & 1 deletion newpr.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
from StringIO import StringIO
import urllib2

from travisciapiprovider import TravisCiApiProvider
import eventhandler


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


def extract_globals_from_payload(payload):
if payload["action"] == "created" or payload["action"] == "labeled":
if 'context' in payload:
owner = payload['repository']['owner']['login']
repo = payload['repository']['name']
travis = TravisCiApiProvider()
build_number = payload['target_url'].split('/')[-1]
build = travis.get_build(build_number)
issue = travis.get_pull_request_number(build)
elif payload['action'] == 'created' or payload['action'] == 'labeled':
owner = payload['repository']['owner']['login']
repo = payload['repository']['name']
issue = str(payload['issue']['number'])
15 changes: 15 additions & 0 deletions travisciapiprovider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import urllib
import json


class TravisCiApiProvider():
host_url = 'https://api.travis-ci.org'
build_url = host_url + '/builds/{build_id}'
log_url = host_url + '/jobs/{job_id}/log'

def get_build(self, build_id):
url = self.build_url.format(build_id=build_id)
return json.loads(urllib.urlopen(url).read())

def get_pull_request_number(self, build_data):
return int(build_data['compare_url'].split('/')[-1])