Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[resolves #89] Add a configuration to set stash page size when comparing changes for change set #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)

Expand Down Expand Up @@ -120,6 +121,7 @@ func main() {
GithubServer: spec.GithubServer,
Token: spec.Token,
StashServer: spec.StashServer,
StashPageSize: spec.StashPageSize,
}

handler := converter.Handler(
Expand Down
7 changes: 6 additions & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type (
GithubServer string
StashServer string
Token string
StashPageSize int
}

plugin struct {
Expand Down Expand Up @@ -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
}
Expand Down
61 changes: 61 additions & 0 deletions plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

}