Skip to content
Draft
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
65 changes: 49 additions & 16 deletions pr_review_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
# global variable
slack_nicks = []

# Using Slack format
slack_format = True

def format_link(text, link):
global slack_format

if slack_format:
return f"<{link}|{text}>"
else:
return f"[{text}]({link})"

def decrypt(data, key):
"""
Expand Down Expand Up @@ -65,7 +75,7 @@ def get_slack_userid(github_login):
Return the unencrypted Slack userid
"""
global slack_nicks
username = f"<https://github.com/{github_login}|@{github_login}>"
username = format_link(f"@{github_login}", f"https://github.com/{github_login}")
if slack_nicks:
for github_username, slack_userid in slack_nicks:
if github_username == github_login:
Expand All @@ -83,7 +93,7 @@ def mask_slack_userids(message):
ret = message
if slack_nicks:
for github_username, slack_userid in slack_nicks:
username = f"<https://github.com/{github_username}|@{github_username}>"
username = format_link(f"@{github_username}", f"https://github.com/{github_username}")
ret = ret.replace(f"<@{slack_userid}>", username)
return ret
return "no valid slack_nicks - masking full message"
Expand Down Expand Up @@ -187,7 +197,15 @@ def get_commit_status(github_api, repo, pull_request_details):
state = "🟠"
# Check if the state is not really 'pending' but if there is actually none
single_status = github_api.repos.list_commit_statuses_for_ref(repo=repo,ref=head["sha"])
if single_status == []:
# Check if all pending status are only waiting for manual trigger
all_running = 0
for ss in status.statuses:
if ss.state == "pending" and ss.description == "Manual testing required":
continue
else:
all_running += 1
# If there is no status or all are waiting for manual trigger mark it as green
if single_status == [] or all_running == 0:
# The combined_status should still be a success if all check runs have passed
if check_run_status == "success":
state = "🟢"
Expand Down Expand Up @@ -343,13 +361,13 @@ def find_jira_key(pr_title, pr_html_url):
"""
Look for a Jira key, when found generate a hyperlink and return the new pr_title_link
"""
pr_title_link = f"<{pr_html_url}|{pr_title}>"
pr_title_link = format_link(pr_title, pr_html_url)

match = re.match(r"([A-Z]+\-\d+)([: -]+)(.+)", pr_title)
if match:
jira_key, separator, title_remainder = match.groups()
if jira_key:
pr_title_link = f"{generate_jira_link(jira_key)}{separator}<{pr_html_url}|{title_remainder}>"
pr_title_link = f"{generate_jira_link(jira_key)}{separator}{format_link(title_remainder, pr_html_url)}"

return pr_title_link

Expand Down Expand Up @@ -397,8 +415,7 @@ def create_pr_review_queue(pull_request_list):
reviewers = ', '.join(get_slack_userid(requested_reviewer['login']) for requested_reviewer in pull_request['requested_reviewers'])
needs_review.append(f"{entry} {reviewers}")
# 4. Needs conflict resolution or rebasing
elif (not pull_request['changes_requested'] and
(pull_request['mergeable_state'] in {'dirty', 'behind'})):
elif (pull_request['mergeable_state'] in {'dirty', 'behind'}):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand and agree with the motivation for this change, but won't this lead to PRs showing up twice on the list?

needs_conflict_resolution.append(f"{entry} {pull_request['login']}")

return needs_reviewer, needs_changes, needs_review, needs_conflict_resolution
Expand All @@ -412,10 +429,15 @@ def main():
parser.add_argument("--repo", help="Set a repo in `--org` on github.com", required=False)
parser.add_argument("--queue", help="Create a review queue", default=True,
action=argparse.BooleanOptionalAction)
parser.add_argument("--slack-format", help="Generate slack format, otherwise use markdown", default=True,
action=argparse.BooleanOptionalAction)
parser.add_argument("--dry-run", help="Don't send Slack notifications", default=False,
action=argparse.BooleanOptionalAction)
args = parser.parse_args()

global slack_format
slack_format = args.slack_format

github_api = GhApi(owner=args.org, token=args.github_token)

init_slack_userlist()
Expand All @@ -430,15 +452,26 @@ def main():
print("No pull requests found that match our criteria. Exiting.")
sys.exit(0)

message = ("Good morning, image builders! :meow_wave:")
if needs_reviewer != []:
message += "\n\n:frog-derp: *We need a reviewer*\n • " + "\n • ".join(needs_reviewer)
if needs_changes != []:
message += "\n\n:changes_requested: *We need changes*\n • " + "\n • ".join(needs_changes)
if needs_review != []:
message += "\n\n:frog-flushed: *We need a review*\n • " + "\n • ".join(needs_review)
if needs_conflict_resolution != []:
message += "\n\n:expressionless-meow: *Update required*\n • " + "\n • ".join(needs_conflict_resolution)
if slack_format:
message = ("Good morning, image builders! :meow_wave:")
if needs_reviewer != []:
message += "\n\n:frog-derp: *We need a reviewer*\n • " + "\n • ".join(needs_reviewer)
if needs_changes != []:
message += "\n\n:changes_requested: *We need changes*\n • " + "\n • ".join(needs_changes)
if needs_review != []:
message += "\n\n:frog-flushed: *We need a review*\n • " + "\n • ".join(needs_review)
if needs_conflict_resolution != []:
message += "\n\n:expressionless-meow: *Update required*\n • " + "\n • ".join(needs_conflict_resolution)
else:
message = ("Good morning team!")
if needs_reviewer != []:
message += "\n\n**We need a reviewer**\n * " + "\n * ".join(needs_reviewer)
if needs_changes != []:
message += "\n\n**We need changes**\n * " + "\n * ".join(needs_changes)
if needs_review != []:
message += "\n\n**We need a review**\n * " + "\n * ".join(needs_review)
if needs_conflict_resolution != []:
message += "\n\n**Update required**\n * " + "\n * ".join(needs_conflict_resolution)

slack_notify(message, args.dry_run)

Expand Down