-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add issue comment when moving issues from one column to another of the project #29311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lunny
merged 17 commits into
go-gitea:main
from
lunny:lunny/add_comment_move_issue_column
Aug 9, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5f5212c
Add issue comment when moving issues from one column to another of th…
lunny bb8fac8
Fix bug
lunny 8bd1218
Fix possible xss bug
lunny d7f48be
Use Escape
lunny e4798b9
Use new template HTML method
lunny 67dfeb2
Ignore the fields on database when it's empty
lunny 8b4cc81
Apply suggestions from code review
wxiaoguang 45ac27e
Update templates/repo/issue/view_content/comments.tmpl
wxiaoguang 58b4698
Fix metadata name
lunny 2118c6b
Update models/migrations/v1_23/v297.go
lunny c43f7ed
Fix lint
lunny b1a2f40
Follow yp05327's suggestion
lunny 45905a8
Merge branch 'main' into lunny/add_comment_move_issue_column
lunny cdcf2c3
Merge branch 'main' into lunny/add_comment_move_issue_column
lunny 6581ed1
Merge branch 'main' into lunny/add_comment_move_issue_column
lunny e1d45e1
Fix possible panic
lunny 4f7fe44
Merge branch 'main' into lunny/add_comment_move_issue_column
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.