Skip to content

Commit 8fe5478

Browse files
committed
Fix test
1 parent 5fd5655 commit 8fe5478

File tree

7 files changed

+35
-550
lines changed

7 files changed

+35
-550
lines changed

models/issue_project.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"code.gitea.io/gitea/models/db"
1212
project_model "code.gitea.io/gitea/models/project"
13+
user_model "code.gitea.io/gitea/models/user"
1314
)
1415

1516
// LoadProject load the project the issue was assigned to
@@ -106,7 +107,7 @@ func LoadIssuesFromBoardList(bs project_model.BoardList) (IssueList, error) {
106107
}
107108

108109
// ChangeProjectAssign changes the project associated with an issue
109-
func ChangeProjectAssign(issue *Issue, doer *User, newProjectID int64) error {
110+
func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64) error {
110111
ctx, committer, err := db.TxContext()
111112
if err != nil {
112113
return err
@@ -120,15 +121,15 @@ func ChangeProjectAssign(issue *Issue, doer *User, newProjectID int64) error {
120121
return committer.Commit()
121122
}
122123

123-
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *User, newProjectID int64) error {
124+
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
124125
e := db.GetEngine(ctx)
125126
oldProjectID := issue.projectID(e)
126127

127128
if _, err := e.Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
128129
return err
129130
}
130131

131-
if err := issue.loadRepo(e); err != nil {
132+
if err := issue.loadRepo(ctx); err != nil {
132133
return err
133134
}
134135

models/project/issue.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package project
66

77
import (
8+
"context"
9+
"fmt"
10+
811
"code.gitea.io/gitea/models/db"
912
)
1013

@@ -71,12 +74,32 @@ func (p *Project) NumOpenIssues() int {
7174
return int(c)
7275
}
7376

74-
// ____ _ _ ____ _
75-
// | _ \ _ __ ___ (_) ___ ___| |_| __ ) ___ __ _ _ __ __| |
76-
// | |_) | '__/ _ \| |/ _ \/ __| __| _ \ / _ \ / _` | '__/ _` |
77-
// | __/| | | (_) | | __/ (__| |_| |_) | (_) | (_| | | | (_| |
78-
// |_| |_| \___// |\___|\___|\__|____/ \___/ \__,_|_| \__,_|
79-
// |__/
77+
// MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column
78+
func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) error {
79+
return db.WithTx(func(ctx context.Context) error {
80+
sess := db.GetEngine(ctx)
81+
82+
issueIDs := make([]int64, 0, len(sortedIssueIDs))
83+
for _, issueID := range sortedIssueIDs {
84+
issueIDs = append(issueIDs, issueID)
85+
}
86+
count, err := sess.Table(new(ProjectIssue)).Where("project_id=?", board.ProjectID).In("issue_id", issueIDs).Count()
87+
if err != nil {
88+
return err
89+
}
90+
if int(count) != len(sortedIssueIDs) {
91+
return fmt.Errorf("all issues have to be added to a project first")
92+
}
93+
94+
for sorting, issueID := range sortedIssueIDs {
95+
_, err = sess.Exec("UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", board.ID, sorting, issueID)
96+
if err != nil {
97+
return err
98+
}
99+
}
100+
return nil
101+
})
102+
}
80103

81104
func (pb *Board) removeIssues(e db.Engine) error {
82105
_, err := e.Exec("UPDATE `project_issue` SET project_board_id = 0 WHERE project_board_id = ? ", pb.ID)

models/project/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99
"testing"
1010

11+
_ "code.gitea.io/gitea/models/repo"
1112
"code.gitea.io/gitea/models/unittest"
1213
)
1314

0 commit comments

Comments
 (0)