Delete `issue_service.CreateComment` (#26298)
I noticed that `issue_service.CreateComment` adds transaction operations on `issues_model.CreateComment`, we can merge the two functions and we can avoid calling each other's methods in the `services` layer. Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
2de0752be7
commit
6151e69d95
|
@ -777,6 +777,12 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) {
|
||||||
|
|
||||||
// CreateComment creates comment with context
|
// CreateComment creates comment with context
|
||||||
func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) {
|
func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) {
|
||||||
|
ctx, committer, err := db.TxContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer committer.Close()
|
||||||
|
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
var LabelID int64
|
var LabelID int64
|
||||||
if opts.Label != nil {
|
if opts.Label != nil {
|
||||||
|
@ -832,7 +838,9 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment,
|
||||||
if err = comment.AddCrossReferences(ctx, opts.Doer, false); err != nil {
|
if err = comment.AddCrossReferences(ctx, opts.Doer, false); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err = committer.Commit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return comment, nil
|
return comment, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,26 +15,6 @@ import (
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateComment creates comment of issue or commit.
|
|
||||||
func CreateComment(ctx context.Context, opts *issues_model.CreateCommentOptions) (comment *issues_model.Comment, err error) {
|
|
||||||
ctx, committer, err := db.TxContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer committer.Close()
|
|
||||||
|
|
||||||
comment, err = issues_model.CreateComment(ctx, opts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = committer.Commit(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return comment, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateRefComment creates a commit reference comment to issue.
|
// CreateRefComment creates a commit reference comment to issue.
|
||||||
func CreateRefComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content, commitSHA string) error {
|
func CreateRefComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content, commitSHA string) error {
|
||||||
if len(commitSHA) == 0 {
|
if len(commitSHA) == 0 {
|
||||||
|
@ -53,7 +33,7 @@ func CreateRefComment(ctx context.Context, doer *user_model.User, repo *repo_mod
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = CreateComment(ctx, &issues_model.CreateCommentOptions{
|
_, err = issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
||||||
Type: issues_model.CommentTypeCommitRef,
|
Type: issues_model.CommentTypeCommitRef,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
@ -66,7 +46,7 @@ func CreateRefComment(ctx context.Context, doer *user_model.User, repo *repo_mod
|
||||||
|
|
||||||
// CreateIssueComment creates a plain issue comment.
|
// CreateIssueComment creates a plain issue comment.
|
||||||
func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content string, attachments []string) (*issues_model.Comment, error) {
|
func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content string, attachments []string) (*issues_model.Comment, error) {
|
||||||
comment, err := CreateComment(ctx, &issues_model.CreateCommentOptions{
|
comment, err := issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
||||||
Type: issues_model.CommentTypeComment,
|
Type: issues_model.CommentTypeComment,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
issue_service "code.gitea.io/gitea/services/issue"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// getCommitIDsFromRepo get commit IDs from repo in between oldCommitID and newCommitID
|
// getCommitIDsFromRepo get commit IDs from repo in between oldCommitID and newCommitID
|
||||||
|
@ -90,7 +89,7 @@ func CreatePushPullComment(ctx context.Context, pusher *user_model.User, pr *iss
|
||||||
|
|
||||||
ops.Content = string(dataJSON)
|
ops.Content = string(dataJSON)
|
||||||
|
|
||||||
comment, err = issue_service.CreateComment(ctx, ops)
|
comment, err = issues_model.CreateComment(ctx, ops)
|
||||||
|
|
||||||
return comment, err
|
return comment, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issu
|
||||||
Content: string(dataJSON),
|
Content: string(dataJSON),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = issue_service.CreateComment(ctx, ops)
|
_, _ = issues_model.CreateComment(ctx, ops)
|
||||||
|
|
||||||
if !pr.IsWorkInProgress() {
|
if !pr.IsWorkInProgress() {
|
||||||
if err := issues_model.PullRequestCodeOwnersReview(ctx, pull, pr); err != nil {
|
if err := issues_model.PullRequestCodeOwnersReview(ctx, pull, pr); err != nil {
|
||||||
|
@ -231,7 +231,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||||
OldRef: oldBranch,
|
OldRef: oldBranch,
|
||||||
NewRef: targetBranch,
|
NewRef: targetBranch,
|
||||||
}
|
}
|
||||||
if _, err = issue_service.CreateComment(ctx, options); err != nil {
|
if _, err = issues_model.CreateComment(ctx, options); err != nil {
|
||||||
return fmt.Errorf("CreateChangeTargetBranchComment: %w", err)
|
return fmt.Errorf("CreateChangeTargetBranchComment: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
issue_service "code.gitea.io/gitea/services/issue"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`)
|
var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`)
|
||||||
|
@ -248,7 +247,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return issue_service.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
return issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
||||||
Type: issues_model.CommentTypeCode,
|
Type: issues_model.CommentTypeCode,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
@ -340,7 +339,7 @@ func DismissApprovalReviews(ctx context.Context, doer *user_model.User, pull *is
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := issue_service.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
comment, err := issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Content: "New commits pushed, approval review dismissed automatically according to repository settings",
|
Content: "New commits pushed, approval review dismissed automatically according to repository settings",
|
||||||
Type: issues_model.CommentTypeDismissReview,
|
Type: issues_model.CommentTypeDismissReview,
|
||||||
|
@ -411,7 +410,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err = issue_service.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
comment, err = issues_model.CreateComment(ctx, &issues_model.CreateCommentOptions{
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Content: message,
|
Content: message,
|
||||||
Type: issues_model.CommentTypeDismissReview,
|
Type: issues_model.CommentTypeDismissReview,
|
||||||
|
|
Loading…
Reference in New Issue