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 #256 from novafloss/skip
Browse files Browse the repository at this point in the history
Unskip jobs before narrowing scope to current stage
  • Loading branch information
bersace committed Feb 14, 2017
2 parents 87aa930 + 4922456 commit 44723a4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
27 changes: 26 additions & 1 deletion jenkins_epo/extensions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ class SkipExtension(Extension):
DEFAULTS = {
'jobs_match': [],
}
BUILD_ALL = ['*']

def process_instruction(self, instruction):
if instruction == 'skip':
Expand Down Expand Up @@ -488,6 +487,31 @@ def run(self):
))


class UnskipExtension(Extension):
stage = '09'

DEFAULTS = {
'jobs_match': [],
}

@asyncio.coroutine
def run(self):
for name, spec in self.current.all_job_specs.items():
job = self.current.jobs[name]
for context in job.list_contexts(spec):
if not match(context, self.current.jobs_match):
continue

status = self.current.statuses.get(context, CommitStatus())
if not status.is_skipped:
continue

logger.info("Unskipping %s.", context)
self.current.last_commit.maybe_update_status(CommitStatus(
status, state='pending', description='Backed!',
))


class YamlExtension(Extension):
"""
# Ephemeral jobs parameters
Expand Down Expand Up @@ -564,6 +588,7 @@ def run(self):
))
return

self.current.all_job_specs = self.current.job_specs
self.current.jobs = head.repository.jobs

for name, args in self.current.yaml.items():
Expand Down
7 changes: 7 additions & 0 deletions jenkins_epo/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def is_running(self):
return True
return False

@property
def is_skipped(self):
return (
self.get('state') == 'success' and
'Skipped' in self.get('description', '')
)

@property
def is_rebuildable(self):
if self.get('state') in {'error', 'failure'}:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
'outdated = jenkins_epo.extensions.core:OutdatedExtension',
'report = jenkins_epo.extensions.core:ReportExtension',
'skip = jenkins_epo.extensions.core:SkipExtension',
'unskip = jenkins_epo.extensions.core:UnskipExtension',
'yaml = jenkins_epo.extensions.core:YamlExtension'
],
},
Expand Down
31 changes: 31 additions & 0 deletions tests/extensions/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,34 @@ def test_skip_run():
assert 'null' in pushed_contextes
assert 'queued' in pushed_contextes
assert 'running' in pushed_contextes


@pytest.mark.asyncio
@asyncio.coroutine
def test_unskip():
from jenkins_epo.extensions.core import CommitStatus, UnskipExtension

ext = UnskipExtension('ext', Mock())
ext.current = ext.bot.current
ext.current.jobs_match = ['m-*']
ext.current.all_job_specs = dict(job=Mock())
ext.current.jobs = {}
ext.current.jobs['job'] = job = Mock()
job.list_contexts.return_value = ['m-nostatus', 'm-unskip', 'skipped']
ext.current.statuses = statuses = {}
statuses['m-unskip'] = CommitStatus(
context='m-unskip', state='success', description='Skipped',
)
statuses['skipped'] = CommitStatus(
context='skipped', state='success', description='Skipped',
)

yield from ext.run()

pushed_contextes = [
c[1][0]['context']
for c in ext.current.last_commit.maybe_update_status.mock_calls
]
assert 'm-unskip' in pushed_contextes
assert 'm-nostatus' not in pushed_contextes
assert 'skipped' not in pushed_contextes

0 comments on commit 44723a4

Please sign in to comment.