-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathquerygen.go
42 lines (35 loc) · 842 Bytes
/
querygen.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
package main
import (
"fmt"
"strings"
)
func getQueryHashes(branches []Branch) []string {
results := []string{}
var hashes strings.Builder
for i, branch := range branches {
if branch.RemoteHeadOid == "" && len(branch.Commits) == 0 {
continue
}
separator := " "
if i == len(branches)-1 {
separator = ""
}
oid := ""
if branch.RemoteHeadOid == "" {
oid = branch.Commits[len(branch.Commits)-1]
} else {
oid = branch.RemoteHeadOid
}
hash := fmt.Sprintf("hash:%s%s", oid, separator)
// https://docs.github.com/en/rest/reference/search#limitations-on-query-length
if len(hashes.String())+len(hash) > 256 {
results = append(results, hashes.String())
hashes.Reset()
}
hashes.WriteString(hash)
}
if len(hashes.String()) > 0 {
results = append(results, hashes.String())
}
return results
}