-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
util.go
80 lines (72 loc) · 2.09 KB
/
util.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package yolosvc
import (
"archive/zip"
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"path/filepath"
"regexp"
"berty.tech/yolo/v2/go/pkg/yolopb"
)
var githubMasterMerge = regexp.MustCompile(`Merge pull request #([0-9]+) from (.*)`)
func artifactKindByPath(path string) yolopb.Artifact_Kind {
switch filepath.Ext(path) {
case ".ipa", ".unsigned-ipa", ".dummy-signed-ipa":
return yolopb.Artifact_IPA
case ".dmg", ".unsigned-dmg", ".dummy-signed-dmg":
return yolopb.Artifact_DMG
case ".apk":
return yolopb.Artifact_APK
}
return yolopb.Artifact_UnknownKind
}
func mimetypeByPath(path string) string {
switch filepath.Ext(path) {
case ".ipa", ".unsigned-ipa", ".dummy-signed-ipa":
return "application/octet-stream"
case ".apk":
return "application/vnd.android.package-archive"
case ".dmg", ".unsigned-dmg", ".dummy-signed-dmg":
return "application/x-apple-diskimage"
case ".jar":
return "application/java-archive"
case ".txt":
return "text/plain"
case ".json":
return "application/json"
case ".zip":
return "application/zip"
case ".plist":
return "application/x-plist"
}
return "application/octet-stream"
}
func md5Sum(input []byte) string {
hasher := md5.New()
_, _ = hasher.Write(input)
return hex.EncodeToString(hasher.Sum(nil))
}
func guessMissingBuildInfo(build *yolopb.Build) {
// try to guess the PR for GitHub builds based on commit message
if build.HasMergerequestID == "" && build.Branch == "master" && build.HasProjectID != "" {
// FIXME: check if the build.project.driver is GitHub
matches := githubMasterMerge.FindAllStringSubmatch(build.Message, -1)
if len(matches) == 1 && len(matches[0]) == 3 {
pr := matches[0][1]
build.HasMergerequestID = fmt.Sprintf("%s/pull/%s", build.HasProjectID, pr)
}
}
if build.VCSTagURL == "" && build.VCSTag != "" && build.HasProjectID != "" {
// FIXME: check if the build.project.driver is GitHub
build.VCSTagURL = fmt.Sprintf("%s/tree/%s", build.HasProjectID, build.VCSTag)
}
}
func readZipFile(zf *zip.File) ([]byte, error) {
f, err := zf.Open()
if err != nil {
return nil, err
}
defer f.Close()
return io.ReadAll(f)
}