def build_task(self, task_id, task_status): """ Create a specific implementation of AnalysisTask according to the task name """ try: name = task_status["task"]["metadata"]["name"] except KeyError: raise Exception("Cannot read task name {}".format(task_id)) # Default format is used first when the correct artifact is available if DefaultTask.matches(task_id): return DefaultTask(task_id, task_status) elif name.startswith("source-test-mozlint-"): return MozLintTask(task_id, task_status) elif name == "source-test-clang-tidy": return ClangTidyTask(task_id, task_status) elif name == "source-test-clang-format": return ClangFormatTask(task_id, task_status) elif name in ("source-test-coverity-coverity", "coverity"): return CoverityTask(task_id, task_status) elif name == "source-test-infer-infer": return InferTask(task_id, task_status) elif name.startswith("source-test-"): logger.error(f"Unsupported {name} task: will need a local implementation") else: raise Exception("Unsupported task {}".format(name))
def build_task(self, task_status): """ Create a specific implementation of AnalysisTask according to the task name """ try: task_id = task_status["status"]["taskId"] except KeyError: raise Exception("Cannot read task name {}".format(task_id)) try: name = task_status["task"]["metadata"]["name"] except KeyError: raise Exception("Cannot read task name {}".format(task_id)) # Default format is used first when the correct artifact is available if DefaultTask.matches(task_id): return DefaultTask(task_id, task_status) elif name.startswith("source-test-mozlint-"): return MozLintTask(task_id, task_status) elif name == "source-test-clang-tidy": return ClangTidyTask(task_id, task_status) elif name == "source-test-clang-format": return ClangFormatTask(task_id, task_status) elif name in ("source-test-coverity-coverity", "coverity"): return CoverityTask(task_id, task_status) elif name == "source-test-infer-infer": return InferTask(task_id, task_status) elif settings.autoland_group_id is not None and not name.startswith( "source-test-"): # Log cleanly on autoland unknown tasks logger.info("Skipping unknown task", id=task_id, name=name) else: return DefaultTask(task_id, task_status)
def test_task_failures(mock_phabricator, phab, mock_try_task): """ Test Phabricator reporter publication with some task failures """ with mock_phabricator as api: revision = Revision.from_try(mock_try_task, api) revision.mercurial_revision = "aabbccddee" revision.repository = "https://hg.mozilla.org/try" revision.repository_try_name = "try" reporter = PhabricatorReporter({"analyzers": ["clang-tidy"]}, api=api) status = { "task": { "metadata": { "name": "mock-infer" } }, "status": { "runs": [{ "runId": 0 }] }, } task = ClangTidyTask("ab3NrysvSZyEwsOHL2MZfw", status) issues, patches = reporter.publish([], revision, [task], []) assert len(issues) == 0 assert len(patches) == 0 # Check the callback has been used to post comments assert phab.comments[51] == [VALID_TASK_FAILURES_MESSAGE]
def test_task_failures(mock_phabricator, mock_try_task): """ Test Phabricator reporter publication with some task failures """ from code_review_bot.report.phabricator import PhabricatorReporter from code_review_bot.revisions import Revision from code_review_bot.tasks.clang_tidy import ClangTidyTask def _check_comment(request): # Check the Phabricator main comment is well formed payload = urllib.parse.parse_qs(request.body) assert payload["output"] == ["json"] assert len(payload["params"]) == 1 details = json.loads(payload["params"][0]) assert details == { "revision_id": 51, "message": VALID_TASK_FAILURES_MESSAGE, "attach_inlines": 1, "__conduit__": { "token": "deadbeef" }, } # Outputs dummy empty response resp = {"error_code": None, "result": None} return ( 201, { "Content-Type": "application/json", "unittest": "task-failure" }, json.dumps(resp), ) responses.add_callback( responses.POST, "http://phabricator.test/api/differential.createcomment", callback=_check_comment, ) with mock_phabricator as api: revision = Revision(api, mock_try_task) reporter = PhabricatorReporter( { "analyzers": ["clang-tidy"], "modes": ("comment") }, api=api) status = {"task": {"metadata": {"name": "mock-infer"}}, "status": {}} task = ClangTidyTask("erroneousTaskId", status) issues, patches = reporter.publish([], revision, [task]) assert len(issues) == 0 assert len(patches) == 0 # Check the callback has been used assert len(responses.calls) > 0 call = responses.calls[-1] assert call.request.url == "http://phabricator.test/api/differential.createcomment" assert call.response.headers.get("unittest") == "task-failure"
def build_task(self, task_id, task_status): """ Create a specific implementation of AnalysisTask according to the task name """ try: name = task_status["task"]["metadata"]["name"] except KeyError: raise Exception("Cannot read task name {}".format(task_id)) if name.startswith("source-test-mozlint-"): return MozLintTask(task_id, task_status) elif name == "source-test-clang-tidy": return ClangTidyTask(task_id, task_status) elif name == "source-test-clang-format": return ClangFormatTask(task_id, task_status) elif name in ("source-test-coverity-coverity", "coverity"): return CoverityTask(task_id, task_status) elif name == "source-test-infer-infer": return InferTask(task_id, task_status) else: raise Exception("Unsupported task {}".format(name))