@@ -120,52 +120,41 @@ func AutoMergePullRequestsLegacy(repoSlug string, verbose bool) error {
120120func WaitForWorkflowCompletion (repoSlug , runID string , timeoutMinutes int , verbose bool ) error {
121121 prAutomergeLog .Printf ("Waiting for workflow completion: repo=%s, runID=%s, timeout=%d minutes" , repoSlug , runID , timeoutMinutes )
122122
123- if verbose {
124- fmt .Fprintln (os .Stderr , console .FormatInfoMessage (fmt .Sprintf ("Waiting for workflow completion (timeout: %d minutes)" , timeoutMinutes )))
125- }
126-
127- // Use the repository slug directly
128- fullRepoName := repoSlug
129-
130123 timeout := time .Duration (timeoutMinutes ) * time .Minute
131- start := time .Now ()
132124
133- for {
134- // Check if timeout exceeded
135- if time .Since (start ) > timeout {
136- return fmt .Errorf ("workflow execution timed out after %d minutes" , timeoutMinutes )
137- }
138-
139- // Check workflow status
140- cmd := exec .Command ("gh" , "run" , "view" , runID , "--repo" , fullRepoName , "--json" , "status,conclusion" )
141- output , err := cmd .Output ()
125+ return PollWithSignalHandling (PollOptions {
126+ PollInterval : 10 * time .Second ,
127+ Timeout : timeout ,
128+ PollFunc : func () (PollResult , error ) {
129+ // Check workflow status
130+ cmd := exec .Command ("gh" , "run" , "view" , runID , "--repo" , repoSlug , "--json" , "status,conclusion" )
131+ output , err := cmd .Output ()
142132
143- if err != nil {
144- return fmt .Errorf ("failed to check workflow status: %w" , err )
145- }
146-
147- status := string (output )
133+ if err != nil {
134+ return PollFailure , fmt .Errorf ("failed to check workflow status: %w" , err )
135+ }
148136
149- // Check if completed
150- if strings .Contains (status , `"status":"completed"` ) {
151- if strings .Contains (status , `"conclusion":"success"` ) {
152- if verbose {
153- fmt .Fprintln (os .Stderr , console .FormatSuccessMessage ("Workflow completed successfully" ))
137+ status := string (output )
138+
139+ // Check if completed
140+ if strings .Contains (status , `"status":"completed"` ) {
141+ if strings .Contains (status , `"conclusion":"success"` ) {
142+ return PollSuccess , nil
143+ } else if strings .Contains (status , `"conclusion":"failure"` ) {
144+ return PollFailure , fmt .Errorf ("workflow failed" )
145+ } else if strings .Contains (status , `"conclusion":"cancelled"` ) {
146+ return PollFailure , fmt .Errorf ("workflow was cancelled" )
147+ } else {
148+ return PollFailure , fmt .Errorf ("workflow completed with unknown conclusion" )
154149 }
155- return nil
156- } else if strings .Contains (status , `"conclusion":"failure"` ) {
157- return fmt .Errorf ("workflow failed" )
158- } else if strings .Contains (status , `"conclusion":"cancelled"` ) {
159- return fmt .Errorf ("workflow was cancelled" )
160- } else {
161- return fmt .Errorf ("workflow completed with unknown conclusion" )
162150 }
163- }
164151
165- // Still running, wait before checking again
166- if verbose {
167- fmt .Fprintln (os .Stderr , console .FormatProgressMessage ("Workflow still running..." ))
168- }
169- time .Sleep (10 * time .Second )
170- }
152+ // Still running, continue polling
153+ return PollContinue , nil
154+ },
155+ StartMessage : fmt .Sprintf ("Waiting for workflow completion (timeout: %d minutes)" , timeoutMinutes ),
156+ ProgressMessage : "Workflow still running..." ,
157+ SuccessMessage : "Workflow completed successfully" ,
158+ Verbose : verbose ,
159+ })
171160}
0 commit comments