diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-08-09 09:29:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-09 01:29:02 +0000 |
commit | 791d7fc76aa41370860126e861cf14d98efe710e (patch) | |
tree | 066bde9247eaa6b91878c818901c378b65f5ecb1 /services/projects | |
parent | aa1055fe16e2a11b4ab9503854be96e776231d93 (diff) | |
download | gitea-791d7fc76aa41370860126e861cf14d98efe710e.tar.gz gitea-791d7fc76aa41370860126e861cf14d98efe710e.zip |
Add issue comment when moving issues from one column to another of the project (#29311)
Fix #27278
Replace #27816
This PR adds a meta-comment for an issue when dragging an issue from one
column to another of a project.
<img width="600" alt="image"
src="https://github.com/go-gitea/gitea/assets/81045/5fc1d954-430e-4db0-aaee-a00006fa91f5">
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: yp05327 <576951401@qq.com>
Diffstat (limited to 'services/projects')
-rw-r--r-- | services/projects/issue.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/services/projects/issue.go b/services/projects/issue.go new file mode 100644 index 0000000000..db1621a39f --- /dev/null +++ b/services/projects/issue.go @@ -0,0 +1,79 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package project + +import ( + "context" + "fmt" + + "code.gitea.io/gitea/models/db" + issues_model "code.gitea.io/gitea/models/issues" + project_model "code.gitea.io/gitea/models/project" + user_model "code.gitea.io/gitea/models/user" +) + +// MoveIssuesOnProjectColumn moves or keeps issues in a column and sorts them inside that column +func MoveIssuesOnProjectColumn(ctx context.Context, doer *user_model.User, column *project_model.Column, sortedIssueIDs map[int64]int64) error { + return db.WithTx(ctx, func(ctx context.Context) error { + issueIDs := make([]int64, 0, len(sortedIssueIDs)) + for _, issueID := range sortedIssueIDs { + issueIDs = append(issueIDs, issueID) + } + count, err := db.GetEngine(ctx). + Where("project_id=?", column.ProjectID). + In("issue_id", issueIDs). + Count(new(project_model.ProjectIssue)) + if err != nil { + return err + } + if int(count) != len(sortedIssueIDs) { + return fmt.Errorf("all issues have to be added to a project first") + } + + issues, err := issues_model.GetIssuesByIDs(ctx, issueIDs) + if err != nil { + return err + } + if _, err := issues.LoadRepositories(ctx); err != nil { + return err + } + + project, err := project_model.GetProjectByID(ctx, column.ProjectID) + if err != nil { + return err + } + + issuesMap := make(map[int64]*issues_model.Issue, len(issues)) + for _, issue := range issues { + issuesMap[issue.ID] = issue + } + + for sorting, issueID := range sortedIssueIDs { + curIssue := issuesMap[issueID] + if curIssue == nil { + continue + } + + _, err = db.Exec(ctx, "UPDATE `project_issue` SET project_board_id=?, sorting=? WHERE issue_id=?", column.ID, sorting, issueID) + 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 { + return err + } + } + return nil + }) +} |