From a8ab65c86ac6f0994cca391d1db51ebb82d89bc0 Mon Sep 17 00:00:00 2001 From: Nicolas Schweitzer Date: Thu, 2 Jan 2025 15:49:33 +0100 Subject: [PATCH 1/2] feat(ask-review): Add the requester to the ask-review message --- tasks/issue.py | 7 ++++--- tasks/libs/ciproviders/github_api.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tasks/issue.py b/tasks/issue.py index 92e4d1ee1cb98b..9efc73b9b52d44 100644 --- a/tasks/issue.py +++ b/tasks/issue.py @@ -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 @@ -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 @@ -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) diff --git a/tasks/libs/ciproviders/github_api.py b/tasks/libs/ciproviders/github_api.py index 54a3ba49a43f15..63fcfeb09a2047 100644 --- a/tasks/libs/ciproviders/github_api.py +++ b/tasks/libs/ciproviders/github_api.py @@ -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 From c5c6b8d43f8a76dc7a704e2841ad8c0653db5e97 Mon Sep 17 00:00:00 2001 From: Nicolas Schweitzer Date: Thu, 2 Jan 2025 17:04:13 +0100 Subject: [PATCH 2/2] Trigger the workflow only on the specific label to prevent multiple messages --- .github/workflows/label-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-analysis.yml b/.github/workflows/label-analysis.yml index 34380a5eb218ed..b0154672ef868a 100644 --- a/.github/workflows/label-analysis.yml +++ b/.github/workflows/label-analysis.yml @@ -140,7 +140,7 @@ jobs: run: inv -e github.agenttelemetry-list-change-ack-check --pr-id=${{ github.event.pull_request.number }} ask-reviews: - if: github.triggering_actor != 'dd-devflow[bot]' && github.event.action != 'synchronize' + if: github.triggering_actor != 'dd-devflow[bot]' && github.event.action == 'labeled' && github.event.label.name == 'ask-review' runs-on: ubuntu-latest steps: - name: Checkout repository