vcs = self._data['changeSet']['kind'] or 'git'
return getattr(self, '_get_%s_rev' % vcs, lambda: None)()
+ def get_revision_branch(self):
+ vcs = self._data['changeSet']['kind'] or 'git'
+ return getattr(self, '_get_%s_rev_branch' % vcs, lambda: None)()
+
def _get_svn_rev(self):
warnings.warn("This untested function may soon be removed from Jenkinsapi.")
maxRevision = 0
# which have lastBuiltRevision in them
_actions = [x for x in self._data['actions']
if x and "lastBuiltRevision" in x]
- # FIXME So this code returns the first item found in the filtered
- # list. Why not just:
- # `return _actions[0]["lastBuiltRevision"]["SHA1"]`
- for item in _actions:
- revision = item["lastBuiltRevision"]["SHA1"]
- return revision
+
+ return _actions[0]["lastBuiltRevision"]["SHA1"]
def _get_hg_rev(self):
warnings.warn("This untested function may soon be removed from Jenkinsapi.")
return [x['mercurialNodeName'] for x in self._data['actions'] if 'mercurialNodeName' in x][0]
+ def _get_svn_rev_branch(self):
+ raise NotImplementedError('_get_svn_rev_branch is not yet implemented')
+
+ def _get_git_rev_branch(self):
+ # Sometimes we have None as part of actions. Filter those actions
+ # which have lastBuiltRevision in them
+ _actions = [x for x in self._data['actions']
+ if x and "lastBuiltRevision" in x]
+
+ return _actions[0]["lastBuiltRevision"]["branch"]
+
+ def _get_hg_rev_branch(self):
+ raise NotImplementedError('_get_hg_rev_branch is not yet implemented')
+
def get_duration(self):
return datetime.timedelta(milliseconds=self._data["duration"])
Can we extract git build revision data from a build object?
"""
self.assertIsInstance(self.b.get_revision(), basestring)
- self.assertEquals(self.b.get_revision(), '7def9ed6e92580f37d00e4980c36c4d36e68f702')
+ self.assertEquals(self.b.get_revision(),
+ '7def9ed6e92580f37d00e4980c36c4d36e68f702')
+
+ def test_git_revision_branch(self):
+ """
+ Can we extract git build branch from a build object?
+ """
+ self.assertIsInstance(self.b.get_revision_branch(), list)
+ self.assertEquals(len(self.b.get_revision_branch()), 1)
+ self.assertIsInstance(self.b.get_revision_branch()[0], dict)
+ self.assertEquals(self.b.get_revision_branch()[0]['SHA1'],
+ '7def9ed6e92580f37d00e4980c36c4d36e68f702')
+ self.assertEquals(self.b.get_revision_branch()[0]['name'],
+ 'origin/unstable')
if __name__ == '__main__':
unittest.main()