From 43b7c174740238a1aa21d068d79dbc38cf9c3953 Mon Sep 17 00:00:00 2001 From: Alison Shao <54658187+alisonshao@users.noreply.github.com> Date: Sat, 20 Dec 2025 19:50:56 -0800 Subject: [PATCH] [CI] Fix /rerun-stage command by using requests for workflow dispatch (#15447) --- scripts/ci/slash_command_handler.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/ci/slash_command_handler.py b/scripts/ci/slash_command_handler.py index ad04de6ad..07a6ef1ef 100644 --- a/scripts/ci/slash_command_handler.py +++ b/scripts/ci/slash_command_handler.py @@ -2,6 +2,7 @@ import json import os import sys +import requests from github import Auth, Github # Configuration @@ -118,7 +119,7 @@ def handle_rerun_failed_ci(gh_repo, pr, comment, user_perms, react_on_success=Tr def handle_rerun_stage( - gh_repo, pr, comment, user_perms, stage_name, react_on_success=True + gh_repo, pr, comment, user_perms, stage_name, token, react_on_success=True ): """ Handles the /rerun-stage command. @@ -221,10 +222,19 @@ def handle_rerun_stage( else: inputs = {"version": "release", "target_stage": stage_name} - success = target_workflow.create_dispatch( - ref=ref, - inputs=inputs, + # Use requests directly as PyGithub's create_dispatch only accepts HTTP 204 + dispatch_url = f"https://api.github.com/repos/{gh_repo.full_name}/actions/workflows/{target_workflow.id}/dispatches" + dispatch_resp = requests.post( + dispatch_url, + json={"ref": ref, "inputs": inputs}, + headers={ + "Authorization": f"Bearer {token}", + "Accept": "application/vnd.github+json", + }, ) + success = dispatch_resp.status_code in (200, 204) + if not success: + print(f"Dispatch failed: {dispatch_resp.status_code} {dispatch_resp.text}") if success: print(f"Successfully triggered workflow for stage '{stage_name}'") @@ -304,7 +314,7 @@ def main(): # Extract stage name from command parts = first_line.split(maxsplit=1) stage_name = parts[1].strip() if len(parts) > 1 else None - handle_rerun_stage(repo, pr, comment, user_perms, stage_name) + handle_rerun_stage(repo, pr, comment, user_perms, stage_name, token) else: print(f"Unknown or ignored command: {first_line}")