Skip to content

Commit

Permalink
Add test. Update docs
Browse files Browse the repository at this point in the history
Signed-off-by: Brett C. Dudo <brett@dudo.io>
  • Loading branch information
dudo committed Jan 18, 2025
1 parent a018717 commit 68116eb
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
44 changes: 43 additions & 1 deletion applicationset/generators/pull_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
ctx := context.Background()
cases := []struct {
selectFunc func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error)
values map[string]string
expected []map[string]interface{}
expectedErr error
applicationSet argoprojiov1alpha1.ApplicationSet
Expand Down Expand Up @@ -120,6 +121,45 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
},
expectedErr: nil,
},
{
selectFunc: func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) {
return pullrequest.NewFakeService(
ctx,
[]*pullrequest.PullRequest{
{
Number: 1,
Title: "title1",
Branch: "my_branch",
TargetBranch: "master",
HeadSHA: "abcd",
Author: "testName",
},
},
nil,
)
},
values: map[string]string{
"foo": "bar",
"pr_branch": "{{ branch }}",
},
expected: []map[string]interface{}{
{
"number": "1",
"title": "title1",
"branch": "my_branch",
"branch_slug": "my-branch",
"target_branch": "master",
"target_branch_slug": "master",
"head_sha": "abcd",
"head_short_sha": "abcd",
"head_short_sha_7": "abcd",
"author": "testName",
"values.foo": "bar",
"values.pr_branch": "my_branch",
},
},
expectedErr: nil,
},
{
selectFunc: func(context.Context, *argoprojiov1alpha1.PullRequestGenerator, *argoprojiov1alpha1.ApplicationSet) (pullrequest.PullRequestService, error) {
return pullrequest.NewFakeService(
Expand Down Expand Up @@ -219,7 +259,9 @@ func TestPullRequestGithubGenerateParams(t *testing.T) {
selectServiceProviderFunc: c.selectFunc,
}
generatorConfig := argoprojiov1alpha1.ApplicationSetGenerator{
PullRequest: &argoprojiov1alpha1.PullRequestGenerator{},
PullRequest: &argoprojiov1alpha1.PullRequestGenerator{
Values: c.values,
},
}

got, gotErr := gen.GenerateParams(&generatorConfig, &c.applicationSet, nil)
Expand Down
38 changes: 38 additions & 0 deletions docs/operator-manual/applicationset/Generators-Pull-Request.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ spec:
* `labels`: Filter the PRs to those containing **all** of the labels listed. (Optional)
* `appSecretName`: A `Secret` name containing a GitHub App secret in [repo-creds format][repo-creds].


[repo-creds]: ../declarative-setup.md#repository-credentials

## GitLab
Expand Down Expand Up @@ -480,3 +481,40 @@ For more information about each event, please refer to the [official documentati
## Lifecycle

An Application will be generated when a Pull Request is discovered when the configured criteria is met - i.e. for GitHub when a Pull Request matches the specified `labels` and/or `pullRequestState`. Application will be removed when a Pull Request no longer meets the specified criteria.

## Pass additional key-value pairs via `values` field

You may pass additional, arbitrary string key-value pairs via the `values` field of any Pull Request generator. Values added via the `values` field are added as `values.(field)`.

```yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: myapps
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- pullRequest:
# ...
values:
pr_branch: '{{ .branch }}'
template:
metadata:
name: '{{ .values.name }}'
spec:
source:
repoURL: '{{ .url }}'
targetRevision: '{{ .branch }}'
path: kubernetes/
project: default
destination:
server: https://kubernetes.default.svc
namespace: default
```

!!! note
The `values.` prefix is always prepended to values provided via `generators.pullRequest.values` field. Ensure you include this prefix in the parameter name within the `template` when using it.

In `values` we can also interpolate all fields set by the Pull Request generator as mentioned above.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ spec:
generators:
- scmProvider:
bitbucket:
# The workspace id (slug).
# The workspace id (slug).
owner: "example-owner"
# The user to use for basic authentication with an app password.
user: "example-user"
Expand Down

0 comments on commit 68116eb

Please sign in to comment.