From c05c0130eb7aa9251069069442f26bb7884fe2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niko=20K=C3=B6ser?= Date: Mon, 25 May 2020 13:31:06 +0200 Subject: [PATCH] refactor: move setRepoSHA func to beginning of package --- pkg/proji/repo/github/github.go | 39 +++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/pkg/proji/repo/github/github.go b/pkg/proji/repo/github/github.go index 333e0314..2935f8b3 100644 --- a/pkg/proji/repo/github/github.go +++ b/pkg/proji/repo/github/github.go @@ -19,6 +19,26 @@ type github struct { repoSHA string } +// setRepoSHA sets the repoSHA attribute equal to the SHA-1 of the last commit in the current branch +func (g *github) setRepoSHA() error { + // Send request for SHA-1 of branch + shaReq := g.apiBaseURI + g.userName + "/" + g.repoName + "/branches/" + g.branchName + response, err := repo.GetRequest(shaReq) + if err != nil { + return err + } + + // Parse body and try to extract SHA + body, _ := ioutil.ReadAll(response.Body) + repoSHA := gjson.Get(string(body), "commit.sha") + defer response.Body.Close() + if !repoSHA.Exists() { + return fmt.Errorf("could not get commit sha-1 from body") + } + g.repoSHA = repoSHA.String() + return nil +} + // New creates a new github repo object func New(repoURLPath string) (repo.Importer, error) { // Parse URL @@ -58,25 +78,6 @@ func (g *github) GetRepoName() string { return g.repoName } // GetBranchName returns the branch name func (g *github) GetBranchName() string { return g.branchName } -// setRepoSHA sets the repoSHA attribute equal to the SHA-1 of the last commit in the current branch -func (g *github) setRepoSHA() error { - // Send request for SHA-1 of branch - shaReq := g.apiBaseURI + g.userName + "/" + g.repoName + "/branches/" + g.branchName - response, err := repo.GetRequest(shaReq) - if err != nil { - return err - } - - // Parse body and try to extract SHA - body, _ := ioutil.ReadAll(response.Body) - repoSHA := gjson.Get(string(body), "commit.sha") - defer response.Body.Close() - if !repoSHA.Exists() { - return fmt.Errorf("could not get commit sha-1 from body") - } - g.repoSHA = repoSHA.String() - return nil -} // GetTreePathsAndTypes gets the paths and types of the repo tree func (g *github) GetTreePathsAndTypes() ([]gjson.Result, []gjson.Result, error) {