Skip to content

Commit

Permalink
Fix unnecessary comment when moving issue on the same project column (#…
Browse files Browse the repository at this point in the history
…33496) (#33499)

Backport #33496 by @lunny

Fix #33482

Co-authored-by: Lunny Xiao <[email protected]>
  • Loading branch information
GiteaBot and lunny authored Feb 5, 2025
1 parent 200cb61 commit 2df7d08
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
10 changes: 6 additions & 4 deletions models/issues/issue_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ func (issue *Issue) projectID(ctx context.Context) int64 {
}

// ProjectColumnID return project column id if issue was assigned to one
func (issue *Issue) ProjectColumnID(ctx context.Context) int64 {
func (issue *Issue) ProjectColumnID(ctx context.Context) (int64, error) {
var ip project_model.ProjectIssue
has, err := db.GetEngine(ctx).Where("issue_id=?", issue.ID).Get(&ip)
if err != nil || !has {
return 0
if err != nil {
return 0, err
} else if !has {
return 0, nil
}
return ip.ProjectColumnID
return ip.ProjectColumnID, nil
}

// LoadIssuesFromColumn load issues assigned to this column
Expand Down
7 changes: 6 additions & 1 deletion modules/indexer/issues/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
projectID = issue.Project.ID
}

projectColumnID, err := issue.ProjectColumnID(ctx)
if err != nil {
return nil, false, err
}

return &internal.IndexerData{
ID: issue.ID,
RepoID: issue.RepoID,
Expand All @@ -106,7 +111,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
NoLabel: len(labels) == 0,
MilestoneID: issue.MilestoneID,
ProjectID: projectID,
ProjectColumnID: issue.ProjectColumnID(ctx),
ProjectColumnID: projectColumnID,
PosterID: issue.PosterID,
AssigneeID: issue.AssigneeID,
MentionIDs: mentionIDs,
Expand Down
31 changes: 19 additions & 12 deletions services/projects/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,29 @@ func MoveIssuesOnProjectColumn(ctx context.Context, doer *user_model.User, colum
continue
}

_, err = db.Exec(ctx, "UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", column.ID, sorting, issueID)
projectColumnID, err := curIssue.ProjectColumnID(ctx)
if err != nil {
return err
}

// add timeline to issue
if _, err := issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
Type: issues_model.CommentTypeProjectColumn,
Doer: doer,
Repo: curIssue.Repo,
Issue: curIssue,
ProjectID: column.ProjectID,
ProjectTitle: project.Title,
ProjectColumnID: column.ID,
ProjectColumnTitle: column.Title,
}); err != nil {
if projectColumnID != column.ID {
// add timeline to issue
if _, err := issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
Type: issues_model.CommentTypeProjectColumn,
Doer: doer,
Repo: curIssue.Repo,
Issue: curIssue,
ProjectID: column.ProjectID,
ProjectTitle: project.Title,
ProjectColumnID: column.ID,
ProjectColumnTitle: column.Title,
}); err != nil {
return err
}
}

_, err = db.Exec(ctx, "UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", column.ID, sorting, issueID)
if err != nil {
return err
}
}
Expand Down

0 comments on commit 2df7d08

Please sign in to comment.