|
|
@@ -7,6 +7,7 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/bradleyfalzon/ghinstallation/v2"
|
|
|
"github.com/google/go-github/v41/github"
|
|
|
@@ -191,23 +192,30 @@ func (c *GithubIncomingWebhookHandler) processPullRequestEvent(event *github.Pul
|
|
|
statuses := []string{"in_progress", "queued", "requested", "waiting"}
|
|
|
errChan := make(chan error)
|
|
|
|
|
|
- wg.Add(len(statuses))
|
|
|
-
|
|
|
for _, status := range statuses {
|
|
|
+ wg.Add(1)
|
|
|
+
|
|
|
go func(status string) {
|
|
|
- defer wg.Done()
|
|
|
+ reqCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
+ defer cancel()
|
|
|
+
|
|
|
+ fmt.Printf("fetching workflow runs for status - %s\n", status)
|
|
|
|
|
|
runs, _, err := client.Actions.ListWorkflowRunsByFileName(
|
|
|
- context.Background(), owner, repo, fmt.Sprintf("porter_%s_env.yml", env.Name),
|
|
|
+ reqCtx, owner, repo, fmt.Sprintf("porter_%s_env.yml", env.Name),
|
|
|
&github.ListWorkflowRunsOptions{
|
|
|
Branch: event.GetPullRequest().GetHead().GetRef(),
|
|
|
Status: status,
|
|
|
},
|
|
|
)
|
|
|
|
|
|
+ fmt.Printf("workflow runs for status - %s, err - %s\n", status, err.Error())
|
|
|
+
|
|
|
if err == nil {
|
|
|
+ fmt.Printf("workflow runs for status - %s, count - %d\n", status, runs.GetTotalCount())
|
|
|
+
|
|
|
for _, run := range runs.WorkflowRuns {
|
|
|
- _, err := client.Actions.CancelWorkflowRunByID(context.Background(), owner, repo, run.GetID())
|
|
|
+ _, err := client.Actions.CancelWorkflowRunByID(reqCtx, owner, repo, run.GetID())
|
|
|
|
|
|
if err != nil {
|
|
|
errChan <- fmt.Errorf("error cancelling %s: %w", run.GetHTMLURL(), err)
|
|
|
@@ -216,6 +224,10 @@ func (c *GithubIncomingWebhookHandler) processPullRequestEvent(event *github.Pul
|
|
|
} else {
|
|
|
errChan <- fmt.Errorf("error listing workflows for status %s: %w", status, err)
|
|
|
}
|
|
|
+
|
|
|
+ fmt.Printf("workflow runs for status - %s, DONE\n", status)
|
|
|
+
|
|
|
+ wg.Done()
|
|
|
}(status)
|
|
|
}
|
|
|
|