Some cleanups to the changeset code (#577)

This commit is contained in:
Victor Agababov 2019-08-15 11:22:08 -07:00 committed by Knative Prow Robot
parent 426561fd09
commit 7e6f1f48c9
1 changed files with 5 additions and 10 deletions

View File

@ -30,9 +30,7 @@ const (
koDataPathEnvName = "KO_DATA_PATH"
)
var (
commitIDRE = regexp.MustCompile(`^[a-f0-9]{40}$`)
)
var commitIDRE = regexp.MustCompile(`^[a-f0-9]{40}$`)
// Get tries to fetch the first 7 digitals of GitHub commit ID from HEAD file in
// KO_DATA_PATH. If it fails, it returns the error it gets.
@ -42,9 +40,8 @@ func Get() (string, error) {
return "", err
}
commitID := strings.TrimSpace(string(data))
if strings.HasPrefix(commitID, "ref: ") {
refName := commitID[len("ref: "):]
data, err := readFileFromKoData(refName)
if rID := strings.TrimPrefix(commitID, "ref: "); rID != commitID {
data, err := readFileFromKoData(rID)
if err != nil {
return "", err
}
@ -63,9 +60,7 @@ func Get() (string, error) {
func readFileFromKoData(filename string) ([]byte, error) {
koDataPath := os.Getenv(koDataPathEnvName)
if koDataPath == "" {
err := fmt.Errorf("%q does not exist or is empty", koDataPathEnvName)
return nil, err
return nil, fmt.Errorf("%q does not exist or is empty", koDataPathEnvName)
}
fullFilename := filepath.Join(koDataPath, filename)
return ioutil.ReadFile(fullFilename)
return ioutil.ReadFile(filepath.Join(koDataPath, filename))
}