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

allow github reporter to work with git@ urls #3148

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is it for? who can set project to smth like repoOwner/repoName ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for when I set project to "foobar" not "owner/repo" This protects the code and allow the code to use the meta data that was really sent to get the data. There is no documentation other than that the project is a meta value. there is nothing saying that it can have magic values. I been burned by this a few times.

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codecov says this line is not covered. that's fine to me. just fix the doc issue.

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