Skip to content

Commit ad3fe09

Browse files
committed
1 parent 93c58e9 commit ad3fe09

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

models/issues/comment.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,9 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
871871
}
872872
fallthrough
873873
case CommentTypeComment:
874+
if err = updateAttachments(ctx, opts, comment); err != nil {
875+
return err
876+
}
874877
if _, err = db.Exec(ctx, "UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil {
875878
return err
876879
}
@@ -896,8 +899,7 @@ func updateAttachments(ctx context.Context, opts *CreateCommentOptions, comment
896899
for i := range attachments {
897900
attachments[i].IssueID = opts.Issue.ID
898901
attachments[i].CommentID = comment.ID
899-
// No assign value could be 0, so ignore AllCols().
900-
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil {
902+
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Cols("issue_id", "comment_id").Update(attachments[i]); err != nil {
901903
return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err)
902904
}
903905
}

models/issues/issue_update.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ type NewIssueOptions struct {
282282

283283
// NewIssueWithIndex creates issue with given index
284284
func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssueOptions) (err error) {
285-
e := db.GetEngine(ctx)
286285
opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
287286

288287
if opts.Issue.MilestoneID > 0 {
@@ -306,7 +305,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
306305
return fmt.Errorf("issue exist")
307306
}
308307

309-
if _, err := e.Insert(opts.Issue); err != nil {
308+
if err := db.Insert(ctx, opts.Issue); err != nil {
310309
return err
311310
}
312311

@@ -336,7 +335,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
336335
// During the session, SQLite3 driver cannot handle retrieve objects after update something.
337336
// So we have to get all needed labels first.
338337
labels := make([]*Label, 0, len(opts.LabelIDs))
339-
if err = e.In("id", opts.LabelIDs).Find(&labels); err != nil {
338+
if err = db.GetEngine(ctx).In("id", opts.LabelIDs).Find(&labels); err != nil {
340339
return fmt.Errorf("find all labels [label_ids: %v]: %w", opts.LabelIDs, err)
341340
}
342341

@@ -368,8 +367,8 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
368367

369368
for i := 0; i < len(attachments); i++ {
370369
attachments[i].IssueID = opts.Issue.ID
371-
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
372-
return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err)
370+
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Cols("issue_id").Update(attachments[i]); err != nil {
371+
return fmt.Errorf("update attachment issue_id [id: %d]: %w", attachments[i].ID, err)
373372
}
374373
}
375374
}

services/repository/repository.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili
124124

125125
// LinkedRepository returns the linked repo if any
126126
func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_model.Repository, unit.Type, error) {
127-
if a.IssueID != 0 {
127+
if a.IssueID != 0 { // attachment for issues or comments
128128
iss, err := issues_model.GetIssueByID(ctx, a.IssueID)
129129
if err != nil {
130130
return nil, unit.TypeIssues, err
@@ -135,13 +135,16 @@ func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_mode
135135
unitType = unit.TypePullRequests
136136
}
137137
return repo, unitType, err
138-
} else if a.ReleaseID != 0 {
138+
} else if a.ReleaseID != 0 { // attachment for releases
139139
rel, err := repo_model.GetReleaseByID(ctx, a.ReleaseID)
140140
if err != nil {
141141
return nil, unit.TypeReleases, err
142142
}
143143
repo, err := repo_model.GetRepositoryByID(ctx, rel.RepoID)
144144
return repo, unit.TypeReleases, err
145+
} else if a.RepoID > 0 { // attachment for repository upload
146+
repo, err := repo_model.GetRepositoryByID(ctx, a.RepoID)
147+
return repo, unit.TypeCode, err
145148
}
146149
return nil, -1, nil
147150
}

0 commit comments

Comments
 (0)