diff --git a/CHANGELOG.md b/CHANGELOG.md index b22ae47..d50e19c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +### Added +- [#89](https://github.com/meltwater/drone-convert-pathschanged/issues/89) add environment variable to allow stash users to specify page size of git compare changes + ## 1.0.0 ### Breaking changes diff --git a/README.md b/README.md index eaaaaa0..a6e1644 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,10 @@ $ docker run -d \ --restart=always \ --name=converter meltwater/drone-convert-pathschanged ``` +Stash APIs are paginated and by default will only return 25 changes when computing the changeset. Set environment variable STASH_PAGE_SIZE to a higher number on the plugin to avoid partial change set detection. +```console +--env=STASH_PAGE_SIZE=1000 +``` 4. Update your Drone server configuration to include the plugin address and the shared secret. diff --git a/main.go b/main.go index 1ee6891..31a1f33 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ type ( BitBucketPassword string `envconfig:"BITBUCKET_PASSWORD"` GithubServer string `envconfig:"GITHUB_SERVER"` StashServer string `envconfig:"STASH_SERVER"` + StashPageSize int `envconfig:"STASH_PAGE_SIZE"` //bumps the rest api page size for changeset detection. Picks only 25 changes if unspecified } ) @@ -120,6 +121,7 @@ func main() { GithubServer: spec.GithubServer, Token: spec.Token, StashServer: spec.StashServer, + StashPageSize: spec.StashPageSize, } handler := converter.Handler( diff --git a/plugin/plugin.go b/plugin/plugin.go index ce4f86d..f963089 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -27,6 +27,7 @@ type ( GithubServer string StashServer string Token string + StashPageSize int } plugin struct { @@ -166,7 +167,11 @@ func (p *plugin) Convert(ctx context.Context, req *converter.Request) (*drone.Co return nil, err } case "stash": - changedFiles, err = providers.GetStashFilesChanged(req.Repo, req.Build, p.params.StashServer, p.params.Token, scm.ListOptions{}) + listOptions := scm.ListOptions{} + if p.params.StashPageSize > 0 { + listOptions.Size = p.params.StashPageSize + } + changedFiles, err = providers.GetStashFilesChanged(req.Repo, req.Build, p.params.StashServer, p.params.Token, listOptions) if err != nil { return nil, err } diff --git a/plugin/plugin_test.go b/plugin/plugin_test.go index ba5c18a..5cd5e79 100644 --- a/plugin/plugin_test.go +++ b/plugin/plugin_test.go @@ -605,3 +605,64 @@ name: default t.Log(diff) } } + +func TestStashPageSizeSetWhenConfigured(t *testing.T) { + gock.New("http://example.com:7990"). + Get("/rest/api/1.0/projects/PRJ/repos/my-repo/compare/changes"). + MatchParam("from", "4f4b0ef1714a5b6cafdaf2f53c7f5f5b38fb9348"). + MatchParam("to", "131cb13f4aed12e725177bc4b7c28db67839bf9f"). + MatchParam("limit", "40"). //this will resolve only if the configured page size was honoured + Reply(200). + Type("application/json"). + File("../providers/testdata/stash/compare.json") + + before := ` +kind: pipeline +type: docker +name: default + +steps: +- name: message + image: busybox + commands: + - echo "This step will be excluded when .drone.yml is changed" + when: + paths: + exclude: + - .drone.yml +` + params := &Params{ + StashServer: "http://example.com:7990", + Token: "invalidtoken", + StashPageSize: 40, + } + + req := &converter.Request{ + Build: drone.Build{ + Before: "4f4b0ef1714a5b6cafdaf2f53c7f5f5b38fb9348", + After: "131cb13f4aed12e725177bc4b7c28db67839bf9f", + }, + Config: drone.Config{ + Data: before, + }, + Repo: drone.Repo{ + Namespace: "repos", + Name: "my-repo", + Slug: "PRJ/my-repo", + Config: ".drone.yml", + }, + } + + plugin := New("stash", params) + + config, err := plugin.Convert(noContext, req) + if err != nil { + t.Error(err) + return + } + + if config == nil { //we are not interested in transformation, only validating limit was set on the request to stash and resolved to gock + t.Errorf("Unexpected Results") + } + +}