summaryrefslogtreecommitdiff
path: root/zuul/driver/github
diff options
context:
space:
mode:
authorJan Hruban <jan.hruban@gooddata.com>2017-01-03 15:03:09 +0100
committerJesse Keating <omgjlk@us.ibm.com>2017-05-08 21:14:28 -0700
commite252a73a461916fb790e46acaf6362f7d938aca4 (patch)
tree5db477e5bfe8cf6ff39e66432f19fdd7dd29f9ec /zuul/driver/github
parent6d53c5ebdd499556f7a9337d831304c51e413ff6 (diff)
downloadzuul-e252a73a461916fb790e46acaf6362f7d938aca4.tar.gz
Support for github commit status
Github reporter sets commit status of pull request based on the result of the pipeline. Change-Id: Id95bf0dbaa710c555e3a1838d3430e18ac9501aa Co-Authored-By: Jesse Keating <omgjlk@us.ibm.com>
Diffstat (limited to 'zuul/driver/github')
-rw-r--r--zuul/driver/github/__init__.py2
-rw-r--r--zuul/driver/github/githubconnection.py10
-rw-r--r--zuul/driver/github/githubreporter.py45
3 files changed, 51 insertions, 6 deletions
diff --git a/zuul/driver/github/__init__.py b/zuul/driver/github/__init__.py
index 4e54f11d7..2d6829d1c 100644
--- a/zuul/driver/github/__init__.py
+++ b/zuul/driver/github/__init__.py
@@ -34,7 +34,7 @@ class GithubDriver(Driver, ConnectionInterface, TriggerInterface,
return githubsource.GithubSource(self, connection)
def getReporter(self, connection, config=None):
- return githubreporter.GithubReporter(self, connection)
+ return githubreporter.GithubReporter(self, connection, config)
def getTriggerSchema(self):
return githubtrigger.getSchema()
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index 7085bf642..6604d81d5 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -277,12 +277,18 @@ class GithubConnection(BaseConnection):
owner, proj = project_name.split('/')
return self.github.pull_request(owner, proj, number).as_dict()
- def report(self, project, pr_number, message):
- owner, proj = project.name.split('/')
+ def commentPull(self, project, pr_number, message):
+ owner, proj = project.split('/')
repository = self.github.repository(owner, proj)
pull_request = repository.issue(pr_number)
pull_request.create_comment(message)
+ def setCommitStatus(self, project, sha, state, url='', description='',
+ context=''):
+ owner, proj = project.split('/')
+ repository = self.github.repository(owner, proj)
+ repository.create_status(sha, state, url, description, context)
+
def _ghTimestampToDate(self, timestamp):
return time.strptime(timestamp, '%Y-%m-%dT%H:%M:%SZ')
diff --git a/zuul/driver/github/githubreporter.py b/zuul/driver/github/githubreporter.py
index 685c60e8d..ecbb48677 100644
--- a/zuul/driver/github/githubreporter.py
+++ b/zuul/driver/github/githubreporter.py
@@ -24,15 +24,54 @@ class GithubReporter(BaseReporter):
name = 'github'
log = logging.getLogger("zuul.GithubReporter")
+ def __init__(self, driver, connection, config=None):
+ super(GithubReporter, self).__init__(driver, connection, config)
+ self._commit_status = self.config.get('status', None)
+ self._create_comment = self.config.get('comment', True)
+
def report(self, source, pipeline, item):
- """Comment on PR with test status."""
+ """Comment on PR and set commit status."""
+ if self._create_comment:
+ self.addPullComment(pipeline, item)
+ if (self._commit_status is not None and
+ hasattr(item.change, 'patchset') and
+ item.change.patchset is not None):
+ self.setPullStatus(pipeline, item)
+
+ def addPullComment(self, pipeline, item):
message = self._formatItemReport(pipeline, item)
project = item.change.project.name
pr_number = item.change.number
+ self.log.debug(
+ 'Reporting change %s, params %s, message: %s' %
+ (item.change, self.config, message))
+ self.connection.commentPull(project, pr_number, message)
+
+ def setPullStatus(self, pipeline, item):
+ project = item.change.project.name
+ sha = item.change.patchset
+ context = pipeline.name
+ state = self._commit_status
+ url = ''
+ if self.connection.sched.config.has_option('zuul', 'status_url'):
+ url = self.connection.sched.config.get('zuul', 'status_url')
+ description = ''
+ if pipeline.description:
+ description = pipeline.description
+
+ self.log.debug(
+ 'Reporting change %s, params %s, status:\n'
+ 'context: %s, state: %s, description: %s, url: %s' %
+ (item.change, self.config, context, state,
+ description, url))
- self.connection.report(project, pr_number, message)
+ self.connection.setCommitStatus(
+ project, sha, state, url, description, context)
def getSchema():
- github_reporter = v.Any(str, v.Schema({}, extra=True))
+ github_reporter = v.Schema({
+ 'status': v.Any('pending', 'success', 'failure'),
+ 'comment': bool
+ })
return github_reporter