1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Add context.Context to more methods (#21546)

This PR adds a context parameter to a bunch of methods. Some helper
`xxxCtx()` methods got replaced with the normal name now.

Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
KN4CK3R
2022-11-19 09:12:33 +01:00
committed by GitHub
parent fefdb7ffd1
commit 044c754ea5
148 changed files with 1411 additions and 1564 deletions

View File

@@ -96,7 +96,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption
return nil, err
}
notification.NotifyCreateRepository(doer, u, repo)
notification.NotifyCreateRepository(db.DefaultContext, doer, u, repo)
return repo, nil
}

View File

@@ -11,6 +11,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -141,8 +142,8 @@ func RenameBranch(repo *repo_model.Repository, doer *user_model.User, gitRepo *g
return "", err
}
notification.NotifyDeleteRef(doer, repo, "branch", git.BranchPrefix+from)
notification.NotifyCreateRef(doer, repo, "branch", git.BranchPrefix+to, refID)
notification.NotifyDeleteRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+from)
notification.NotifyCreateRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+to, refID)
return "", nil
}

View File

@@ -177,7 +177,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
}
}
notification.NotifyForkRepository(doer, opts.BaseRepo, repo)
notification.NotifyForkRepository(ctx, doer, opts.BaseRepo, repo)
return repo, nil
}

View File

@@ -117,7 +117,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
tagName := opts.TagName()
if opts.IsDelRef() {
notification.NotifyPushCommits(
pusher, repo,
db.DefaultContext, pusher, repo,
&repo_module.PushUpdateOptions{
RefFullName: git.TagPrefix + tagName,
OldCommitID: opts.OldCommitID,
@@ -125,7 +125,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}, repo_module.NewPushCommits())
delTags = append(delTags, tagName)
notification.NotifyDeleteRef(pusher, repo, "tag", opts.RefFullName)
notification.NotifyDeleteRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName)
} else { // is new tag
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
if err != nil {
@@ -137,7 +137,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID)
notification.NotifyPushCommits(
pusher, repo,
db.DefaultContext, pusher, repo,
&repo_module.PushUpdateOptions{
RefFullName: git.TagPrefix + tagName,
OldCommitID: git.EmptySHA,
@@ -145,7 +145,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}, commits)
addTags = append(addTags, tagName)
notification.NotifyCreateRef(pusher, repo, "tag", opts.RefFullName, opts.NewCommitID)
notification.NotifyCreateRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID)
}
} else if opts.IsBranch() { // If is branch reference
if pusher == nil || pusher.ID != opts.PusherID {
@@ -190,7 +190,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
if err != nil {
return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err)
}
notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName, opts.NewCommitID)
notification.NotifyCreateRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID)
} else {
l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
if err != nil {
@@ -250,7 +250,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum]
}
notification.NotifyPushCommits(pusher, repo, opts, commits)
notification.NotifyPushCommits(db.DefaultContext, pusher, repo, opts, commits)
if err = git_model.RemoveDeletedBranchByName(repo.ID, branch); err != nil {
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err)
@@ -261,7 +261,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err)
}
} else {
notification.NotifyDeleteRef(pusher, repo, "branch", opts.RefFullName)
notification.NotifyDeleteRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName)
if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil {
// close all related pulls
log.Error("close related pull request failed: %v", err)

View File

@@ -32,7 +32,7 @@ func CreateRepository(doer, owner *user_model.User, opts repo_module.CreateRepoO
return nil, err
}
notification.NotifyCreateRepository(doer, owner, repo)
notification.NotifyCreateRepository(db.DefaultContext, doer, owner, repo)
return repo, nil
}
@@ -45,7 +45,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod
if notify {
// If the repo itself has webhooks, we need to trigger them before deleting it...
notification.NotifyDeleteRepository(doer, repo)
notification.NotifyDeleteRepository(ctx, doer, repo)
}
if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {

View File

@@ -101,7 +101,7 @@ func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.R
return nil, err
}
notification.NotifyCreateRepository(doer, owner, generateRepo)
notification.NotifyCreateRepository(db.DefaultContext, doer, owner, generateRepo)
return generateRepo, nil
}

View File

@@ -55,7 +55,7 @@ func TransferOwnership(doer, newOwner *user_model.User, repo *repo_model.Reposit
}
}
notification.NotifyTransferRepository(doer, repo, oldOwner.Name)
notification.NotifyTransferRepository(db.DefaultContext, doer, repo, oldOwner.Name)
return nil
}
@@ -78,7 +78,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *repo_model.Repository, ne
repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
repo.Name = newRepoName
notification.NotifyRenameRepository(doer, repo, oldRepoName)
notification.NotifyRenameRepository(db.DefaultContext, doer, repo, oldRepoName)
return nil
}
@@ -127,7 +127,7 @@ func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *repo_model.R
}
// notify users who are able to accept / reject transfer
notification.NotifyRepoPendingTransfer(doer, newOwner, repo)
notification.NotifyRepoPendingTransfer(db.DefaultContext, doer, newOwner, repo)
return nil
}