1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Clean some functions about project issue (#27705)

1. remove unused function `MoveIssueAcrossProjectBoards`
2. extract the project board condition into a function
3. use db.NoCondition instead of -1. (BTW, the usage of db.NoCondition
is too confusing. Is there any way to avoid that?)
4. remove the unnecessary comment since the ctx refactor is completed.
5. Change `b.ID != 0` to `b.ID > 0`. It's more intuitive but I think
they're the same since board ID can't be negative.
This commit is contained in:
Nanguan Lin
2023-10-20 20:01:25 +08:00
committed by GitHub
parent cab7b7f59c
commit eb1478791f
3 changed files with 14 additions and 37 deletions

View File

@@ -51,7 +51,7 @@ func (issue *Issue) ProjectBoardID(ctx context.Context) int64 {
func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList, error) {
issueList := make(IssueList, 0, 10)
if b.ID != 0 {
if b.ID > 0 {
issues, err := Issues(ctx, &IssuesOptions{
ProjectBoardID: b.ID,
ProjectID: b.ProjectID,
@@ -65,7 +65,7 @@ func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList
if b.Default {
issues, err := Issues(ctx, &IssuesOptions{
ProjectBoardID: -1, // Issues without ProjectBoardID
ProjectBoardID: db.NoConditionID,
ProjectID: b.ProjectID,
SortType: "project-column-sorting",
})
@@ -150,30 +150,3 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U
ProjectID: newProjectID,
})
}
// MoveIssueAcrossProjectBoards move a card from one board to another
func MoveIssueAcrossProjectBoards(ctx context.Context, issue *Issue, board *project_model.Board) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
defer committer.Close()
sess := db.GetEngine(ctx)
var pis project_model.ProjectIssue
has, err := sess.Where("issue_id=?", issue.ID).Get(&pis)
if err != nil {
return err
}
if !has {
return fmt.Errorf("issue has to be added to a project first")
}
pis.ProjectBoardID = board.ID
if _, err := sess.ID(pis.ID).Cols("project_board_id").Update(&pis); err != nil {
return err
}
return committer.Commit()
}