Skip to content

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

refactor: decouple issue status from rollout execution (#18690)

Danny Xud1f144d3a399
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 19ec722828..8c73687612 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -751,9 +751,33 @@ func (s *IssueService) ApproveIssue(ctx context.Context, req *connect.Request[v1
return errors.Wrap(err, "failed to check if the approval is approved")
}
if approved {
- if err := webhook.ChangeIssueStatus(ctx, s.store, s.webhookManager, issue, storepb.Issue_DONE, store.SystemBotUser, ""); err != nil {
- return errors.Wrap(err, "failed to update issue status")
+ newStatus := storepb.Issue_DONE
+ updatedIssue, err := s.store.UpdateIssue(ctx, issue.UID, &store.UpdateIssueMessage{Status: &newStatus})
+ if err != nil {
+ return errors.Wrapf(err, "failed to update issue %q's status", issue.Title)
+ }
+
+ if _, err := s.store.CreateIssueComments(ctx, common.SystemBotEmail, &store.IssueCommentMessage{
+ IssueUID: issue.UID,
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_IssueUpdate_{
+ IssueUpdate: &storepb.IssueCommentPayload_IssueUpdate{
+ FromStatus: &issue.Status,
+ ToStatus: &updatedIssue.Status,
+ },
+ },
+ },
+ }); err != nil {
+ return errors.Wrapf(err, "failed to create issue comment after changing the issue status")
}
+
+ s.webhookManager.CreateEvent(ctx, &webhook.Event{
+ Actor: store.SystemBotUser,
+ Type: storepb.Activity_ISSUE_STATUS_UPDATE,
+ Comment: "",
+ Issue: webhook.NewIssue(updatedIssue),
+ Project: webhook.NewProject(project),
+ })
}
return nil
}(); err != nil {
diff --git a/backend/api/v1/rollout_service.go b/backend/api/v1/rollout_service.go
index 421ba324b3..3a334e3048 100644
--- a/backend/api/v1/rollout_service.go
+++ b/backend/api/v1/rollout_service.go
@@ -363,6 +363,37 @@ func CreateRolloutAndPendingTasks(
return errors.Wrap(err, "failed to update plan hasRollout")
}
+ // Update issue status to DONE when rollout is created
+ if issue != nil {
+ newStatus := storepb.Issue_DONE
+ updatedIssue, err := s.UpdateIssue(ctx, issue.UID, &store.UpdateIssueMessage{Status: &newStatus})
+ if err != nil {
+ return errors.Wrapf(err, "failed to update issue %q's status", issue.Title)
+ }
+
+ if _, err := s.CreateIssueComments(ctx, common.SystemBotEmail, &store.IssueCommentMessage{
+ IssueUID: issue.UID,
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_IssueUpdate_{
+ IssueUpdate: &storepb.IssueCommentPayload_IssueUpdate{
+ FromStatus: &issue.Status,
+ ToStatus: &updatedIssue.Status,
+ },
+ },
+ },
+ }); err != nil {
+ return errors.Wrapf(err, "failed to create issue comment after changing the issue status")
+ }
+
+ webhookManager.CreateEvent(ctx, &webhook.Event{
+ Actor: store.SystemBotUser,
+ Type: storepb.Activity_ISSUE_STATUS_UPDATE,
+ Comment: "",
+ Issue: webhook.NewIssue(updatedIssue),
+ Project: webhook.NewProject(project),
+ })
+ }
+
// Check if we should auto-rollout
envPolicies := make(map[string]*storepb.RolloutPolicy)
for _, task := range tasks {
diff --git a/backend/component/webhook/manager.go b/backend/component/webhook/manager.go
index ec17ea82d8..059b84852a 100644
--- a/backend/component/webhook/manager.go
+++ b/backend/component/webhook/manager.go
@@ -372,29 +372,3 @@ func getUsersFromUsers(users ...*store.UserMessage) UsersGetter {
return users, nil
}
}
-
-// ChangeIssueStatus changes the status of an issue.
-func ChangeIssueStatus(ctx context.Context, stores *store.Store, webhookManager *Manager, issue *store.IssueMessage, newStatus storepb.Issue_Status, updater *store.UserMessage, comment string) error {
- updateIssueMessage := &store.UpdateIssueMessage{Status: &newStatus}
- updatedIssue, err := stores.UpdateIssue(ctx, issue.UID, updateIssueMessage)
- if err != nil {
- return errors.Wrapf(err, "failed to update issue %q's status", issue.Title)
- }
-
- project, err := stores.GetProject(ctx, &store.FindProjectMessage{ResourceID: &updatedIssue.ProjectID})
- if err != nil {
- return errors.Wrapf(err, "failed to get project")
- }
- if project == nil {
- return errors.Errorf("project %s not found", updatedIssue.ProjectID)
- }
-
- webhookManager.CreateEvent(ctx, &Event{
- Actor: updater,
- Type: storepb.Activity_ISSUE_STATUS_UPDATE,
- Comment: comment,
- Issue: NewIssue(updatedIssue),
- Project: NewProject(project),
- })
- return nil
-}
diff --git a/backend/runner/approval/runner.go b/backend/runner/approval/runner.go
index b7208ce6a0..24918f5f2d 100644
--- a/backend/runner/approval/runner.go
+++ b/backend/runner/approval/runner.go
@@ -191,7 +191,36 @@ func (r *Runner) findApprovalTemplateForIssue(ctx context.Context, issue *store.
if err := utils.UpdateProjectPolicyFromGrantIssue(ctx, r.store, issue, payload.GrantRequest); err != nil {
return false, err
}
- if err := webhook.ChangeIssueStatus(ctx, r.store, r.webhookManager, issue, storepb.Issue_DONE, store.SystemBotUser, ""); err != nil {
+ if err := func() error {
+ newStatus := storepb.Issue_DONE
+ updatedIssue, err := r.store.UpdateIssue(ctx, issue.UID, &store.UpdateIssueMessage{Status: &newStatus})
+ if err != nil {
+ return errors.Wrapf(err, "failed to update issue %q's status", issue.Title)
+ }
+
+ if _, err := r.store.CreateIssueComments(ctx, common.SystemBotEmail, &store.IssueCommentMessage{
+ IssueUID: issue.UID,
+ Payload: &storepb.IssueCommentPayload{
+ Event: &storepb.IssueCommentPayload_IssueUpdate_{
+ IssueUpdate: &storepb.IssueCommentPayload_IssueUpdate{
+ FromStatus: &issue.Status,
+ ToStatus: &updatedIssue.Status,
+ },
+ },
+ },
+ }); err != nil {
+ return errors.Wrapf(err, "failed to create issue comment after changing the issue status")
+ }
+
+ r.webhookManager.CreateEvent(ctx, &webhook.Event{
+ Actor: store.SystemBotUser,
+ Type: storepb.Activity_ISSUE_STATUS_UPDATE,
+ Comment: "",
+ Issue: webhook.NewIssue(updatedIssue),
+ Project: webhook.NewProject(project),
+ })
+ return nil
+ }(); err != nil {
return false, errors.Wrap(err, "failed to update issue status")
}
}
diff --git a/backend/runner/taskrun/scheduler.go b/backend/runner/taskrun/scheduler.go
index 35dccb2b67..976f0d8751 100644
--- a/backend/runner/taskrun/scheduler.go
+++ b/backend/runner/taskrun/scheduler.go
@@ -8,7 +8,6 @@ import (
"github.com/pkg/errors"
- "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/component/config"
"github.com/bytebase/bytebase/backend/component/state"
@@ -149,15 +148,11 @@ func (s *Scheduler) ListenTaskSkippedOrDone(ctx context.Context) {
currentEnvironment := task.Environment
var nextEnvironment string
- var planDone bool
for i, env := range filteredEnvironmentOrder {
if env == currentEnvironment {
if i < len(filteredEnvironmentOrder)-1 {
nextEnvironment = filteredEnvironmentOrder[i+1]
}
- if i == len(filteredEnvironmentOrder)-1 {
- planDone = true
- }
break
}
}
@@ -221,49 +216,6 @@ func (s *Scheduler) ListenTaskSkippedOrDone(ctx context.Context) {
slog.Error("failed to create rollout release notification activity", log.BBError(err))
}
- // After all tasks in the pipeline are done, we will resolve the issue.
- if issueN != nil && planDone {
- if err := func() error {
- // For those database data export issues, we don't resolve them automatically.
- if issueN.Type == storepb.Issue_DATABASE_EXPORT {
- return nil
- }
-
- newStatus := storepb.Issue_DONE
- updatedIssue, err := s.store.UpdateIssue(ctx, issueN.UID, &store.UpdateIssueMessage{Status: &newStatus})
- if err != nil {
- return errors.Wrapf(err, "failed to update issue status")
- }
-
- fromStatus := storepb.Issue_Status(storepb.Issue_Status_value[issueN.Status.String()])
- toStatus := storepb.Issue_Status(storepb.Issue_Status_value[updatedIssue.Status.String()])
- if _, err := s.store.CreateIssueComments(ctx, common.SystemBotEmail, &store.IssueCommentMessage{
- IssueUID: issueN.UID,
- Payload: &storepb.IssueCommentPayload{
- Event: &storepb.IssueCommentPayload_IssueUpdate_{
- IssueUpdate: &storepb.IssueCommentPayload_IssueUpdate{
- FromStatus: &fromStatus,
- ToStatus: &toStatus,
- },
- },
- },
- }); err != nil {
- return errors.Wrapf(err, "failed to create issue comment after changing the issue status")
- }
-
- s.webhookManager.CreateEvent(ctx, &webhook.Event{
- Actor: store.SystemBotUser,
- Type: storepb.Activity_ISSUE_STATUS_UPDATE,
- Comment: "",
- Issue: webhook.NewIssue(updatedIssue),
- Project: webhook.NewProject(project),
- })
-
- return nil
- }(); err != nil {
- slog.Error("failed to update issue status", log.BBError(err))
- }
- }
return nil
}(); err != nil {
slog.Error("failed to handle task skipped or done", log.BBError(err))