From 4922456dbc8116369a44fb2ca1fe90a06c8be18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20BERSAC=20=28bersace=29?= Date: Tue, 14 Feb 2017 14:06:21 +0100 Subject: [PATCH] Unskip jobs before narrowing scope to current stage --- jenkins_epo/extensions/core.py | 27 ++++++++++++++++++++++++++- jenkins_epo/repository.py | 7 +++++++ setup.py | 1 + tests/extensions/test_core.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/jenkins_epo/extensions/core.py b/jenkins_epo/extensions/core.py index 4f08813c..e3e91153 100644 --- a/jenkins_epo/extensions/core.py +++ b/jenkins_epo/extensions/core.py @@ -453,7 +453,6 @@ class SkipExtension(Extension): DEFAULTS = { 'jobs_match': [], } - BUILD_ALL = ['*'] def process_instruction(self, instruction): if instruction == 'skip': @@ -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 @@ -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(): diff --git a/jenkins_epo/repository.py b/jenkins_epo/repository.py index 89438250..b229abfb 100644 --- a/jenkins_epo/repository.py +++ b/jenkins_epo/repository.py @@ -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'}: diff --git a/setup.py b/setup.py index 51fd2fa6..38f56bd4 100644 --- a/setup.py +++ b/setup.py @@ -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' ], }, diff --git a/tests/extensions/test_core.py b/tests/extensions/test_core.py index 46ed9aa4..b118d307 100644 --- a/tests/extensions/test_core.py +++ b/tests/extensions/test_core.py @@ -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