Skip to content

Commit a93c4b5

Browse files
committed
Fix org identifier and add job url
1 parent f225ebf commit a93c4b5

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

megalinter/reporters/ApiReporter.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def build_payload(self):
5454
# Git info
5555
repo_info = get_git_context_info(self.master.request_id, os.path.realpath(self.master.github_workspace))
5656
git_identifier = f"{repo_info["repo_name"]}/{repo_info["branch_name"]}"
57-
org_identifier = self.get_org_identifier(git_identifier)
57+
org_identifier = self.get_org_identifier(repo_info["branch_name"])
5858
self.payload = {
5959
"source": "MegaLinter",
6060
"gitRepoName": repo_info["repo_name"],
@@ -75,7 +75,6 @@ def build_payload(self):
7575
"descriptor": linter.descriptor_id,
7676
"linter": linter.linter_name,
7777
"linterKey": linter.name,
78-
"linterDocUrl": linter_doc_url,
7978
"data": {},
8079
}
8180
# Status
@@ -88,7 +87,10 @@ def build_payload(self):
8887
else "error"
8988
)
9089
)
91-
linter_payload_data = {}
90+
linter_payload_data = {
91+
"linterDocUrl": linter_doc_url,
92+
"jobUrl": repo_info["job_url"]
93+
}
9294
linter_payload_data["severityIcon"] = (
9395
"✅"
9496
if linter.status == "success" and linter.return_code == 0
@@ -114,13 +116,15 @@ def build_payload(self):
114116
self.payload["linters"].append(linter_payload)
115117

116118

117-
def get_org_identifier(self, git_identifier: str):
119+
def get_org_identifier(self, branch_name: str):
118120
org_identifier = config.get(
119121
self.master.request_id, "API_REPORTER_ORG_IDENTIFIER", None
120122
)
121123
if org_identifier is not None:
122124
return org_identifier
123-
return git_identifier.replace("monitoring_","").replace("__","--").replace("_sandbox",".sandbox")
125+
# Workaround for sfdx-hardis, but it's better to set ENV variable API_REPORTER_ORG_IDENTIFIER
126+
return branch_name.replace("monitoring_","").replace(
127+
"_","-").replace("__","--").replace("_sandbox","__sandbox")
124128

125129

126130
def format_payload(self):

megalinter/utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def is_git_repo(path):
317317
return False
318318

319319
def get_git_context_info(request_id, path):
320+
# Repo name
320321
repo_name = config.get_first_var_set(
321322
request_id,
322323
[
@@ -329,6 +330,7 @@ def get_git_context_info(request_id, path):
329330
None)
330331
if repo_name is not None:
331332
repo_name = repo_name.split("/")[-1] #Get last portion
333+
# Branch name
332334
branch_name = config.get_first_var_set(
333335
request_id,
334336
[
@@ -360,9 +362,19 @@ def get_git_context_info(request_id, path):
360362
branch_name = branch.name
361363
except Exception as e:
362364
branch_name = "?"
365+
# Job URL
366+
job_url = config.get_first_var_set(
367+
request_id,
368+
[
369+
"GITHUB_JOB_URL",
370+
"CI_JOB_URL"
371+
# TODO: Handle Azure, BitBucket & Jenkins
372+
],
373+
"")
363374
return {
364375
"repo_name": repo_name,
365-
"branch_name": branch_name
376+
"branch_name": branch_name,
377+
"job_url": job_url
366378
}
367379

368380

0 commit comments

Comments
 (0)