Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the comment marker format #1359

Merged
merged 3 commits into from
Mar 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions megalinter/reporters/GithubCommentReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ def comment_marker(self):

This marker is used to find the same comment again so it can be updated.

The marker includes the workflow name and jobid if available (via the
GITHUB_WORKFLOW and GITHUB_JOB environment variables) to avoid clashes
between multiple Mega-Linter jobs operating on the same PR:

<!-- megalinter: github-comment-reporter workflow='...' jobid='...' -->

"""
workflow = os.getenv("GITHUB_WORKFLOW", "")
jobid = os.getenv("GITHUB_JOB", "")
identifier = "".join(filter(None, (workflow, jobid)))
identifier_with_padding = identifier and f" {identifier}"
return f"<!-- megalinter: github-comment-reporter{identifier_with_padding} -->"
workflow = os.getenv("GITHUB_WORKFLOW")
jobid = os.getenv("GITHUB_JOB")
workflow = workflow and f"workflow={workflow!r}"
jobid = jobid and f"jobid={jobid!r}"
identifier = " ".join(
["github-comment-reporter", *filter(None, (workflow, jobid))]
)
return f"<!-- megalinter: {identifier} -->"

def produce_report(self):
# Post comment on GitHub pull request
Expand Down