Skip to content

Commit

Permalink
allow github reporter to work with git@ urls
Browse files Browse the repository at this point in the history
Add some verbose messages that can be useful
add a release note fragment
add test code
  • Loading branch information
dragon512 committed Jul 27, 2017
1 parent 119a673 commit bf6f0fc
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 4 deletions.
1 change: 1 addition & 0 deletions master/buildbot/newsfragments/github.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:py:class:`~buildbot.reporters.github.GitHubStatusPush` now support reporting to ssh style URLs, ie `git@github.com:Owner/RepoName.git`
13 changes: 9 additions & 4 deletions master/buildbot/reporters/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from buildbot.reporters import http
from buildbot.util import httpclientservice
from buildbot.util import unicode2NativeString
from buildbot.util.giturlparse import giturlparse

HOSTED_BASE_URL = 'https://api.github.com'

Expand Down Expand Up @@ -136,12 +137,16 @@ def send(self, build):
else:
issue = None

if project:
if "/" in project:
repoOwner, repoName = project.split('/')
else:
repo = sourcestamps[0]['repository'].split('/')[-2:]
repoOwner = repo[0]
repoName = '.'.join(repo[1].split('.')[:-1])
giturl = giturlparse(sourcestamps[0]['repository'])
repoOwner = giturl.owner
repoName = giturl.repo

if self.verbose:
log.msg("Updating github status: repoOwner={repoOwner}, repoName={repoName}".format(
repoOwner=repoOwner, repoName=repoName))

for sourcestamp in sourcestamps:
sha = sourcestamp['revision']
Expand Down
106 changes: 106 additions & 0 deletions master/buildbot/test/unit/test_reporter_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from buildbot.test.fake import fakemaster
from buildbot.test.util.reporter import ReporterTestMixin

URLtestcount = 0


class TestGitHubStatusPush(unittest.TestCase, ReporterTestMixin):
# project must be in the form <owner>/<project>
Expand Down Expand Up @@ -115,6 +117,110 @@ def test_empty(self):
self.sp.buildFinished(("build", 20, "finished"), build)


class TestGitHubStatusPushURL(unittest.TestCase, ReporterTestMixin):
# project must be in the form <owner>/<project>
TEST_PROJECT = u'buildbot'

@defer.inlineCallbacks
def setUp(self):
global URLtestcount
if (URLtestcount == 0):
ReporterTestMixin.TEST_REPO = u'https://github.com/buildbot1/buildbot1.git'
else:
ReporterTestMixin.TEST_REPO = u'git@github.com:buildbot2/buildbot2.git'
URLtestcount = 1

# ignore config error if txrequests is not installed
self.patch(config, '_errors', Mock())
self.master = fakemaster.make_master(testcase=self,
wantData=True, wantDb=True, wantMq=True)

yield self.master.startService()
self._http = yield fakehttpclientservice.HTTPClientService.getFakeService(
self.master, self,
HOSTED_BASE_URL, headers={
'Authorization': 'token XXYYZZ',
'User-Agent': 'Buildbot'
},
debug=None, verify=None)
sp = self.setService()
sp.sessionFactory = Mock(return_value=Mock())
yield sp.setServiceParent(self.master)

def setService(self):
self.sp = GitHubStatusPush('XXYYZZ')
return self.sp

def tearDown(self):
return self.master.stopService()

@defer.inlineCallbacks
def setupBuildResults(self, buildResults):
self.insertTestData([buildResults], buildResults)
build = yield self.master.data.get(("builds", 20))
defer.returnValue(build)

@defer.inlineCallbacks
def test_ssh(self):
build = yield self.setupBuildResults(SUCCESS)
# we make sure proper calls to txrequests have been made
self._http.expect(
'post',
'/repos/buildbot2/buildbot2/statuses/d34db33fd43db33f',
json={'state': 'pending',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build started.', 'context': 'buildbot/Builder0'})
self._http.expect(
'post',
'/repos/buildbot2/buildbot2/statuses/d34db33fd43db33f',
json={'state': 'success',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build done.', 'context': 'buildbot/Builder0'})
self._http.expect(
'post',
'/repos/buildbot2/buildbot2/statuses/d34db33fd43db33f',
json={'state': 'failure',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build done.', 'context': 'buildbot/Builder0'})

build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build)
build['complete'] = True
self.sp.buildFinished(("build", 20, "finished"), build)
build['results'] = FAILURE
self.sp.buildFinished(("build", 20, "finished"), build)

@defer.inlineCallbacks
def test_https(self):
build = yield self.setupBuildResults(SUCCESS)
# we make sure proper calls to txrequests have been made
self._http.expect(
'post',
'/repos/buildbot1/buildbot1/statuses/d34db33fd43db33f',
json={'state': 'pending',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build started.', 'context': 'buildbot/Builder0'})
self._http.expect(
'post',
'/repos/buildbot1/buildbot1/statuses/d34db33fd43db33f',
json={'state': 'success',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build done.', 'context': 'buildbot/Builder0'})
self._http.expect(
'post',
'/repos/buildbot1/buildbot1/statuses/d34db33fd43db33f',
json={'state': 'failure',
'target_url': 'http://localhost:8080/#builders/79/builds/0',
'description': 'Build done.', 'context': 'buildbot/Builder0'})

build['complete'] = False
self.sp.buildStarted(("build", 20, "started"), build)
build['complete'] = True
self.sp.buildFinished(("build", 20, "finished"), build)
build['results'] = FAILURE
self.sp.buildFinished(("build", 20, "finished"), build)


class TestGitHubCommentPush(TestGitHubStatusPush):

def setService(self):
Expand Down

0 comments on commit bf6f0fc

Please sign in to comment.