Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zjjhot committed Mar 2, 2024
1 parent 93c58e9 commit ad3fe09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions models/issues/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,9 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
}
fallthrough
case CommentTypeComment:
if err = updateAttachments(ctx, opts, comment); err != nil {
return err
}
if _, err = db.Exec(ctx, "UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil {
return err
}
Expand All @@ -896,8 +899,7 @@ func updateAttachments(ctx context.Context, opts *CreateCommentOptions, comment
for i := range attachments {
attachments[i].IssueID = opts.Issue.ID
attachments[i].CommentID = comment.ID
// No assign value could be 0, so ignore AllCols().
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Update(attachments[i]); err != nil {
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Cols("issue_id", "comment_id").Update(attachments[i]); err != nil {
return fmt.Errorf("update attachment [%d]: %w", attachments[i].ID, err)
}
}
Expand Down
9 changes: 4 additions & 5 deletions models/issues/issue_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ type NewIssueOptions struct {

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

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

if _, err := e.Insert(opts.Issue); err != nil {
if err := db.Insert(ctx, opts.Issue); err != nil {
return err
}

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

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

for i := 0; i < len(attachments); i++ {
attachments[i].IssueID = opts.Issue.ID
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
return fmt.Errorf("update attachment [id: %d]: %w", attachments[i].ID, err)
if _, err = db.GetEngine(ctx).ID(attachments[i].ID).Cols("issue_id").Update(attachments[i]); err != nil {
return fmt.Errorf("update attachment issue_id [id: %d]: %w", attachments[i].ID, err)
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions services/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili

// LinkedRepository returns the linked repo if any
func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_model.Repository, unit.Type, error) {
if a.IssueID != 0 {
if a.IssueID != 0 { // attachment for issues or comments
iss, err := issues_model.GetIssueByID(ctx, a.IssueID)
if err != nil {
return nil, unit.TypeIssues, err
Expand All @@ -135,13 +135,16 @@ func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_mode
unitType = unit.TypePullRequests
}
return repo, unitType, err
} else if a.ReleaseID != 0 {
} else if a.ReleaseID != 0 { // attachment for releases
rel, err := repo_model.GetReleaseByID(ctx, a.ReleaseID)
if err != nil {
return nil, unit.TypeReleases, err
}
repo, err := repo_model.GetRepositoryByID(ctx, rel.RepoID)
return repo, unit.TypeReleases, err
} else if a.RepoID > 0 { // attachment for repository upload
repo, err := repo_model.GetRepositoryByID(ctx, a.RepoID)
return repo, unit.TypeCode, err
}
return nil, -1, nil
}

0 comments on commit ad3fe09

Please sign in to comment.