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_infer_artifact(version, nb, mock_revision, mock_hgmo): """ Test Infer artifact per version, comparing a raw artifact processed and expected issues list """ with open(os.path.join(FIXTURES_DIR, f"infer_artifact_{version}.json")) as f: artifact = json.load(f) status = {"task": {"metadata": {"name": "mock-infer"}}, "status": {}} task = InferTask("someTaskId", status) issues = task.parse_issues({"public/code-review/infer.json": artifact}, mock_revision) assert len(artifact) == len(issues) == nb issues_data = [issue.as_dict() for issue in issues] with open(os.path.join(FIXTURES_DIR, f"infer_issues_{version}.json")) as f: assert issues_data == json.load(f)
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))
def test_publication(tmpdir, mock_issues, mock_revision): """ Test debug publication and report analysis """ from code_review_bot.report.debug import DebugReporter # Load description from Taskcluster tasks mock_revision.setup_try( "decision", { # Base information are retrieved from the decision task "decision": { "task": { "metadata": { "name": "Mock decision task" }, "payload": { "image": "taskcluster/decision", "env": { "GECKO_HEAD_REV": "deadc0ffee", "GECKO_HEAD_REPOSITORY": "https://hg.mozilla.org/try", "GECKO_BASE_REPOSITORY": "https://hg.mozilla.org/mozilla-central", }, }, } } }, ) report_dir = str(tmpdir.mkdir("public").realpath()) report_path = os.path.join(report_dir, "report.json") assert not os.path.exists(report_path) status = {"task": {"metadata": {"name": "mock-infer"}}, "status": {}} task = InferTask("someTaskId", status) r = DebugReporter(report_dir) r.publish(mock_issues, mock_revision, [task], []) assert os.path.exists(report_path) with open(report_path) as f: report = json.load(f) assert "issues" in report assert report["issues"] == [{ "nb": 0 }, { "nb": 1 }, { "nb": 2 }, { "nb": 3 }, { "nb": 4 }] assert "revision" in report assert report["revision"] == { "id": 51, "diff_id": 42, "url": "https://phabricator.test/D51", "bugzilla_id": 1234567, "diff_phid": "PHID-DIFF-test", "phid": "PHID-DREV-zzzzz", "title": "Static Analysis tests", "has_clang_files": False, "repository": "https://hg.mozilla.org/try", "target_repository": "https://hg.mozilla.org/mozilla-central", "mercurial_revision": "deadc0ffee", } assert "task_failures" in report assert report["task_failures"] == [{ "id": "someTaskId", "name": "mock-infer" }] assert "time" in report assert isinstance(report["time"], float)