-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add issue comment when moving issues from one column to another of th…
…e 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 <[email protected]> Co-authored-by: yp05327 <[email protected]>
- Loading branch information
1 parent
aa1055f
commit 791d7fc
Showing
11 changed files
with
181 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters