mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-19 00:10:15 +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:
parent
fefdb7ffd1
commit
044c754ea5
148 changed files with 1411 additions and 1564 deletions
|
@ -24,24 +24,24 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
)
|
||||
|
||||
func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) {
|
||||
func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) {
|
||||
var created bool
|
||||
// Only actual create when publish.
|
||||
if !rel.IsDraft {
|
||||
if !gitRepo.IsTagExist(rel.TagName) {
|
||||
if err := rel.LoadAttributes(); err != nil {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
protectedTags, err := git_model.GetProtectedTags(rel.Repo.ID)
|
||||
protectedTags, err := git_model.GetProtectedTags(ctx, rel.Repo.ID)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("GetProtectedTags: %w", err)
|
||||
}
|
||||
|
||||
// Trim '--' prefix to prevent command line argument vulnerability.
|
||||
rel.TagName = strings.TrimPrefix(rel.TagName, "--")
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID)
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(ctx, protectedTags, rel.TagName, rel.PublisherID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -81,13 +81,13 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo
|
|||
commits.CompareURL = rel.Repo.ComposeCompareURL(git.EmptySHA, commit.ID.String())
|
||||
|
||||
notification.NotifyPushCommits(
|
||||
rel.Publisher, rel.Repo,
|
||||
ctx, rel.Publisher, rel.Repo,
|
||||
&repository.PushUpdateOptions{
|
||||
RefFullName: git.TagPrefix + rel.TagName,
|
||||
OldCommitID: git.EmptySHA,
|
||||
NewCommitID: commit.ID.String(),
|
||||
}, commits)
|
||||
notification.NotifyCreateRef(rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String())
|
||||
notification.NotifyCreateRef(ctx, rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String())
|
||||
rel.CreatedUnix = timeutil.TimeStampNow()
|
||||
}
|
||||
commit, err := gitRepo.GetTagCommit(rel.TagName)
|
||||
|
@ -102,7 +102,7 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo
|
|||
}
|
||||
|
||||
if rel.PublisherID <= 0 {
|
||||
u, err := user_model.GetUserByEmail(commit.Author.Email)
|
||||
u, err := user_model.GetUserByEmailContext(ctx, commit.Author.Email)
|
||||
if err == nil {
|
||||
rel.PublisherID = u.ID
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
|
|||
}
|
||||
}
|
||||
|
||||
if _, err = createTag(gitRepo, rel, msg); err != nil {
|
||||
if _, err = createTag(gitRepo.Ctx, gitRepo, rel, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
|
|||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notification.NotifyNewRelease(rel)
|
||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -173,7 +173,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
|||
IsTag: true,
|
||||
}
|
||||
|
||||
if _, err = createTag(gitRepo, rel, msg); err != nil {
|
||||
if _, err = createTag(ctx, gitRepo, rel, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
|||
if rel.ID == 0 {
|
||||
return errors.New("UpdateRelease only accepts an exist release")
|
||||
}
|
||||
isCreated, err := createTag(gitRepo, rel, "")
|
||||
isCreated, err := createTag(gitRepo.Ctx, gitRepo, rel, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -272,12 +272,12 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
|||
}
|
||||
|
||||
if !isCreated {
|
||||
notification.NotifyUpdateRelease(doer, rel)
|
||||
notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
return
|
||||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notification.NotifyNewRelease(rel)
|
||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -296,11 +296,11 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
|||
}
|
||||
|
||||
if delTag {
|
||||
protectedTags, err := git_model.GetProtectedTags(rel.RepoID)
|
||||
protectedTags, err := git_model.GetProtectedTags(ctx, rel.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetProtectedTags: %w", err)
|
||||
}
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID)
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(ctx, protectedTags, rel.TagName, rel.PublisherID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -318,15 +318,15 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
|||
}
|
||||
|
||||
notification.NotifyPushCommits(
|
||||
doer, repo,
|
||||
ctx, doer, repo,
|
||||
&repository.PushUpdateOptions{
|
||||
RefFullName: git.TagPrefix + rel.TagName,
|
||||
OldCommitID: rel.Sha1,
|
||||
NewCommitID: git.EmptySHA,
|
||||
}, repository.NewPushCommits())
|
||||
notification.NotifyDeleteRef(doer, repo, "tag", git.TagPrefix+rel.TagName)
|
||||
notification.NotifyDeleteRef(ctx, doer, repo, "tag", git.TagPrefix+rel.TagName)
|
||||
|
||||
if err := repo_model.DeleteReleaseByID(id); err != nil {
|
||||
if err := repo_model.DeleteReleaseByID(ctx, id); err != nil {
|
||||
return fmt.Errorf("DeleteReleaseByID: %w", err)
|
||||
}
|
||||
} else {
|
||||
|
@ -338,11 +338,11 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
|||
}
|
||||
|
||||
rel.Repo = repo
|
||||
if err = rel.LoadAttributes(); err != nil {
|
||||
if err = rel.LoadAttributes(ctx); err != nil {
|
||||
return fmt.Errorf("LoadAttributes: %w", err)
|
||||
}
|
||||
|
||||
if err := repo_model.DeleteAttachmentsByRelease(rel.ID); err != nil {
|
||||
if err := repo_model.DeleteAttachmentsByRelease(ctx, rel.ID); err != nil {
|
||||
return fmt.Errorf("DeleteAttachments: %w", err)
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
|||
}
|
||||
}
|
||||
|
||||
notification.NotifyDeleteRelease(doer, rel)
|
||||
notification.NotifyDeleteRelease(ctx, doer, rel)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue