@@ -180,3 +180,54 @@ func (h *Handlers) pullCommentEditorConfig( |
| 180 | 180 | |
| 181 | 181 | return config |
| 182 | 182 | } |
| 183 | + |
| 184 | +func (h *Handlers) pullNewCommentEditorConfig(ctx context.Context, row reposdb.Repo, viewer middleware.CurrentUser) commentEditorConfig { |
| 185 | + config := commentEditorConfig{} |
| 186 | + if !viewer.IsAnonymous() && !strings.EqualFold(viewer.Username, "copilot") { |
| 187 | + config.Mentions = append(config.Mentions, commentEditorMention{ |
| 188 | + Username: viewer.Username, |
| 189 | + AvatarURL: commentEditorAvatarURL(viewer.Username), |
| 190 | + }) |
| 191 | + } |
| 192 | + |
| 193 | + seenRefs := map[int64]struct{}{} |
| 194 | + addRef := func(number int64, title, kind, state string) { |
| 195 | + if number == 0 { |
| 196 | + return |
| 197 | + } |
| 198 | + if _, ok := seenRefs[number]; ok { |
| 199 | + return |
| 200 | + } |
| 201 | + seenRefs[number] = struct{}{} |
| 202 | + config.References = append(config.References, commentEditorReference{ |
| 203 | + Number: number, |
| 204 | + Title: title, |
| 205 | + Kind: kind, |
| 206 | + State: state, |
| 207 | + }) |
| 208 | + } |
| 209 | + if prs, err := h.pq.ListPullRequestsByRepo(ctx, h.d.Pool, pullsdb.ListPullRequestsByRepoParams{ |
| 210 | + RepoID: row.ID, |
| 211 | + Limit: 8, |
| 212 | + StateFilter: pgtype.Text{}, |
| 213 | + Draft: pgtype.Bool{}, |
| 214 | + }); err == nil { |
| 215 | + for _, item := range prs { |
| 216 | + addRef(item.Number, item.Title, "pull request", string(item.State)) |
| 217 | + } |
| 218 | + } |
| 219 | + if issues, err := h.iq.ListIssues(ctx, h.d.Pool, issuesdb.ListIssuesParams{ |
| 220 | + RepoID: row.ID, |
| 221 | + Limit: 8, |
| 222 | + StateFilter: pgtype.Text{}, |
| 223 | + Kind: issuesdb.NullIssueKind{IssueKind: issuesdb.IssueKindIssue, Valid: true}, |
| 224 | + }); err == nil { |
| 225 | + for _, item := range issues { |
| 226 | + addRef(item.Number, item.Title, "issue", string(item.State)) |
| 227 | + } |
| 228 | + } |
| 229 | + if len(config.References) > 10 { |
| 230 | + config.References = config.References[:10] |
| 231 | + } |
| 232 | + return config |
| 233 | +} |