-
Notifications
You must be signed in to change notification settings - Fork 6
/
sig.go
45 lines (34 loc) · 838 Bytes
/
sig.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
package main
import (
"encoding/base64"
"sigs.k8s.io/yaml"
"github.com/opensourceways/robot-gitee-openeuler-welcome/community"
)
func (bot *robot) getSigOfRepo(repo string, cfg *botConfig) (string, error) {
c, err := bot.loadFile(cfg.sigFile)
if err != nil {
return "", err
}
s := new(community.Sigs)
if err := decodeYamlFile(c, s); err != nil {
return "", err
}
if err := s.Validate(); err != nil {
return "", err
}
return s.GetSig(repo), nil
}
func (bot *robot) loadFile(f fileOfRepo) (string, error) {
c, err := bot.cli.GetPathContent(f.org, f.repo, f.path, f.branch)
if err != nil {
return "", err
}
return c.Content, nil
}
func decodeYamlFile(content string, v interface{}) error {
c, err := base64.StdEncoding.DecodeString(content)
if err != nil {
return err
}
return yaml.Unmarshal(c, v)
}