Skip to content

Commit

Permalink
Fix Grafana job url for GitHub, Azure & Bitbucket (#3880)
Browse files Browse the repository at this point in the history
* Fix job url for GitHub, Azure & Bitbucket

* [MegaLinter] Apply linters fixes

* Change format of prometheus payload

---------

Co-authored-by: nvuillam <[email protected]>
  • Loading branch information
nvuillam and nvuillam authored Aug 18, 2024
1 parent 841a345 commit b1eb99c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
6 changes: 2 additions & 4 deletions megalinter/reporters/ApiReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,15 @@ def build_metrics_payload(self):
all_metrics_lines = []
for linter in self.master.linters:
if linter.is_active is True:
metric_id = linter.linter_name
metric_line = (
metric_id
+ ","
"linter_run,"
+ metric_base_tags
+ f"descriptor={linter.descriptor_id},"
+ f"linter={linter.linter_name},"
+ f"linterKey={linter.name}"
+ " "
)
metric_line += f"metric={linter.total_number_errors}"
metric_line += f"numberErrorsFound={linter.total_number_errors}"
# Number of files & errors
if linter.cli_lint_mode != "project":
metric_line += f",numberFilesFound={len(linter.files)}"
Expand Down
34 changes: 33 additions & 1 deletion megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import re
import tempfile
import urllib.parse
from fnmatch import fnmatch
from typing import Any, Optional, Pattern, Sequence

Expand Down Expand Up @@ -371,10 +372,41 @@ def get_git_context_info(request_id, path):
[
"GITHUB_JOB_URL",
"CI_JOB_URL",
# TODO: Handle Azure, BitBucket & Jenkins
],
"",
)
# GitHub job url
if job_url == "" and config.get(request_id, "GITHUB_REPOSITORY", "") != "":
github_server_url = config.get(
request_id, "GITHUB_SERVER_URL", "https://github.com"
)
github_repo = config.get(request_id, "GITHUB_REPOSITORY")
run_id = config.get(request_id, "GITHUB_RUN_ID")
job_url = f"{github_server_url}/{github_repo}/actions/runs/{run_id}"
# Azure Job url
elif job_url == "" and config.get(request_id, "SYSTEM_COLLECTIONURI", "") != "":
SYSTEM_COLLECTIONURI = config.get(request_id, "SYSTEM_COLLECTIONURI")
SYSTEM_TEAMPROJECT = urllib.parse.quote(
config.get(request_id, "SYSTEM_TEAMPROJECT")
)
BUILD_BUILDID = config.get(
request_id,
"BUILD_BUILDID",
config.get(request_id, "BUILD_BUILD_ID"),
)
job_url = f"{SYSTEM_COLLECTIONURI}{SYSTEM_TEAMPROJECT}/_build/results?buildId={BUILD_BUILDID}"
# BitBucket job url
elif job_url == "" and config.get(request_id, "BITBUCKET_STEP_UUID", "") != "":
bitbucket_project_url = config.get(request_id, "BITBUCKET_GIT_HTTP_ORIGIN", "")
bitbucket_pipeline_job_number = config.get(
request_id, "BITBUCKET_BUILD_NUMBER", ""
)
pipeline_step_run_uuid = config.get(request_id, "BITBUCKET_STEP_UUID", "")
pipeline_step_run_uuid = urllib.parse.quote(pipeline_step_run_uuid)
job_url = (
f"{bitbucket_project_url}/pipelines/results/"
f"{bitbucket_pipeline_job_number}/steps/{pipeline_step_run_uuid}"
)
return {"repo_name": repo_name, "branch_name": branch_name, "job_url": job_url}


Expand Down

0 comments on commit b1eb99c

Please sign in to comment.