Skip to content

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

chore: gitlab mr comment (#11480)

Danny Xu157d69120c50
diff --git a/backend/api/gitops/webhook.go b/backend/api/gitops/webhook.go
index 22cd0fe317..1ac8543dbb 100644
--- a/backend/api/gitops/webhook.go
+++ b/backend/api/gitops/webhook.go
@@ -149,11 +149,11 @@ 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 {
+ if vcsProvider.Type == storepb.VCSType_GITHUB || vcsProvider.Type == storepb.VCSType_GITLAB {
comment := getPullRequestComment(setting.ExternalUrl, issue.Name)
pullRequestID := getPullRequestID(prInfo.url)
if err := vcs.Get(
- storepb.VCSType_GITHUB,
+ vcsProvider.Type,
vcs.ProviderConfig{InstanceURL: vcsProvider.InstanceURL, AuthToken: vcsProvider.AccessToken},
).CreatePullRequestComment(ctx, vcsConnector.Payload.ExternalId, pullRequestID, comment); err != nil {
return c.String(http.StatusOK, fmt.Sprintf("failed to create pull request comment, error %v", err))
diff --git a/backend/plugin/vcs/gitlab/gitlab.go b/backend/plugin/vcs/gitlab/gitlab.go
index 86b325fcc9..e31091ce5b 100644
--- a/backend/plugin/vcs/gitlab/gitlab.go
+++ b/backend/plugin/vcs/gitlab/gitlab.go
@@ -295,7 +295,25 @@ func (p *Provider) ListPullRequestFile(ctx context.Context, repositoryID, pullRe
}
// 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 {
+ url := fmt.Sprintf("%s/projects/%s/merge_requests/%s/notes?body=%s", p.APIURL(p.instanceURL), repositoryID, pullRequestID, url.QueryEscape(comment))
+ code, body, err := internal.Post(ctx, url, p.getAuthorization(), nil)
+ 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)
+ }
+
+ // GitLab 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/gitlab.go b/backend/tests/fake/gitlab.go
index c4b00fc196..eb83d6e080 100644
--- a/backend/tests/fake/gitlab.go
+++ b/backend/tests/fake/gitlab.go
@@ -71,6 +71,7 @@ func NewGitLab(port int) VCSProvider {
projectGroup.POST("/projects/:id/repository/branches", gl.createProjectBranch)
projectGroup.POST("/projects/:id/merge_requests", gl.createProjectPullRequest)
projectGroup.GET("/projects/:id/merge_requests/:mrID/changes", gl.getMergeRequestChanges)
+ projectGroup.GET("/projects/:id/merge_requests/:mrID/notes", gl.createMergeRequestComment)
projectGroup.GET("/projects/:id/repository/compare", gl.compareCommits)
return gl
@@ -357,6 +358,10 @@ func (gl *GitLab) getMergeRequestChanges(c echo.Context) error {
return c.String(http.StatusOK, string(buf))
}
+func (*GitLab) createMergeRequestComment(echo.Context) error {
+ return nil
+}
+
func (gl *GitLab) compareCommits(c echo.Context) error {
pd, err := gl.validProject(c)
if err != nil {
diff --git a/frontend/src/components/IssueV1/components/Sidebar/VCSInfo.vue b/frontend/src/components/IssueV1/components/Sidebar/VCSInfo.vue
index 9f8b6ee068..7fdda258ea 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/VCSInfo.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/VCSInfo.vue
@@ -3,7 +3,7 @@
v-if="issue.planEntity?.vcsSource && vcsConnector"
class="text-sm text-control-light flex space-x-1 items-center"
>
- <VCSIcon v-if="vcsProvider" :type="vcsProvider.type" />
+ <VCSIcon :type="issue.planEntity?.vcsSource.vcsType" />
<a
:href="issue.planEntity?.vcsSource.pullRequestUrl"
target="_blank"