Skip to content

Commit 6968a36

Browse files
committed
Filter actions by name if desired
Signed-off-by: Martin Wohlfart <github@wohlf.art>
1 parent d8b1fe2 commit 6968a36

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

main.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"text/tabwriter"
1313
"time"
1414

15-
units "github.com/docker/go-units"
15+
"github.com/docker/go-units"
1616

1717
"github.com/google/go-github/v50/github"
1818
"golang.org/x/oauth2"
@@ -28,9 +28,9 @@ type RepoSummary struct {
2828

2929
func main() {
3030
var (
31-
orgName, userName, token, tokenFile, repoList, reposFile, apiUrl string
32-
days int
33-
punchCard, byRepo bool
31+
orgName, userName, token, tokenFile, repoList, reposFile, actionList, apiUrl string
32+
days int
33+
punchCard, byRepo bool
3434
)
3535

3636
flag.StringVar(&orgName, "org", "", "Organization name")
@@ -40,6 +40,7 @@ func main() {
4040
flag.StringVar(&tokenFile, "token-file", "", "Path to the file containing the GitHub token")
4141
flag.StringVar(&repoList, "include", "", "List of repos you want stats for eg. 'org/repo1,org/repo2'")
4242
flag.StringVar(&reposFile, "include-file", "", "Path to file containing the Github repos list or '-' for stdin")
43+
flag.StringVar(&actionList, "include-actions", "", "List of actions you want stats for eg. 'Build")
4344

4445
flag.BoolVar(&byRepo, "by-repo", false, "Show breakdown by repository")
4546

@@ -213,6 +214,7 @@ func main() {
213214
page = res.NextPage
214215
}
215216

217+
workflowRuns = actionNameFilter(actionList, workflowRuns)
216218
totalRuns += len(workflowRuns)
217219

218220
var owner string
@@ -516,3 +518,24 @@ func filterRepositories(repos []*github.Repository, repoList, reposFile string)
516518

517519
return repos, nil
518520
}
521+
522+
func actionNameFilter(actionList string, runs []*github.WorkflowRun) []*github.WorkflowRun {
523+
if len(actionList) == 0 {
524+
return runs
525+
}
526+
527+
actionsFromList := parseInclude(actionList)
528+
byName := make(map[string]bool, len(actionsFromList))
529+
for _, name := range actionsFromList {
530+
byName[name] = true
531+
}
532+
533+
var filtered []*github.WorkflowRun
534+
for _, run := range runs {
535+
if run.Name != nil && byName[*run.Name] {
536+
filtered = append(filtered, run)
537+
}
538+
}
539+
540+
return filtered
541+
}

0 commit comments

Comments
 (0)