Skip to content

Commit

Permalink
feat(ask-review): Add the requester to the ask-review message
Browse files Browse the repository at this point in the history
  • Loading branch information
chouetz committed Jan 2, 2025
1 parent 5fa6f8b commit a8ab65c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tasks/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from invoke import task

from tasks.libs.ciproviders.github_api import GithubAPI
from tasks.libs.ciproviders.github_api import GithubAPI, ask_review_actor
from tasks.libs.issue.assign import assign_with_model, assign_with_rules
from tasks.libs.issue.model.actions import fetch_data_and_train_model
from tasks.libs.pipeline.notifications import GITHUB_SLACK_MAP, GITHUB_SLACK_REVIEW_MAP
Expand Down Expand Up @@ -82,6 +82,7 @@ def ask_reviews(_, pr_id):
gh = GithubAPI()
pr = gh.repo.get_pull(int(pr_id))
if any(label.name == 'ask-review' for label in pr.get_labels()):
actor = ask_review_actor(pr)
reviewers = [f"@datadog/{team.slug}" for team in pr.requested_teams]

from slack_sdk import WebClient
Expand All @@ -92,11 +93,11 @@ def ask_reviews(_, pr_id):
(chan for team, chan in GITHUB_SLACK_REVIEW_MAP.items() if team.casefold() == reviewer.casefold()),
'#agent-devx-help',
)
message = f'Hello :{random.choice(WAVES)}:! Can you please review <{pr.html_url}/s|{pr.title}>?\n Thanks in advance!'
message = f'Hello :{random.choice(WAVES)}:!\n*{actor}* would like you to review <{pr.html_url}/s|{pr.title}>?\nThanks in advance!'
if channel == '#agent-devx-help':
message = f'Hello :{random.choice(WAVES)}:!\nA review channel is missing for {reviewer}, can you please ask them to update `github_slack_review_map.yaml` and transfer them this review <{pr.html_url}/s|{pr.title}>?\n Thanks in advance!'
try:
client.chat_postMessage(channel=channel, text=message)
except Exception as e:
message = f"An error occurred while sending a review message for PR <{pr.html_url}/s|{pr.title}> to channel {channel}. Error: {e}"
message = f"An error occurred while sending a review message from {actor} for PR <{pr.html_url}/s|{pr.title}> to channel {channel}. Error: {e}"
client.chat_postMessage(channel='#agent-devx-ops', text=message)
6 changes: 6 additions & 0 deletions tasks/libs/ciproviders/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,9 @@ def create_release_pr(title, base_branch, target_branch, version, changelog_pr=F
print(color_message(f"Done creating new PR. Link: {updated_pr.html_url}", "bold"))

return updated_pr.html_url


def ask_review_actor(pr):
for event in pr.get_issue_events():
if event.event == "labeled" and event.label.name == "ask-review":
return event.actor.name or event.actor.login

0 comments on commit a8ab65c

Please sign in to comment.