Skip to content

Commit c614b4f

Browse files
authored
Merge pull request #31 from chrisgavin/dont-search-workflows
Filter workflow runs locally rather than searching.
2 parents ca65e7d + 0f7375c commit c614b4f

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

internal/run/run.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package run
22

33
import (
44
"fmt"
5-
"net/url"
65
"strings"
76
"time"
87

@@ -17,8 +16,12 @@ type User struct {
1716
}
1817

1918
type WorkflowRun struct {
20-
ID int64 `json:"id"`
21-
Conclusion string `json:"conclusion"`
19+
ID int64 `json:"id"`
20+
Conclusion string `json:"conclusion"`
21+
Actor User `json:"actor"`
22+
Branch string `json:"head_branch"`
23+
Event string `json:"event"`
24+
CreatedAt time.Time `json:"created_at"`
2225
}
2326

2427
type WorkflowRuns struct {
@@ -31,19 +34,24 @@ func findRun(client api.RESTClient, repository repository.Repository, reference
3134
return nil, errors.Wrap(err, "Unable to get the current user.")
3235
}
3336

34-
urlParameters := url.Values{}
35-
urlParameters.Add("actor", user.Login)
36-
urlParameters.Add("branch", strings.TrimPrefix(reference, "refs/heads/"))
37-
urlParameters.Add("event", "workflow_dispatch")
38-
createdRange := fmt.Sprintf("%s..%s", after.Format(time.RFC3339), before.Format(time.RFC3339))
39-
urlParameters.Add("created", createdRange)
40-
4137
workflowRuns := WorkflowRuns{}
42-
if err := client.Get(fmt.Sprintf("repos/%s/%s/actions/runs?%s", repository.Owner(), repository.Name(), urlParameters.Encode()), &workflowRuns); err != nil {
38+
if err := client.Get(fmt.Sprintf("repos/%s/%s/actions/runs", repository.Owner(), repository.Name()), &workflowRuns); err != nil {
4339
return nil, errors.Wrap(err, "Unable to get list of recent runs.")
4440
}
4541

4642
for _, run := range workflowRuns.WorkflowRuns {
43+
if !strings.EqualFold(run.Actor.Login, user.Login) {
44+
continue
45+
}
46+
if run.Branch != strings.TrimPrefix(reference, "refs/heads/") {
47+
continue
48+
}
49+
if run.Event != "workflow_dispatch" {
50+
continue
51+
}
52+
if run.CreatedAt.Before(after) || run.CreatedAt.After(before) {
53+
continue
54+
}
4755
return &run, nil
4856
}
4957
return nil, nil

0 commit comments

Comments
 (0)