mirror of https://github.com/go-gitea/gitea
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>pull/31761/head^2
parent
aa1055fe16
commit
791d7fc76a
@ -0,0 +1,23 @@ |
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_23 //nolint
|
||||||
|
|
||||||
|
import ( |
||||||
|
"xorm.io/xorm" |
||||||
|
) |
||||||
|
|
||||||
|
// CommentMetaData stores metadata for a comment, these data will not be changed once inserted into database
|
||||||
|
type CommentMetaData struct { |
||||||
|
ProjectColumnID int64 `json:"project_column_id"` |
||||||
|
ProjectColumnTitle string `json:"project_column_title"` |
||||||
|
ProjectTitle string `json:"project_title"` |
||||||
|
} |
||||||
|
|
||||||
|
func AddCommentMetaDataColumn(x *xorm.Engine) error { |
||||||
|
type Comment struct { |
||||||
|
CommentMetaData *CommentMetaData `xorm:"JSON TEXT"` // put all non-index metadata in a single field
|
||||||
|
} |
||||||
|
|
||||||
|
return x.Sync(new(Comment)) |
||||||
|
} |
@ -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 |
||||||
|
}) |
||||||
|
} |
Loading…
Reference in new issue