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