Skip to content

Commit

Permalink
Support markdown format as well
Browse files Browse the repository at this point in the history
  • Loading branch information
marusak committed Jan 22, 2024
1 parent efb47de commit bd2e16d
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 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 @@ -351,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 @@ -419,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 @@ -437,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

0 comments on commit bd2e16d

Please sign in to comment.