Skip to content

Commit be9246a

Browse files
authored
Merge pull request #725 from chmouel/issue-723-incoming-webhook-for-bitbucket-cloud
2 parents 47899ec + 7d6df48 commit be9246a

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

docs/content/docs/guide/incoming_webhook.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ you will need to have a git_provider spec to specify a token when using the
1818
github-apps method the same way we are doing for github-webhook method. Refer to
1919
the [github webhook documentation](/docs/install/github_webhook) for how to set
2020
this up.
21+
22+
Additionally since we are not able to detect automatically the type of provider
23+
on URL. You will need to add it to the `git_provider.type` spec. Supported
24+
values are:
25+
26+
- github
27+
- gitlab
28+
- bitbucket-cloud
29+
2130
{{< /hint >}}
2231

2332
Here is an example of a Repository CRD matching the target branch main:

pkg/provider/bitbucketcloud/bitbucket.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ func (v *Provider) SetClient(_ context.Context, event *info.Event) error {
152152
}
153153

154154
func (v *Provider) GetCommitInfo(_ context.Context, event *info.Event) error {
155+
branchortag := event.SHA
156+
if branchortag == "" {
157+
branchortag = event.HeadBranch
158+
}
155159
response, err := v.Client.Repositories.Commits.GetCommits(&bitbucket.CommitsOptions{
156160
Owner: event.Organization,
157161
RepoSlug: event.Repository,
158-
Branchortag: event.SHA,
162+
Branchortag: branchortag,
159163
})
160164
if err != nil {
161165
return err

pkg/provider/bitbucketcloud/bitbucket_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ func TestGetCommitInfo(t *testing.T) {
149149
Mainbranch: bitbucket.RepositoryBranch{Name: "branshe"},
150150
},
151151
},
152+
{
153+
name: "Get commit info no SHA",
154+
event: bbcloudtest.MakeEvent(&info.Event{
155+
Organization: "org",
156+
Repository: "repo",
157+
HeadBranch: "hello",
158+
SHA: "none",
159+
}),
160+
commitinfo: types.Commit{
161+
Hash: "convertedcommit",
162+
Links: types.Links{
163+
HTML: types.HTMLLink{
164+
HRef: "https://everywhereigo",
165+
},
166+
},
167+
Message: "Das Commit",
168+
Author: types.Author{},
169+
},
170+
repoinfo: &bitbucket.Repository{
171+
Mainbranch: bitbucket.RepositoryBranch{Name: "branshe"},
172+
},
173+
},
152174
}
153175
for _, tt := range tests {
154176
t.Run(tt.name, func(t *testing.T) {

pkg/provider/bitbucketcloud/test/bbcloudtest.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ func MakeEvent(event *info.Event) *info.Event {
325325
if rev.SHA == "" {
326326
rev.SHA = "1234"
327327
}
328+
if rev.SHA == "none" {
329+
rev.SHA = ""
330+
}
328331
if rev.Organization == "" {
329332
rev.Organization = "owner"
330333
}

0 commit comments

Comments
 (0)