From 95a94ca00f00e041ca5b12f2346517e009bf48db Mon Sep 17 00:00:00 2001 From: nvuillam Date: Wed, 24 Jan 2024 20:09:56 +0100 Subject: [PATCH 1/2] Activate CI servers reporters only if we find a related default env variable Fixes https://github.com/oxsecurity/megalinter/issues/3317 --- CHANGELOG.md | 1 + megalinter/reporters/AzureCommentReporter.py | 4 +++- megalinter/reporters/BitbucketCommentReporter.py | 6 ++++-- megalinter/reporters/GithubCommentReporter.py | 4 +++- megalinter/reporters/GitlabCommentReporter.py | 2 ++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26b6ef44822..ba56403ca88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l - New linters - Fixes + - Activate CI servers reporters only if we find a related default env variable - Doc diff --git a/megalinter/reporters/AzureCommentReporter.py b/megalinter/reporters/AzureCommentReporter.py index 8142328f4b2..80988d48bda 100644 --- a/megalinter/reporters/AzureCommentReporter.py +++ b/megalinter/reporters/AzureCommentReporter.py @@ -26,7 +26,9 @@ class AzureCommentReporter(Reporter): scope = "mega-linter" def manage_activation(self): - if ( + if not config.exists(self.master.request_id,"SYSTEM_COLLECTIONURI"): + self.is_active = False + elif ( config.get(self.master.request_id, "AZURE_COMMENT_REPORTER", "true") != "true" ): diff --git a/megalinter/reporters/BitbucketCommentReporter.py b/megalinter/reporters/BitbucketCommentReporter.py index 3cee301e495..baf9bfd8917 100644 --- a/megalinter/reporters/BitbucketCommentReporter.py +++ b/megalinter/reporters/BitbucketCommentReporter.py @@ -18,9 +18,11 @@ class BitbucketCommentReporter(Reporter): BITBUCKET_API = "https://api.bitbucket.org/2.0" def manage_activation(self): - if ( + if not config.exists(self.master.request_id,"BITBUCKET_REPO_FULL_NAME"): + self.is_active = False + elif ( config.get(self.master.request_id, "BITBUCKET_COMMENT_REPORTER", "true") - == "true" + == "true" ): self.is_active = True else: diff --git a/megalinter/reporters/GithubCommentReporter.py b/megalinter/reporters/GithubCommentReporter.py index fde46088013..6b0fa46f95b 100644 --- a/megalinter/reporters/GithubCommentReporter.py +++ b/megalinter/reporters/GithubCommentReporter.py @@ -22,7 +22,9 @@ class GithubCommentReporter(Reporter): issues_root = ML_REPO_URL + "/issues" def manage_activation(self): - if ( + if not config.exists(self.master.request_id, "GITHUB_REPOSITORY"): + self.is_active = False + elif ( config.get(self.master.request_id, "GITHUB_COMMENT_REPORTER", "true") != "true" ): diff --git a/megalinter/reporters/GitlabCommentReporter.py b/megalinter/reporters/GitlabCommentReporter.py index 8c851e94690..d15d5ed8e11 100644 --- a/megalinter/reporters/GitlabCommentReporter.py +++ b/megalinter/reporters/GitlabCommentReporter.py @@ -18,6 +18,8 @@ class GitlabCommentReporter(Reporter): gitlab_server_url = "https://gitlab.com" def manage_activation(self): + if not config.exists(self.master.request_id,"CI_JOB_TOKEN"): + self.is_active = False if ( config.get(self.master.request_id, "GITLAB_COMMENT_REPORTER", "true") != "true" From 00440c42de277c19dcc081192f60466bb40493f6 Mon Sep 17 00:00:00 2001 From: nvuillam Date: Wed, 24 Jan 2024 19:16:00 +0000 Subject: [PATCH 2/2] [MegaLinter] Apply linters fixes --- megalinter/reporters/AzureCommentReporter.py | 2 +- megalinter/reporters/BitbucketCommentReporter.py | 4 ++-- megalinter/reporters/GithubCommentReporter.py | 2 +- megalinter/reporters/GitlabCommentReporter.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/megalinter/reporters/AzureCommentReporter.py b/megalinter/reporters/AzureCommentReporter.py index 80988d48bda..e9a0af77a21 100644 --- a/megalinter/reporters/AzureCommentReporter.py +++ b/megalinter/reporters/AzureCommentReporter.py @@ -26,7 +26,7 @@ class AzureCommentReporter(Reporter): scope = "mega-linter" def manage_activation(self): - if not config.exists(self.master.request_id,"SYSTEM_COLLECTIONURI"): + if not config.exists(self.master.request_id, "SYSTEM_COLLECTIONURI"): self.is_active = False elif ( config.get(self.master.request_id, "AZURE_COMMENT_REPORTER", "true") diff --git a/megalinter/reporters/BitbucketCommentReporter.py b/megalinter/reporters/BitbucketCommentReporter.py index baf9bfd8917..9a93c6003bd 100644 --- a/megalinter/reporters/BitbucketCommentReporter.py +++ b/megalinter/reporters/BitbucketCommentReporter.py @@ -18,11 +18,11 @@ class BitbucketCommentReporter(Reporter): BITBUCKET_API = "https://api.bitbucket.org/2.0" def manage_activation(self): - if not config.exists(self.master.request_id,"BITBUCKET_REPO_FULL_NAME"): + if not config.exists(self.master.request_id, "BITBUCKET_REPO_FULL_NAME"): self.is_active = False elif ( config.get(self.master.request_id, "BITBUCKET_COMMENT_REPORTER", "true") - == "true" + == "true" ): self.is_active = True else: diff --git a/megalinter/reporters/GithubCommentReporter.py b/megalinter/reporters/GithubCommentReporter.py index 6b0fa46f95b..09e58e2256b 100644 --- a/megalinter/reporters/GithubCommentReporter.py +++ b/megalinter/reporters/GithubCommentReporter.py @@ -23,7 +23,7 @@ class GithubCommentReporter(Reporter): def manage_activation(self): if not config.exists(self.master.request_id, "GITHUB_REPOSITORY"): - self.is_active = False + self.is_active = False elif ( config.get(self.master.request_id, "GITHUB_COMMENT_REPORTER", "true") != "true" diff --git a/megalinter/reporters/GitlabCommentReporter.py b/megalinter/reporters/GitlabCommentReporter.py index d15d5ed8e11..d9ac8c282b3 100644 --- a/megalinter/reporters/GitlabCommentReporter.py +++ b/megalinter/reporters/GitlabCommentReporter.py @@ -18,7 +18,7 @@ class GitlabCommentReporter(Reporter): gitlab_server_url = "https://gitlab.com" def manage_activation(self): - if not config.exists(self.master.request_id,"CI_JOB_TOKEN"): + if not config.exists(self.master.request_id, "CI_JOB_TOKEN"): self.is_active = False if ( config.get(self.master.request_id, "GITLAB_COMMENT_REPORTER", "true")