Skip to content

Commit

Permalink
Merge branch 'master' into feat/add-approved-review-count-to-the-version
Browse files Browse the repository at this point in the history
  • Loading branch information
rickardl authored Oct 19, 2020
2 parents b083b8c + 43c9bd9 commit c4b5c6d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ generate notifications over the webhook. So if you have a repository with little
| `git_depth` | No | `1` | Shallow clone the repository using the `--depth` Git option |
| `submodules` | No | `true` | Recursively clone git submodules. Defaults to false. |
| `list_changed_files` | No | `true` | Generate a list of changed files and save alongside metadata |
| `fetch_tags` | No | `true` | Fetch tags from remote repository |

Clones the base (e.g. `master` branch) at the latest commit, and merges the pull request at the specified commit
into master. This ensures that we are both testing and setting status on the exact commit that was requested in
Expand Down
18 changes: 10 additions & 8 deletions fakes/fake_git.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -o fakes/fake_git.go . Git
type Git interface {
Init(string) error
Pull(string, string, int, bool) error
Pull(string, string, int, bool, bool) error
RevParse(string) (string, error)
Fetch(string, int, int, bool) error
Checkout(string, string, bool) error
Expand Down Expand Up @@ -81,7 +81,7 @@ func (g *GitClient) Init(branch string) error {
}

// Pull ...
func (g *GitClient) Pull(uri, branch string, depth int, submodules bool) error {
func (g *GitClient) Pull(uri, branch string, depth int, submodules bool, fetchTags bool) error {
endpoint, err := g.Endpoint(uri)
if err != nil {
return err
Expand All @@ -91,6 +91,9 @@ func (g *GitClient) Pull(uri, branch string, depth int, submodules bool) error {
if depth > 0 {
args = append(args, "--depth", strconv.Itoa(depth))
}
if fetchTags {
args = append(args, "--tags")
}
if submodules {
args = append(args, "--recurse-submodules")
}
Expand Down
48 changes: 24 additions & 24 deletions in.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp
if err := git.Init(pull.BaseRefName); err != nil {
return nil, err
}
if err := git.Pull(pull.Repository.URL, pull.BaseRefName, request.Params.GitDepth, request.Params.Submodules); err != nil {
if err := git.Pull(pull.Repository.URL, pull.BaseRefName, request.Params.GitDepth, request.Params.Submodules, request.Params.FetchTags); err != nil {
return nil, err
}

Expand All @@ -39,29 +39,6 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp
return nil, err
}

switch tool := request.Params.IntegrationTool; tool {
case "rebase":
if err := git.Rebase(pull.BaseRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "merge", "":
if err := git.Merge(pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "checkout":
if err := git.Checkout(pull.HeadRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("invalid integration tool specified: %s", tool)
}

if request.Source.GitCryptKey != "" {
if err := git.GitCryptUnlock(request.Source.GitCryptKey); err != nil {
return nil, err
}
}

// Create the metadata
var metadata Metadata
metadata.Add("pr", strconv.Itoa(pull.Number))
Expand Down Expand Up @@ -101,7 +78,29 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp
if err := ioutil.WriteFile(filepath.Join(path, filename), content, 0644); err != nil {
return nil, fmt.Errorf("failed to write metadata file %s: %s", filename, err)
}
}

switch tool := request.Params.IntegrationTool; tool {
case "rebase":
if err := git.Rebase(pull.BaseRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "merge", "":
if err := git.Merge(pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
case "checkout":
if err := git.Checkout(pull.HeadRefName, pull.Tip.OID, request.Params.Submodules); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("invalid integration tool specified: %s", tool)
}

if request.Source.GitCryptKey != "" {
if err := git.GitCryptUnlock(request.Source.GitCryptKey); err != nil {
return nil, err
}
}

if request.Params.ListChangedFiles {
Expand Down Expand Up @@ -135,6 +134,7 @@ type GetParameters struct {
GitDepth int `json:"git_depth"`
Submodules bool `json:"submodules"`
ListChangedFiles bool `json:"list_changed_files"`
FetchTags bool `json:"fetch_tags"`
}

// GetRequest ...
Expand Down
3 changes: 2 additions & 1 deletion in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,12 @@ func TestGet(t *testing.T) {
}

if assert.Equal(t, 1, git.PullCallCount()) {
url, base, depth, submodules := git.PullArgsForCall(0)
url, base, depth, submodules, fetchTags := git.PullArgsForCall(0)
assert.Equal(t, tc.pullRequest.Repository.URL, url)
assert.Equal(t, tc.pullRequest.BaseRefName, base)
assert.Equal(t, tc.parameters.GitDepth, depth)
assert.Equal(t, tc.parameters.Submodules, submodules)
assert.Equal(t, tc.parameters.FetchTags, fetchTags)
}

if assert.Equal(t, 1, git.RevParseCallCount()) {
Expand Down

0 comments on commit c4b5c6d

Please sign in to comment.