@@ -2,7 +2,6 @@ package run
2
2
3
3
import (
4
4
"fmt"
5
- "net/url"
6
5
"strings"
7
6
"time"
8
7
@@ -17,8 +16,12 @@ type User struct {
17
16
}
18
17
19
18
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"`
22
25
}
23
26
24
27
type WorkflowRuns struct {
@@ -31,19 +34,24 @@ func findRun(client api.RESTClient, repository repository.Repository, reference
31
34
return nil , errors .Wrap (err , "Unable to get the current user." )
32
35
}
33
36
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
-
41
37
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 {
43
39
return nil , errors .Wrap (err , "Unable to get list of recent runs." )
44
40
}
45
41
46
42
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
+ }
47
55
return & run , nil
48
56
}
49
57
return nil , nil
0 commit comments