MCPcopy Create free account
hub / github.com/bytebase/bytebase / UpdateIssue

Method UpdateIssue

backend/store/issue.go:220–275  ·  view source on GitHub ↗

UpdateIssue updates an issue.

(ctx context.Context, projectID string, uid int64, patch *UpdateIssueMessage)

Source from the content-addressed store, hash-verified

218
219// UpdateIssue updates an issue.
220func (s *Store) UpdateIssue(ctx context.Context, projectID string, uid int64, patch *UpdateIssueMessage) (*IssueMessage, error) {
221 oldIssue, err := s.GetIssue(ctx, &FindIssueMessage{ProjectIDs: []string{projectID}, UID: &uid})
222 if err != nil {
223 return nil, err
224 }
225
226 set := qb.Q()
227 set.Comma("updated_at = ?", time.Now())
228
229 if v := patch.Title; v != nil {
230 set.Comma("name = ?", *v)
231 }
232 if v := patch.Status; v != nil {
233 set.Comma("status = ?", v.String())
234 }
235 if v := patch.Description; v != nil {
236 set.Comma("description = ?", *v)
237 }
238 if v := patch.PayloadUpsert; v != nil {
239 v.Labels = CanonicalizeIssueLabels(v.Labels)
240 p, err := protojson.Marshal(v)
241 if err != nil {
242 return nil, errors.Wrapf(err, "failed to marshal patch.PayloadUpsert")
243 }
244 set.Comma("payload = payload || ?", p)
245 } else if patch.RemoveLabels {
246 set.Comma("payload = payload || jsonb_build_object('labels', ?::JSONB)", nil)
247 }
248
249 if patch.Title != nil || patch.Description != nil {
250 title := oldIssue.Title
251 if patch.Title != nil {
252 title = *patch.Title
253 }
254 description := oldIssue.Description
255 if patch.Description != nil {
256 description = *patch.Description
257 }
258
259 tsVector := getTSVector(fmt.Sprintf("%s %s", title, description))
260 set.Comma("ts_vector = ?", tsVector)
261 }
262
263 q := qb.Q().Space("UPDATE issue SET ? WHERE project = ? AND id = ?", set, projectID, uid)
264
265 query, args, err := q.ToSQL()
266 if err != nil {
267 return nil, errors.Wrapf(err, "failed to build sql")
268 }
269
270 if _, err := s.GetDB().ExecContext(ctx, query, args...); err != nil {
271 return nil, err
272 }
273
274 return s.GetIssue(ctx, &FindIssueMessage{ProjectIDs: []string{projectID}, UID: &uid})
275}
276
277// ListIssues returns the list of issues by find query.

Callers

nothing calls this directly

Calls 9

GetIssueMethod · 0.95
GetDBMethod · 0.95
QFunction · 0.92
CanonicalizeIssueLabelsFunction · 0.85
getTSVectorFunction · 0.85
CommaMethod · 0.80
SpaceMethod · 0.80
ToSQLMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected