Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: bitbucket pr comment (#11481)

Danny Xu6c847b9a21b8
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index 1ac8543dbb..f26e2c7e81 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -149,7 +149,7 @@ func (s *Service) RegisterWebhookRoutes(g *echo.Group) {
if err != nil {
return c.String(http.StatusOK, fmt.Sprintf("failed to create issue from pull request %s, error %v", prInfo.url, err))
}
- if vcsProvider.Type == storepb.VCSType_GITHUB || vcsProvider.Type == storepb.VCSType_GITLAB {
+ if vcsProvider.Type == storepb.VCSType_GITHUB || vcsProvider.Type == storepb.VCSType_GITLAB || vcsProvider.Type == storepb.VCSType_BITBUCKET {
comment := getPullRequestComment(setting.ExternalUrl, issue.Name)
pullRequestID := getPullRequestID(prInfo.url)
if err := vcs.Get(
diff --git a/backend/plugin/vcs/bitbucket/bitbucket.go b/backend/plugin/vcs/bitbucket/bitbucket.go
index c34ab2f013..47ce9f8347 100644
--- a/backend/plugin/vcs/bitbucket/bitbucket.go
+++ b/backend/plugin/vcs/bitbucket/bitbucket.go
@@ -311,8 +311,39 @@ func (p *Provider) ListPullRequestFile(ctx context.Context, repositoryID, pullRe
return files, nil
}
+type Comment struct {
+ Content CommentContent `json:"content"`
+}
+
+type CommentContent struct {
+ Raw string `json:"raw"`
+}
+
// CreatePullRequestComment creates a pull request comment.
-func (*Provider) CreatePullRequestComment(_ context.Context, _, _, _ string) error {
+func (p *Provider) CreatePullRequestComment(ctx context.Context, repositoryID, pullRequestID, comment string) error {
+ commentMessage := Comment{Content: CommentContent{Raw: comment}}
+ commentCreatePayload, err := json.Marshal(commentMessage)
+ if err != nil {
+ return errors.Wrap(err, "failed to marshal request body for creating pull request comment")
+ }
+ url := fmt.Sprintf("%s/repositories/%s/pullrequests/%s/comments", p.APIURL(p.instanceURL), repositoryID, pullRequestID)
+ code, body, err := internal.Post(ctx, url, p.getAuthorization(), commentCreatePayload)
+ if err != nil {
+ return errors.Wrapf(err, "POST %s", url)
+ }
+
+ if code == http.StatusNotFound {
+ return common.Errorf(common.NotFound, "failed to create pull request comment through URL %s", url)
+ }
+
+ // GitHub returns 201 HTTP status codes upon successful issue comment creation,
+ if code != http.StatusCreated {
+ return errors.Errorf("failed to create pull request comment through URL %s, status code: %d, body: %s",
+ url,
+ code,
+ body,
+ )
+ }
return nil
}
diff --git a/backend/tests/fake/bitbucket.go b/backend/tests/fake/bitbucket.go
index 125bd9da80..1b6ff2ad0f 100644
--- a/backend/tests/fake/bitbucket.go
+++ b/backend/tests/fake/bitbucket.go
@@ -66,6 +66,7 @@ func NewBitbucket(port int) VCSProvider {
g.GET("/repositories/:owner/:repo/refs/branches/:branchName", bb.getRepositoryBranch)
g.GET("/repositories/:owner/:repo/diffstat/:baseHead", bb.compareCommits)
g.GET("/repositories/:owner/:repo/pullrequests/:prID/diffstat", bb.listPullRequestFile)
+ g.GET("/repositories/:owner/:repo/pullrequests/:prID/comments", bb.createPullRequestComment)
return bb
}
@@ -403,3 +404,7 @@ func (bb *Bitbucket) listPullRequestFile(c echo.Context) error {
}
return c.String(http.StatusOK, string(buf))
}
+
+func (*Bitbucket) createPullRequestComment(echo.Context) error {
+ return nil
+}
diff --git a/frontend/src/types/proto/v1/rollout_service.ts b/frontend/src/types/proto/v1/rollout_service.ts
index 0bf8a2104c..8aaff29736 100644
--- a/frontend/src/types/proto/v1/rollout_service.ts
+++ b/frontend/src/types/proto/v1/rollout_service.ts
@@ -301,12 +301,12 @@ export interface Plan_ExportDataConfig {
}
export interface Plan_VCSSource {
+ vcsType: VCSType;
/**
* Optional.
* If present, we will update the pull request for rollout status.
* Format: projects/{project-ID}/vcsConnectors/{vcs-connector}
*/
- vcsType: VCSType;
vcsConnector: string;
pullRequestUrl: string;
}
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index 061c8c6e06..dbf843f250 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -7512,8 +7512,8 @@ When paginating, all other parameters provided to `ListRolloutTaskRuns` must mat
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
-| vcs_type | [VCSType](#bytebase-v1-VCSType) | | Optional. If present, we will update the pull request for rollout status. Format: projects/{project-ID}/vcsConnectors/{vcs-connector} |
-| vcs_connector | [string](#string) | | |
+| vcs_type | [VCSType](#bytebase-v1-VCSType) | | |
+| vcs_connector | [string](#string) | | Optional. If present, we will update the pull request for rollout status. Format: projects/{project-ID}/vcsConnectors/{vcs-connector} |
| pull_request_url | [string](#string) | | |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 825e25028b..f2d87c2734 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -20880,16 +20880,16 @@ Must be a subset of the specs in the same step. </p></td>
<td>vcs_type</td>
<td><a href="#bytebase.v1.VCSType">VCSType</a></td>
<td></td>
- <td><p>Optional.
-If present, we will update the pull request for rollout status.
-Format: projects/{project-ID}/vcsConnectors/{vcs-connector} </p></td>
+ <td><p> </p></td>
</tr>
<tr>
<td>vcs_connector</td>
<td><a href="#string">string</a></td>
<td></td>
- <td><p> </p></td>
+ <td><p>Optional.
+If present, we will update the pull request for rollout status.
+Format: projects/{project-ID}/vcsConnectors/{vcs-connector} </p></td>
</tr>
<tr>
diff --git a/proto/generated-go/v1/rollout_service.pb.go b/proto/generated-go/v1/rollout_service.pb.go
index ec3efd9ea7..f807fb4f64 100644
--- a/proto/generated-go/v1/rollout_service.pb.go
+++ b/proto/generated-go/v1/rollout_service.pb.go
@@ -3007,12 +3007,12 @@ type Plan_VCSSource struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
+ VcsType VCSType `protobuf:"varint,1,opt,name=vcs_type,json=vcsType,proto3,enum=bytebase.v1.VCSType" json:"vcs_type,omitempty"`
// Optional.
// If present, we will update the pull request for rollout status.
// Format: projects/{project-ID}/vcsConnectors/{vcs-connector}
- VcsType VCSType `protobuf:"varint,1,opt,name=vcs_type,json=vcsType,proto3,enum=bytebase.v1.VCSType" json:"vcs_type,omitempty"`
- VcsConnector string `protobuf:"bytes,2,opt,name=vcs_connector,json=vcsConnector,proto3" json:"vcs_connector,omitempty"`
- PullRequestUrl string `protobuf:"bytes,3,opt,name=pull_request_url,json=pullRequestUrl,proto3" json:"pull_request_url,omitempty"`
+ VcsConnector string `protobuf:"bytes,2,opt,name=vcs_connector,json=vcsConnector,proto3" json:"vcs_connector,omitempty"`
+ PullRequestUrl string `protobuf:"bytes,3,opt,name=pull_request_url,json=pullRequestUrl,proto3" json:"pull_request_url,omitempty"`
}
func (x *Plan_VCSSource) Reset() {
diff --git a/proto/v1/rollout_service.proto b/proto/v1/rollout_service.proto
index 4d3d57e8e0..b3749468e3 100644
--- a/proto/v1/rollout_service.proto
+++ b/proto/v1/rollout_service.proto
@@ -293,10 +293,10 @@ message Plan {
}
message VCSSource {
+ VCSType vcs_type = 1;
// Optional.
// If present, we will update the pull request for rollout status.
// Format: projects/{project-ID}/vcsConnectors/{vcs-connector}
- VCSType vcs_type = 1;
string vcs_connector = 2;
string pull_request_url = 3;
}