Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

Commit

Permalink
Merge pull request #245 from novafloss/branches
Browse files Browse the repository at this point in the history
Distinct ref and shortref for branch limit
  • Loading branch information
bersace committed Feb 9, 2017
2 parents 843f0f6 + 95e1f5d commit 610aaf1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jenkins_epo/extensions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,),
Expand Down
2 changes: 1 addition & 1 deletion jenkins_epo/extensions/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '*'))
Expand Down
3 changes: 2 additions & 1 deletion jenkins_epo/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/extensions/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 9 additions & 9 deletions tests/extensions/test_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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()),
Expand All @@ -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)),
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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'])),
Expand All @@ -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']),
Expand All @@ -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 = {}
Expand All @@ -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()),
Expand Down

0 comments on commit 610aaf1

Please sign in to comment.