mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Avoid repeating the pr comment message if the content is the same
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
f6f1333da9
commit
1de32fcfdb
2 changed files with 15 additions and 9 deletions
4
.github/workflows/pr-checks.yml
vendored
4
.github/workflows/pr-checks.yml
vendored
|
@ -45,7 +45,9 @@ jobs:
|
|||
shell: bash
|
||||
run: |
|
||||
set -o pipefail
|
||||
pre-commit run -v --hook-stage manual check-known-missing-docstrings --show-diff-on-failure --color=never --files ${{ join(fromJSON(steps.changed-files.outputs.salt_files), ' ') }} | tee output.txt
|
||||
pre-commit run --hook-stage manual check-known-missing-docstrings \
|
||||
--show-diff-on-failure --color=never \
|
||||
--files ${{ join(fromJSON(steps.changed-files.outputs.salt_files), ' ') }} | tee output.txt
|
||||
|
||||
- name: Comment on PR
|
||||
# Comment on PRs if pre-commit triggered a failure
|
||||
|
|
|
@ -58,20 +58,15 @@ Thanks again!
|
|||
"""
|
||||
|
||||
|
||||
def delete_previous_comments(pr, created_comment_id):
|
||||
def get_previous_comments(pr):
|
||||
for comment in pr.get_issue_comments():
|
||||
if comment.user.login != "github-actions[bot]":
|
||||
# Not a comment made by this bot
|
||||
continue
|
||||
if comment.id == created_comment_id:
|
||||
# This is the comment we have just created
|
||||
continue
|
||||
if not comment.body.startswith(COMMENT_HEADER):
|
||||
# This comment does not start with our header
|
||||
continue
|
||||
# We have a match, delete it
|
||||
print(f"Deleting previous comment {comment}")
|
||||
comment.delete()
|
||||
yield comment
|
||||
|
||||
|
||||
def comment_on_pr(options, issues_output):
|
||||
|
@ -87,8 +82,17 @@ def comment_on_pr(options, issues_output):
|
|||
comment_header=COMMENT_HEADER, issues_output=issues_output
|
||||
)
|
||||
)
|
||||
new_comment_content = COMMENT_TEMPLATE.format(
|
||||
comment_header=COMMENT_HEADER, issues_output=issues_output
|
||||
)
|
||||
for comment in get_previous_comments(pr):
|
||||
if comment.body.strip() != new_comment_content.strip():
|
||||
# The content has changed.
|
||||
print(f"Deleting previous comment {comment}")
|
||||
comment.delete()
|
||||
|
||||
comment = pr.create_issue_comment(new_comment_content)
|
||||
print(f"Created Comment: {comment}")
|
||||
delete_previous_comments(pr, comment.id)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Add table
Reference in a new issue