cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.3.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/discovery/files.go

57lines · modecode

1package discovery
2
3import "sort"
4
5func NewFileCommitsFromMap(m map[string][]string) FileCommits {
6 return FileCommits{pathCommits: m}
7}
8
9type FileCommits struct {
10 pathCommits map[string][]string
11}
12
13func (fc FileCommits) Results() (results []File) {
14 for path, commits := range fc.pathCommits {
15 results = append(results, File{Path: path, Commits: commits})
16 }
17 sort.Slice(results, func(i, j int) bool {
18 return results[i].Path < results[j].Path
19 })
20 return
21}
22
23func (fc FileCommits) Paths() (paths []string) {
24 for path := range fc.pathCommits {
25 paths = append(paths, path)
26 }
27
28 sort.Strings(paths)
29 return
30}
31
32func (fc FileCommits) Commits() (commits []string) {
33 cm := map[string]struct{}{}
34 for _, cs := range fc.pathCommits {
35 for _, c := range cs {
36 cm[c] = struct{}{}
37 }
38 }
39
40 for c := range cm {
41 commits = append(commits, c)
42 }
43
44 sort.Strings(commits)
45 return
46}
47
48func (fc FileCommits) HasCommit(commit string) bool {
49 for _, commits := range fc.pathCommits {
50 for _, c := range commits {
51 if c == commit {
52 return true
53 }
54 }
55 }
56 return false
57}
58