Skip to content

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

Comment create webhook

天舟f1e86344e99a
diff --git a/server/activity.go b/server/activity.go
index 84e0b137d6..16b86301b4 100644
--- a/server/activity.go
+++ b/server/activity.go
@@ -45,17 +45,13 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {
foundIssue = issue
}
- activity, err := s.ActivityService.CreateActivity(context.Background(), activityCreate)
+ activity, err := s.ActivityManager.CreateActivity(context.Background(), activityCreate, &ActivityMeta{
+ issue: foundIssue,
+ })
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
}
- if activityCreate.Type == api.ActivityIssueCommentCreate {
- if err := s.PostInboxIssueActivity(context.Background(), foundIssue, activity.ID); err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to post activity to inbox").SetInternal(err)
- }
- }
-
if err := s.ComposeActivityRelationship(context.Background(), activity); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch created activity relationship").SetInternal(err)
}
diff --git a/server/activity_manager.go b/server/activity_manager.go
index a5de8a1f1e..78cb05ecce 100644
--- a/server/activity_manager.go
+++ b/server/activity_manager.go
@@ -26,15 +26,15 @@ func NewActivityManager(server *Server, activityService api.ActivityService) *Ac
}
}
-func (m *ActivityManager) CreateActivity(ctx context.Context, create *api.ActivityCreate, meta *ActivityMeta) error {
+func (m *ActivityManager) CreateActivity(ctx context.Context, create *api.ActivityCreate, meta *ActivityMeta) (*api.Activity, error) {
activity, err := m.activityService.CreateActivity(ctx, create)
if err != nil {
- return err
+ return nil, err
}
if meta.issue != nil {
if err := m.s.PostInboxIssueActivity(context.Background(), meta.issue, activity.ID); err != nil {
- return err
+ return nil, err
}
hookFind := &api.ProjectWebhookFind{
@@ -43,7 +43,7 @@ func (m *ActivityManager) CreateActivity(ctx context.Context, create *api.Activi
}
hookList, err := m.s.ProjectWebhookService.FindProjectWebhookList(context.Background(), hookFind)
if err != nil {
- return fmt.Errorf("failed to find project webhook hook after changing the issue status: %v, error: %w", meta.issue.Name, err)
+ return nil, fmt.Errorf("failed to find project webhook hook after changing the issue status: %v, error: %w", meta.issue.Name, err)
}
// If we need to post webhook event, then we need to make sure the project info exists since we will include
@@ -55,7 +55,7 @@ func (m *ActivityManager) CreateActivity(ctx context.Context, create *api.Activi
}
meta.issue.Project, err = m.s.ProjectService.FindProject(ctx, projectFind)
if err != nil {
- return fmt.Errorf("failed to find project for posting webhook event after changing the issue status: %v, error: %w", meta.issue.Name, err)
+ return nil, fmt.Errorf("failed to find project for posting webhook event after changing the issue status: %v, error: %w", meta.issue.Name, err)
}
}
@@ -64,38 +64,50 @@ func (m *ActivityManager) CreateActivity(ctx context.Context, create *api.Activi
}
updater, err := m.s.PrincipalService.FindPrincipal(context.Background(), principalFind)
if err != nil {
- return fmt.Errorf("failed to find updater for posting webhook event after changing the issue status: %v, error: %w", meta.issue.Name, err)
+ return nil, fmt.Errorf("failed to find updater for posting webhook event after changing the issue status: %v, error: %w", meta.issue.Name, err)
}
// Call exteranl webhook endpoint in Go routine to avoid blocking web serveing thread.
go func() {
for _, hook := range hookList {
title := ""
- switch meta.issue.Status {
- case "OPEN":
- title = fmt.Sprintf("Issue reopened - %s", meta.issue.Name)
- case "DONE":
- title = fmt.Sprintf("Issue resolved - %s", meta.issue.Name)
- case "CANCELED":
- title = fmt.Sprintf("Issue canceled - %s", meta.issue.Name)
+ link := fmt.Sprintf("%s:%d/issue/%s", m.s.frontendHost, m.s.frontendPort, api.IssueSlug(meta.issue))
+ metaList := []webhook.WebhookMeta{}
+ switch create.Type {
+ case api.ActivityIssueStatusUpdate:
+ switch meta.issue.Status {
+ case "OPEN":
+ title = fmt.Sprintf("Reopened issue - %s", meta.issue.Name)
+ case "DONE":
+ title = fmt.Sprintf("Resolved issue - %s", meta.issue.Name)
+ case "CANCELED":
+ title = fmt.Sprintf("Canceled issue - %s", meta.issue.Name)
+ }
+ case api.ActivityIssueCommentCreate:
+ title = "Comment created"
+ link += fmt.Sprintf("#activity%d", activity.ID)
+ metaList = append(metaList, webhook.WebhookMeta{
+ Name: "Issue",
+ Value: meta.issue.Name,
+ })
}
+ metaList = append(metaList, webhook.WebhookMeta{
+ Name: "Project",
+ Value: meta.issue.Project.Name,
+ })
+
err := webhook.Post(
hook.Type,
webhook.WebhookContext{
URL: hook.URL,
Title: title,
Description: create.Comment,
- Link: fmt.Sprintf("%s:%d/issue/%s", m.s.frontendHost, m.s.frontendPort, api.IssueSlug(meta.issue)),
+ Link: link,
CreatorName: updater.Name,
CreatorEmail: updater.Email,
CreatedTs: time.Now().Unix(),
- MetaList: []webhook.WebhookMeta{
- {
- Name: "Project",
- Value: meta.issue.Project.Name,
- },
- },
+ MetaList: metaList,
},
)
if err != nil {
@@ -110,5 +122,5 @@ func (m *ActivityManager) CreateActivity(ctx context.Context, create *api.Activi
}
}
- return nil
+ return activity, nil
}
diff --git a/server/issue.go b/server/issue.go
index 20c36409e8..cb1b816f27 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -494,7 +494,7 @@ func (s *Server) ChangeIssueStatus(ctx context.Context, issue *api.Issue, newSta
Payload: string(payload),
}
- err = s.ActivityManager.CreateActivity(context.Background(), activityCreate, &ActivityMeta{
+ _, err = s.ActivityManager.CreateActivity(context.Background(), activityCreate, &ActivityMeta{
issue: updatedIssue,
})
if err != nil {