(ctx context.Context, ref bus.IssueRef)
| 88 | } |
| 89 | |
| 90 | func (r *Runner) processIssue(ctx context.Context, ref bus.IssueRef) { |
| 91 | // Get fresh issue from database |
| 92 | uid := ref.UID |
| 93 | issue, err := r.store.GetIssue(ctx, &store.FindIssueMessage{ProjectIDs: []string{ref.ProjectID}, UID: &uid}) |
| 94 | if err != nil { |
| 95 | slog.Error("failed to get issue for approval check", |
| 96 | slog.String("project", ref.ProjectID), slog.Int64("issue_uid", ref.UID), log.BBError(err)) |
| 97 | return |
| 98 | } |
| 99 | if issue == nil { |
| 100 | return // Issue deleted, nothing to do |
| 101 | } |
| 102 | |
| 103 | project, err := r.store.GetProjectByResourceID(ctx, ref.ProjectID) |
| 104 | if err != nil { |
| 105 | slog.Error("failed to get project", log.BBError(err)) |
| 106 | return |
| 107 | } |
| 108 | if project == nil { |
| 109 | slog.Error("project not found", slog.String("project", ref.ProjectID)) |
| 110 | return |
| 111 | } |
| 112 | approvalSetting, err := r.store.GetWorkspaceApprovalSetting(ctx, project.Workspace) |
| 113 | if err != nil { |
| 114 | slog.Error("failed to get workspace approval setting", log.BBError(err)) |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | if err := findApprovalTemplateForIssue(ctx, r.store, r.webhookManager, r.licenseService, issue, approvalSetting); err != nil { |
| 119 | slog.Error("failed to find approval template", |
| 120 | slog.String("project", ref.ProjectID), slog.Int64("issue_uid", ref.UID), |
| 121 | slog.String("issue_title", issue.Title), |
| 122 | log.BBError(err)) |
| 123 | // Don't persist error - user can rerun plan check to retry |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | // After approval finding is done, check if the issue is now approved |
| 128 | // (e.g., skip approval case where no template is required). |
| 129 | // If approved, trigger rollout creation. |
| 130 | if issue.PlanUID != nil { |
| 131 | // Re-fetch issue to get updated approval state |
| 132 | issue, err = r.store.GetIssue(ctx, &store.FindIssueMessage{ProjectIDs: []string{ref.ProjectID}, UID: &uid}) |
| 133 | if err != nil { |
| 134 | slog.Error("failed to re-fetch issue after approval finding", |
| 135 | slog.String("project", ref.ProjectID), slog.Int64("issue_uid", ref.UID), log.BBError(err)) |
| 136 | return |
| 137 | } |
| 138 | if issue == nil { |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | approved, err := utils.CheckIssueApproved(issue) |
| 143 | if err != nil { |
| 144 | slog.Error("failed to check if issue is approved", |
| 145 | slog.String("project", ref.ProjectID), slog.Int64("issue_uid", ref.UID), log.BBError(err)) |
| 146 | return |
| 147 | } |
no test coverage detected