Skip to content

Commit

Permalink
Follow yp05327's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed May 28, 2024
1 parent c43f7ed commit b1a2f40
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
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.
// 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]

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

0 comments on commit b1a2f40

Please sign in to comment.