-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzer.go
54 lines (50 loc) · 1.17 KB
/
analyzer.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
package analyzer
import (
"fmt"
"github.com/elgohr/github-action-analyzer/downloader"
"gopkg.in/yaml.v2"
"strings"
)
func GetSummary(actionName string, configs <-chan downloader.ActionConfiguration) *Summary {
summary := Summary{
TotalRepositories: 0,
TotalSteps: 0,
With: map[string]int{},
}
for config := range configs {
fmt.Println(fmt.Sprintf("analyzing usage in %s", config.Name))
summary.TotalRepositories += 1
var parsedConfig Configuration
if err := yaml.Unmarshal(config.Configuration, &parsedConfig); err != nil {
fmt.Println(err)
}
for _, build := range parsedConfig.Jobs {
for _, step := range build.Steps {
if strings.HasPrefix(step.Uses, actionName) {
summary.TotalSteps += 1
for key := range step.With {
if count, exists := summary.With[key]; exists {
summary.With[key] = count + 1
} else {
summary.With[key] = 1
}
}
}
}
}
}
return &summary
}
type Summary struct {
TotalRepositories int
TotalSteps int
With map[string]int
}
type Configuration struct {
Jobs map[string]struct {
Steps []struct {
Uses string
With map[string]string
}
}
}