diff --git a/cmd/telefonistka/bump-version-overwrite.go b/cmd/telefonistka/bump-version-overwrite.go index fa6b4f59..e2df86df 100644 --- a/cmd/telefonistka/bump-version-overwrite.go +++ b/cmd/telefonistka/bump-version-overwrite.go @@ -73,7 +73,7 @@ func bumpVersionOverwrite(targetRepo string, targetFile string, file string, git ghPrClientDetails.PrLogger = log.WithFields(log.Fields{}) // TODO what fields should be here? defaultBranch, _ := ghPrClientDetails.GetDefaultBranch() - initialFileContent, err, statusCode := githubapi.GetFileContent(ghPrClientDetails, defaultBranch, targetFile) + initialFileContent, statusCode, err := githubapi.GetFileContent(ghPrClientDetails, defaultBranch, targetFile) if statusCode == 404 { ghPrClientDetails.PrLogger.Infof("File %s was not found\n", targetFile) } else if err != nil { diff --git a/cmd/telefonistka/bump-version-regex.go b/cmd/telefonistka/bump-version-regex.go index 0e9fa25e..fc3d50f1 100644 --- a/cmd/telefonistka/bump-version-regex.go +++ b/cmd/telefonistka/bump-version-regex.go @@ -71,7 +71,7 @@ func bumpVersionRegex(targetRepo string, targetFile string, regex string, replac r := regexp.MustCompile(regex) defaultBranch, _ := ghPrClientDetails.GetDefaultBranch() - initialFileContent, err, _ := githubapi.GetFileContent(ghPrClientDetails, defaultBranch, targetFile) + initialFileContent, _, err := githubapi.GetFileContent(ghPrClientDetails, defaultBranch, targetFile) if err != nil { ghPrClientDetails.PrLogger.Errorf("Fail to fetch file content:%s\n", err) os.Exit(1) diff --git a/cmd/telefonistka/bump-version-yaml.go b/cmd/telefonistka/bump-version-yaml.go index 7642662c..c130b775 100644 --- a/cmd/telefonistka/bump-version-yaml.go +++ b/cmd/telefonistka/bump-version-yaml.go @@ -74,7 +74,7 @@ func bumpVersionYaml(targetRepo string, targetFile string, address string, value defaultBranch, _ := ghPrClientDetails.GetDefaultBranch() - initialFileContent, err, _ := githubapi.GetFileContent(ghPrClientDetails, defaultBranch, targetFile) + initialFileContent, _, err := githubapi.GetFileContent(ghPrClientDetails, defaultBranch, targetFile) if err != nil { ghPrClientDetails.PrLogger.Errorf("Fail to fetch file content:%s\n", err) os.Exit(1) diff --git a/internal/pkg/githubapi/github.go b/internal/pkg/githubapi/github.go index 4a0929bc..bf75c41c 100644 --- a/internal/pkg/githubapi/github.go +++ b/internal/pkg/githubapi/github.go @@ -1008,7 +1008,7 @@ func ApprovePr(approverClient *github.Client, ghPrClientDetails GhPrClientDetail } func GetInRepoConfig(ghPrClientDetails GhPrClientDetails, defaultBranch string) (*cfg.Config, error) { - inRepoConfigFileContentString, err, _ := GetFileContent(ghPrClientDetails, defaultBranch, "telefonistka.yaml") + inRepoConfigFileContentString, _, err := GetFileContent(ghPrClientDetails, defaultBranch, "telefonistka.yaml") if err != nil { ghPrClientDetails.PrLogger.Errorf("Could not get in-repo configuration: err=%s\n", err) return nil, err @@ -1020,18 +1020,23 @@ func GetInRepoConfig(ghPrClientDetails GhPrClientDetails, defaultBranch string) return c, err } -func GetFileContent(ghPrClientDetails GhPrClientDetails, branch string, filePath string) (string, error, int) { +func GetFileContent(ghPrClientDetails GhPrClientDetails, branch string, filePath string) (string, int, error) { rGetContentOps := github.RepositoryContentGetOptions{Ref: branch} fileContent, _, resp, err := ghPrClientDetails.GhClientPair.v3Client.Repositories.GetContents(ghPrClientDetails.Ctx, ghPrClientDetails.Owner, ghPrClientDetails.Repo, filePath, &rGetContentOps) - prom.InstrumentGhCall(resp) if err != nil { ghPrClientDetails.PrLogger.Errorf("Fail to get file:%s\n%v\n", err, resp) - return "", err, resp.StatusCode + if resp == nil { + return "", 0, err + } + prom.InstrumentGhCall(resp) + return "", resp.StatusCode, err + } else { + prom.InstrumentGhCall(resp) } fileContentString, err := fileContent.GetContent() if err != nil { ghPrClientDetails.PrLogger.Errorf("Fail to serlize file:%s\n", err) - return "", err, resp.StatusCode + return "", resp.StatusCode, err } - return fileContentString, nil, resp.StatusCode + return fileContentString, resp.StatusCode, nil }