diff --git a/jenkins_epo/extensions/core.py b/jenkins_epo/extensions/core.py index d5787a9e..dc018918 100644 --- a/jenkins_epo/extensions/core.py +++ b/jenkins_epo/extensions/core.py @@ -375,7 +375,7 @@ def run(self): if not errored: return - branch_name = self.current.head.ref[len('refs/heads/'):] + branch_name = self.current.head.shortref builds = '- ' + '\n- '.join([s['target_url'] for s in errored]) issue = self.current.head.repository.report_issue( title="%s is broken" % (branch_name,), diff --git a/jenkins_epo/extensions/jenkins.py b/jenkins_epo/extensions/jenkins.py index e6d2fa24..4fab057e 100644 --- a/jenkins_epo/extensions/jenkins.py +++ b/jenkins_epo/extensions/jenkins.py @@ -388,7 +388,7 @@ def run(self): self.current.current_stage = stage # Filter job specs to the current stage ones. - current_ref = self.current.head.ref + current_ref = self.current.head.shortref self.current.job_specs = {} for job in stage.job_specs: branches = list(job.config.get('branches', '*')) diff --git a/jenkins_epo/repository.py b/jenkins_epo/repository.py index 22c67d05..965cdd25 100644 --- a/jenkins_epo/repository.py +++ b/jenkins_epo/repository.py @@ -427,6 +427,7 @@ def __init__(self, repository, ref, sha): self.repository = repository self.sha = sha self.ref = ref + self.shortref = ref[len('refs/heads/'):] def __lt__(self, other): return self.sort_key() < other.sort_key() @@ -463,7 +464,7 @@ def __hash__(self): @property def url(self): return 'https://github.com/%s/tree/%s' % ( - self.repository, self.ref[len('refs/heads/'):], + self.repository, self.shortref, ) def fetch_previous_commits(self, last_date=None): diff --git a/tests/extensions/test_core.py b/tests/extensions/test_core.py index b3610c29..46ed9aa4 100644 --- a/tests/extensions/test_core.py +++ b/tests/extensions/test_core.py @@ -131,6 +131,7 @@ def test_report(): ext.current.head = Mock(spec=Branch) ext.current.head.sha = 'c0defada' ext.current.head.ref = 'refs/heads/branch' + ext.current.head.shortref = 'branch' ext.current.head.repository = Mock() ext.current.head.repository.report_issue.return_value = { 'number': '1', diff --git a/tests/extensions/test_stages.py b/tests/extensions/test_stages.py index b2e20d65..6fa8ef40 100644 --- a/tests/extensions/test_stages.py +++ b/tests/extensions/test_stages.py @@ -11,7 +11,7 @@ def test_first_stage(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['build', 'test'] ext.current.job_specs = specs = { 'build': Mock(config=dict(stage='build')), @@ -41,7 +41,7 @@ def test_second_stage(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['build', 'test'] ext.current.job_specs = specs = { 'test': Mock(config=dict()), @@ -69,7 +69,7 @@ def test_no_test_stage(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['build', 'deploy'] ext.current.job_specs = specs = { 'build': Mock(config=dict()), @@ -96,7 +96,7 @@ def test_periodic_ignored(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['deploy', 'test'] ext.current.job_specs = specs = { 'periodic': Mock(config=dict(periodic=True)), @@ -126,7 +126,7 @@ def test_periodic_required(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['deploy', 'test'] ext.current.job_specs = specs = { 'deploy': Mock(config=dict(stage='deploy', periodic=True)), @@ -156,7 +156,7 @@ def test_branches_limit(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['test'] ext.current.job_specs = specs = { 'job': Mock(config=dict(branches=['master'])), @@ -181,7 +181,7 @@ def test_external_context(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = [ dict(name='deploy', external=['deploy/prod']), dict(name='final', external=['final']), @@ -208,7 +208,7 @@ def test_nostages(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['test', 'deploy'] ext.current.job_specs = {} ext.current.jobs = {} @@ -225,7 +225,7 @@ def test_complete(): ext = StagesExtension('stages', Mock()) ext.current = Mock() - ext.current.head.ref = 'pr' + ext.current.head.shortref = 'pr' ext.current.SETTINGS.STAGES = ['test', 'deploy'] ext.current.job_specs = specs = { 'test-job': Mock(config=dict()),