Skip to content

Commit

Permalink
Fix org identifier and add job url
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed May 19, 2024
1 parent f225ebf commit a93c4b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 9 additions & 5 deletions megalinter/reporters/ApiReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def build_payload(self):
# Git info
repo_info = get_git_context_info(self.master.request_id, os.path.realpath(self.master.github_workspace))
git_identifier = f"{repo_info["repo_name"]}/{repo_info["branch_name"]}"
org_identifier = self.get_org_identifier(git_identifier)
org_identifier = self.get_org_identifier(repo_info["branch_name"])
self.payload = {
"source": "MegaLinter",
"gitRepoName": repo_info["repo_name"],
Expand All @@ -75,7 +75,6 @@ def build_payload(self):
"descriptor": linter.descriptor_id,
"linter": linter.linter_name,
"linterKey": linter.name,
"linterDocUrl": linter_doc_url,
"data": {},
}
# Status
Expand All @@ -88,7 +87,10 @@ def build_payload(self):
else "error"
)
)
linter_payload_data = {}
linter_payload_data = {
"linterDocUrl": linter_doc_url,
"jobUrl": repo_info["job_url"]
}
linter_payload_data["severityIcon"] = (
"✅"
if linter.status == "success" and linter.return_code == 0
Expand All @@ -114,13 +116,15 @@ def build_payload(self):
self.payload["linters"].append(linter_payload)


def get_org_identifier(self, git_identifier: str):
def get_org_identifier(self, branch_name: str):
org_identifier = config.get(
self.master.request_id, "API_REPORTER_ORG_IDENTIFIER", None
)
if org_identifier is not None:
return org_identifier
return git_identifier.replace("monitoring_","").replace("__","--").replace("_sandbox",".sandbox")
# Workaround for sfdx-hardis, but it's better to set ENV variable API_REPORTER_ORG_IDENTIFIER
return branch_name.replace("monitoring_","").replace(
"_","-").replace("__","--").replace("_sandbox","__sandbox")


def format_payload(self):
Expand Down
14 changes: 13 additions & 1 deletion megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def is_git_repo(path):
return False

def get_git_context_info(request_id, path):
# Repo name
repo_name = config.get_first_var_set(
request_id,
[
Expand All @@ -329,6 +330,7 @@ def get_git_context_info(request_id, path):
None)
if repo_name is not None:
repo_name = repo_name.split("/")[-1] #Get last portion
# Branch name
branch_name = config.get_first_var_set(
request_id,
[
Expand Down Expand Up @@ -360,9 +362,19 @@ def get_git_context_info(request_id, path):
branch_name = branch.name
except Exception as e:
branch_name = "?"
# Job URL
job_url = config.get_first_var_set(
request_id,
[
"GITHUB_JOB_URL",
"CI_JOB_URL"
# TODO: Handle Azure, BitBucket & Jenkins
],
"")
return {
"repo_name": repo_name,
"branch_name": branch_name
"branch_name": branch_name,
"job_url": job_url
}


Expand Down

0 comments on commit a93c4b5

Please sign in to comment.