Skip to content

Commit

Permalink
Support WithProperties for Git repourl
Browse files Browse the repository at this point in the history
Fixes #885.
  • Loading branch information
John Carr authored and Amber Yust committed Oct 12, 2010
1 parent c8e1ced commit 6d6648e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
12 changes: 7 additions & 5 deletions master/buildbot/steps/source.py
Expand Up @@ -175,21 +175,23 @@ def computeRepositoryURL(self, repository):
isinstance(repository, str) or isinstance(repository, unicode)

s = self.build.getSourceStamp()
props = self.build.getProperties()

if not repository:
assert s.repository
return str(s.repository)
else:
if callable(repository):
return str(repository(s.repository))
return str(props.render(repository(s.repository)))
elif isinstance(repository, dict):
return str(repository.get(s.repository))
return str(props.render(repository.get(s.repository)))
else: # string or unicode
try:
repourl = str(repository % s.repository)
except TypeError:
# that's the backward compatibility case
repourl = repository
return str(repourl)
repourl = props.render(repository)
return repourl

def start(self):
if self.notReally:
Expand Down Expand Up @@ -849,7 +851,7 @@ def startVC(self, branch, revision, patch):
if branch is not None:
self.args['branch'] = branch

self.args['repourl'] = self.computeRepositoryURL(self.repourl)
self.args['repourl'] = self.computeRepositoryURL(self.repourl)
self.args['revision'] = revision
self.args['patch'] = patch
slavever = self.slaveVersion("git")
Expand Down
25 changes: 25 additions & 0 deletions master/buildbot/test/unit/test_source_repourl.py
Expand Up @@ -5,10 +5,17 @@
class SourceStamp(object):
repository = "test"

class Properties(object):
def render(self, value):
return value % dict(foo="bar")

class Build(object):
s = SourceStamp()
props = Properties()
def getSourceStamp(self):
return self.s
def getProperties(self):
return self.props

class RepoURL(unittest.TestCase):

Expand All @@ -35,3 +42,21 @@ def test_callable(self):
func = lambda x: x[::-1]
self.assertEquals(s.computeRepositoryURL(func), "tset")

def test_backward_compatibility_render(self):
s = Source()
s.build = Build()
self.assertEquals(s.computeRepositoryURL("repourl%(foo)s"), "repourlbar")

def test_dict_render(self):
s = Source()
s.build = Build()
d = dict(test="repourl%(foo)s")
self.assertEquals(s.computeRepositoryURL(d), "repourlbar")

def test_callable_render(self):
s = Source()
s.build = Build()
func = lambda x: x+"%(foo)s"
self.assertEquals(s.computeRepositoryURL(func), "testbar")


2 changes: 2 additions & 0 deletions master/docs/cfg-buildsteps.texinfo
Expand Up @@ -402,6 +402,8 @@ the Change and its return value will be used as repository URL.
@end table
@end table

Use of WithProperites with string, dict and callable is supported.

Note that this is quite similar to the mechanism used by the WebStatus
for the @code{changecommentlink}, @code{projects} or @code{repositories} parameter.

Expand Down

0 comments on commit 6d6648e

Please sign in to comment.