Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add issue comment when moving issues from one column to another of the project #29311

Merged
merged 17 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Follow yp05327's suggestion
  • Loading branch information
lunny committed May 28, 2024
commit b1a2f40e1fcdee1a651f1db3e912986e2081342f
1 change: 1 addition & 0 deletions models/migrations/v1_22/v287.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
lunny marked this conversation as resolved.
Show resolved Hide resolved
// SPDX-License-Identifier: MIT

package v1_22 //nolint

import (
Expand Down
24 changes: 0 additions & 24 deletions models/project/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,6 @@ func (p *Project) NumOpenIssues(ctx context.Context) int {
return int(c)
}

// MoveIssuesOnProjectColumn moves or keeps issues in a column and sorts them inside that column
func MoveIssuesOnProjectColumn(ctx context.Context, column *Column, sortedIssueIDs map[int64]int64) error {
return db.WithTx(ctx, func(ctx context.Context) error {
sess := db.GetEngine(ctx)
issueIDs := util.ValuesOfMap(sortedIssueIDs)

count, err := sess.Table(new(ProjectIssue)).Where("project_id=?", column.ProjectID).In("issue_id", issueIDs).Count()
if err != nil {
return err
}
if int(count) != len(sortedIssueIDs) {
return fmt.Errorf("all issues have to be added to a project first")
}

for sorting, issueID := range sortedIssueIDs {
_, err = sess.Exec("UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", column.ID, sorting, issueID)
if err != nil {
return err
}
}
return nil
})
}

func (c *Column) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Column) error {
if c.ProjectID != newColumn.ProjectID {
return fmt.Errorf("columns have to be in the same project")
Expand Down
13 changes: 6 additions & 7 deletions services/projects/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@ func MoveIssuesOnProjectColumn(ctx context.Context, doer *user_model.User, colum
return err
}

issuesMap := make(map[int64]*issues_model.Issue, len(issues))
for _, issue := range issues {
issuesMap[issue.ID] = issue
}

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

var curIssue *issues_model.Issue
for _, issue := range issues {
if issue.ID == issueID {
curIssue = issue
break
}
}
curIssue := issuesMap[issueID]
lunny marked this conversation as resolved.
Show resolved Hide resolved

// add timeline to issue
if _, err := issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
Expand Down