Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
28 changes: 19 additions & 9 deletions applicationset/services/pull_request/bitbucket_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ type BitbucketCloudService struct {
}

type BitbucketCloudPullRequest struct {
ID int `json:"id"`
Title string `json:"title"`
Source BitbucketCloudPullRequestSource `json:"source"`
Author BitbucketCloudPullRequestAuthor `json:"author"`
ID int `json:"id"`
Title string `json:"title"`
Source BitbucketCloudPullRequestSource `json:"source"`
Author BitbucketCloudPullRequestAuthor `json:"author"`
Destination BitbucketCloudPullRequestDestination `json:"destination"`
}

type BitbucketCloudPullRequestDestination struct {
Branch BitbucketCloudPullRequestDestinationBranch `json:"branch"`
}

type BitbucketCloudPullRequestDestinationBranch struct {
Name string `json:"name"`
}

type BitbucketCloudPullRequestSource struct {
Expand Down Expand Up @@ -136,11 +145,12 @@ func (b *BitbucketCloudService) List(_ context.Context) ([]*PullRequest, error)
pullRequests := []*PullRequest{}
for _, pull := range pulls {
pullRequests = append(pullRequests, &PullRequest{
Number: pull.ID,
Title: pull.Title,
Branch: pull.Source.Branch.Name,
HeadSHA: pull.Source.Commit.Hash,
Author: pull.Author.Nickname,
Number: pull.ID,
Title: pull.Title,
Branch: pull.Source.Branch.Name,
TargetBranch: pull.Destination.Branch.Name,
HeadSHA: pull.Source.Commit.Hash,
Author: pull.Author.Nickname,
})
}

Expand Down
67 changes: 52 additions & 15 deletions applicationset/services/pull_request/bitbucket_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
},
"author": {
"nickname": "testName"
},
"destination": {
"branch": {
"name": "master"
}
}
},
{
Expand All @@ -365,6 +370,11 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
},
"author": {
"nickname": "testName"
},
"destination": {
"branch": {
"name": "branch-200"
}
}
}
]
Expand All @@ -390,6 +400,11 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
},
"author": {
"nickname": "testName"
},
"destination": {
"branch": {
"name": "master"
}
}
}
]
Expand All @@ -413,18 +428,20 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
require.NoError(t, err)
assert.Len(t, pullRequests, 2)
assert.Equal(t, PullRequest{
Number: 101,
Title: "feat(101)",
Branch: "feature-101",
HeadSHA: "1a8dd249c04a",
Author: "testName",
Number: 101,
Title: "feat(101)",
Branch: "feature-101",
HeadSHA: "1a8dd249c04a",
Author: "testName",
TargetBranch: "master",
}, *pullRequests[0])
assert.Equal(t, PullRequest{
Number: 102,
Title: "feat(102)",
Branch: "feature-102",
HeadSHA: "6344d9623e3b",
Author: "testName",
Number: 102,
Title: "feat(102)",
Branch: "feature-102",
HeadSHA: "6344d9623e3b",
Author: "testName",
TargetBranch: "master",
}, *pullRequests[1])

regexp = `.*2$`
Expand All @@ -438,11 +455,12 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
require.NoError(t, err)
assert.Len(t, pullRequests, 1)
assert.Equal(t, PullRequest{
Number: 102,
Title: "feat(102)",
Branch: "feature-102",
HeadSHA: "6344d9623e3b",
Author: "testName",
Number: 102,
Title: "feat(102)",
Branch: "feature-102",
HeadSHA: "6344d9623e3b",
Author: "testName",
TargetBranch: "master",
}, *pullRequests[0])

regexp = `[\d{2}`
Expand All @@ -454,4 +472,23 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) {
},
})
require.Error(t, err)

regexp = `feature-2[\d]{2}`
targetRegexp := `branch.*`
pullRequests, err = ListPullRequests(t.Context(), svc, []v1alpha1.PullRequestGeneratorFilter{
{
BranchMatch: &regexp,
TargetBranchMatch: &targetRegexp,
},
})
require.NoError(t, err)
assert.Len(t, pullRequests, 1)
assert.Equal(t, PullRequest{
Number: 200,
Title: "feat(200)",
Branch: "feature-200",
HeadSHA: "4cf807e67a6d",
Author: "testName",
TargetBranch: "branch-200",
}, *pullRequests[0])
}
15 changes: 14 additions & 1 deletion docs/operator-manual/applicationset/Generators-Pull-Request.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,27 @@ spec:
# Filter PRs using the source branch name. (optional)
filters:
- branchMatch: ".*-argocd"

# If you need to filter destination branch too, you can use this
- targetBranchMatch: "master"

# Also you can combine source and target branch filters like
# This case will match any pull-request where source branch ends with "-argocd" and destination branch is master
- branchMatch: ".*-argocd"
targetBranchMatch: "master"
template:
# ...
```

- `owner`: Required name of the Bitbucket workspace
- `repo`: Required name of the Bitbucket repository.
- `api`: Optional URL to access the Bitbucket REST API. For the example above, an API request would be made to `https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/pullrequests`. If not set, defaults to `https://api.bitbucket.org/2.0`
- `branchMatch`: Optional regexp filter which should match the source branch name. This is an alternative to labels which are not supported by Bitbucket server.

You can use branch `filters` like
- `branchMatch`: Optional regexp filter which should match the source branch name.
- `targetBranchMatch`: Optional regexp filter which should match destination branch name.

> Note: Labels are not supported by Bitbucket.

If you want to access a private repository, Argo CD will need credentials to access repository in Bitbucket Cloud. You can use Bitbucket App Password (generated per user, with access to whole workspace), or Bitbucket App Token (generated per repository, with access limited to repository scope only). If both App Password and App Token are defined, App Token will be used.

Expand Down
Loading