Skip to content

Commit

Permalink
Change logic for ne news
Browse files Browse the repository at this point in the history
  • Loading branch information
bobleesj authored Sep 19, 2024
1 parent a2a108d commit fc41569
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions .github/workflows/check-news.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Check if the PR has a news item.
Put a warning comment and fail the CI if it doesn't.
Code modified from https://github.com/xonsh/xonsh
Put a warning comment if it doesn't.
"""

import os
Expand All @@ -11,17 +9,15 @@
from github import Github, PullRequest


def check_news_file(pr: PullRequest.PullRequest):
# Get the list of files changed in the PR
changed_files = pr.get_files()
pattern = 'news/*.rst'
for file in changed_files:
if (
file.status == 'added' and
fnmatch(file.filename, pattern)
):
return True
return False
def get_added_files(pr: PullRequest.PullRequest):
print(pr, pr.number)
for file in pr.get_files():
if file.status == "added":
yield file.filename


def check_news_file(pr):
return any(map(lambda file_name: fnmatch(file_name, "news/*.rst"), get_added_files(pr)))


def get_pr_number():
Expand All @@ -45,18 +41,20 @@ def main():
has_news_added = check_news_file(pr)
old_comment = get_old_comment(pr)

if old_comment:
print("Found an existing comment from bot")
if has_news_added:
print("Delete warning from bot, since news items is added.")
if has_news_added:
if old_comment:
print("Found an existing comment from bot")
print("Delete warning from bot, since news item is added.")
old_comment.delete()
elif not has_news_added:
else:
print("No news item found")

pr.create_issue_comment(
"""\
**Warning!** No news item is found for this PR. If this is an user facing change/feature/fix,
please add a news item by copying the format from `news/TEMPLATE.rst`.
if old_comment:
print("Old warning remains relevant, no action needed.")
else:
pr.create_issue_comment(
"""\
**Warning!** No news item is found for this PR. If this is a user-facing change/feature/fix,
please add a news item by copying the format from `news/TEMPLATE.rst`.
"""
)
assert False
Expand Down

0 comments on commit fc41569

Please sign in to comment.