-
Notifications
You must be signed in to change notification settings - Fork 3
/
workflows.go
57 lines (51 loc) · 1.56 KB
/
workflows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"context"
"fmt"
"log/slog"
"strings"
github "github.com/google/go-github/v58/github"
"github.com/spf13/viper"
)
func GetWorkflowsForRepo(client *github.Client, repo *github.Repository) ([]*github.Workflow, error) {
opt := &github.ListOptions{PerPage: 50}
ctx := context.Background()
includeInactive := viper.GetBool("inactive")
var allWorkflows []*github.Workflow
for {
workflows, resp, err := client.Actions.ListWorkflows(ctx, *repo.Owner.Login, *repo.Name, opt)
if err != nil {
return nil, err
}
for _, workflow := range workflows.Workflows {
if !includeInactive && *workflow.State != "active" {
continue
}
if len(IncludeSet) > 0 {
_, ok := IncludeSet[strings.ToLower(*workflow.Name)]
if !ok {
continue
}
} else if len(ExcludeSet) > 0 {
_, ok := ExcludeSet[strings.ToLower(*workflow.Name)]
if ok {
continue
}
}
if !strings.Contains(*workflow.BadgeURL, "/actions/workflow") {
var parts = strings.Split(*workflow.Path, "/")
var yaml = parts[len(parts)-1]
var newBadgeUrl = fmt.Sprintf("https://github.com/%s/actions/workflows/%s/badge.svg", *repo.FullName, yaml)
slog.Debug("Hack to fix busted Github API result", "repo", *repo.FullName, "badbadge", *workflow.BadgeURL, "goodbadge", newBadgeUrl)
*workflow.BadgeURL = newBadgeUrl
}
allWorkflows = append(allWorkflows, workflow)
}
if resp.NextPage == 0 {
break
}
slog.Debug("paging for workflows", "repo", *repo.FullName, "page", resp.NextPage)
opt.Page = resp.NextPage
}
return allWorkflows, nil
}