Skip to content

Commit

Permalink
Add support for "failed" task_output in Run.get_run_id method #17
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Sep 22, 2020
1 parent 03e7a3c commit a27159e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

### v1.0.3 (unreleased)

- **ScanPipe** -- Add support for "failed" task_output in Run.get_run_id method
Fix for https://github.com/nexB/scancode.io/issues/17

### v1.0.2 (2020-09-18)

- **ScanPipe** -- Add documentation and tutorial.
Expand Down
8 changes: 4 additions & 4 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ def get_run_id(self):
Return the run id from the task output.
"""
if self.task_output:
run_id_re = re.compile(r"run-id [0-9]+")
run_id_string = run_id_re.search(self.task_output).group()
if run_id_string:
return run_id_string.split()[-1]
run_id_pattern = re.compile(r"run-id (?P<run_id>[0-9]+)")
match = run_id_pattern.search(self.task_output)
if match:
return match.group("run_id")


class CodebaseResourceQuerySet(ProjectRelatedQuerySet):
Expand Down
20 changes: 18 additions & 2 deletions scanpipe/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,35 @@ def test_scanpipe_project_model_get_next_run(self):

self.assertEqual(None, self.project1.get_next_run())

def test_scanpipe_run_model_methods(self):
def test_scanpipe_run_model_task_methods(self):
run1 = Run.objects.create(project=self.project1, pipeline="pipeline")

self.assertFalse(run1.task_succeeded)

run1.task_exitcode = 0
run1.save()
self.assertTrue(run1.task_succeeded)

run1.task_exitcode = 1
run1.save()
self.assertFalse(run1.task_succeeded)

def test_scanpipe_run_model_get_run_id_method(self):
run1 = Run.objects.create(project=self.project1, pipeline="pipeline")

self.assertIsNone(run1.get_run_id())

run1.task_output = "Missing run-id"
run1.save()
self.assertIsNone(run1.get_run_id())

run1.task_output = "Workflow starting (run-id 1593181041039832):"
run1.save()
self.assertEqual("1593181041039832", run1.get_run_id())

run1.task_output = "(run-id 123) + (run-id 456)"
run1.save()
self.assertEqual("123", run1.get_run_id())

def test_scanpipe_codebase_resource_model_methods(self):
resource = CodebaseResource.objects.create(
project=self.project1, path="filename.ext"
Expand Down

0 comments on commit a27159e

Please sign in to comment.