mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Use for a repo action one database transaction (#19576)
... more context (part of #9307)
This commit is contained in:
@@ -591,7 +591,7 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e
|
||||
}
|
||||
|
||||
// ReadBy sets issue to be read by given user.
|
||||
func (issue *Issue) ReadBy(userID int64) error {
|
||||
func (issue *Issue) ReadBy(ctx context.Context, userID int64) error {
|
||||
if err := UpdateIssueUserByRead(userID, issue.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -635,7 +635,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
|
||||
// Check for open dependencies
|
||||
if issue.IsClosed && issue.Repo.IsDependenciesEnabledCtx(ctx) {
|
||||
// only check if dependencies are enabled and we're about to close an issue, otherwise reopening an issue would fail when there are unsatisfied dependencies
|
||||
noDeps, err := issueNoDependenciesLeft(e, issue)
|
||||
noDeps, err := IssueNoDependenciesLeft(ctx, issue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -693,13 +693,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
|
||||
}
|
||||
|
||||
// ChangeIssueStatus changes issue status to open or closed.
|
||||
func ChangeIssueStatus(issue *Issue, doer *user_model.User, isClosed bool) (*Comment, error) {
|
||||
ctx, committer, err := db.TxContext()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User, isClosed bool) (*Comment, error) {
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -707,16 +701,7 @@ func ChangeIssueStatus(issue *Issue, doer *user_model.User, isClosed bool) (*Com
|
||||
return nil, err
|
||||
}
|
||||
|
||||
comment, err := changeIssueStatus(ctx, issue, doer, isClosed, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = committer.Commit(); err != nil {
|
||||
return nil, fmt.Errorf("Commit: %v", err)
|
||||
}
|
||||
|
||||
return comment, nil
|
||||
return changeIssueStatus(ctx, issue, doer, isClosed, false)
|
||||
}
|
||||
|
||||
// ChangeIssueTitle changes the title of this issue, as the given user.
|
||||
@@ -787,16 +772,11 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err
|
||||
}
|
||||
|
||||
// AddDeletePRBranchComment adds delete branch comment for pull request issue
|
||||
func AddDeletePRBranchComment(doer *user_model.User, repo *repo_model.Repository, issueID int64, branchName string) error {
|
||||
issue, err := getIssueByID(db.GetEngine(db.DefaultContext), issueID)
|
||||
func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issueID int64, branchName string) error {
|
||||
issue, err := getIssueByID(db.GetEngine(ctx), issueID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx, committer, err := db.TxContext()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
opts := &CreateCommentOptions{
|
||||
Type: CommentTypeDeleteBranch,
|
||||
Doer: doer,
|
||||
@@ -804,11 +784,8 @@ func AddDeletePRBranchComment(doer *user_model.User, repo *repo_model.Repository
|
||||
Issue: issue,
|
||||
OldRef: branchName,
|
||||
}
|
||||
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
_, err = CreateCommentCtx(ctx, opts)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateIssueAttachments update attachments by UUIDs for the issue
|
||||
|
Reference in New Issue
Block a user