33"""
44
55import logging
6- import os
76from datetime import datetime , timedelta
87from typing import Dict , Set
98
1312class WorkflowRestartChecker :
1413 """Check if workflows have been restarted using ClickHouse."""
1514
16- def __init__ (self ):
15+ def __init__ (self , repo_owner : str = "pytorch" , repo_name : str = "pytorch" ):
1716 self ._cache : Dict [str , bool ] = {}
17+ self .repo_owner = repo_owner
18+ self .repo_name = repo_name
1819
1920 def has_restarted_workflow (self , workflow_name : str , commit_sha : str ) -> bool :
2021 """
@@ -139,9 +140,6 @@ def restart_workflow(self, workflow_name: str, commit_sha: str) -> bool:
139140 logging .error (f"Failed to get GitHub client: { e } " )
140141 return False
141142
142- repo_owner = os .getenv ("GITHUB_REPO_OWNER" , "pytorch" )
143- repo_name = os .getenv ("GITHUB_REPO_NAME" , "pytorch" )
144-
145143 try :
146144 # Use trunk/{sha} tag format
147145 tag_ref = f"trunk/{ commit_sha } "
@@ -150,15 +148,15 @@ def restart_workflow(self, workflow_name: str, commit_sha: str) -> bool:
150148 workflow_file_name = f"{ normalized_workflow_name } .yml"
151149
152150 # Get repo and workflow objects
153- repo = client .get_repo (f"{ repo_owner } /{ repo_name } " )
151+ repo = client .get_repo (f"{ self . repo_owner } /{ self . repo_name } " )
154152 workflow = repo .get_workflow (workflow_file_name )
155153
156154 # Dispatch the workflow
157155 workflow .create_dispatch (ref = tag_ref , inputs = {})
158156
159157 # Construct the workflow runs URL
160158 workflow_url = (
161- f"https://github.com/{ repo_owner } /{ repo_name } "
159+ f"https://github.com/{ self . repo_owner } /{ self . repo_name } "
162160 f"/actions/workflows/{ workflow_file_name } "
163161 f"?query=branch%3Atrunk%2F{ commit_sha } "
164162 )
0 commit comments