mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-14 05:52:43 +00:00
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
4563148a61
commit
5cb0c9aa0d
193 changed files with 1264 additions and 1154 deletions
|
@ -156,7 +156,7 @@ func ProcRecive(ctx *context.PrivateContext, opts *private.HookOptions) []privat
|
|||
Flow: models.PullRequestFlowAGit,
|
||||
}
|
||||
|
||||
if err := pull_service.NewPullRequest(repo, prIssue, []int64{}, []string{}, pr, []int64{}); err != nil {
|
||||
if err := pull_service.NewPullRequest(ctx, repo, prIssue, []int64{}, []string{}, pr, []int64{}); err != nil {
|
||||
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
|
||||
return nil
|
||||
|
@ -205,7 +205,7 @@ func ProcRecive(ctx *context.PrivateContext, opts *private.HookOptions) []privat
|
|||
}
|
||||
|
||||
if !forcePush {
|
||||
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+opts.NewCommitIDs[i]).RunInDirWithEnv(repo.RepoPath(), os.Environ())
|
||||
output, err := git.NewCommandContext(ctx, "rev-list", "--max-count=1", oldCommitID, "^"+opts.NewCommitIDs[i]).RunInDirWithEnv(repo.RepoPath(), os.Environ())
|
||||
if err != nil {
|
||||
log.Error("Unable to detect force push between: %s and %s in %-v Error: %v", oldCommitID, opts.NewCommitIDs[i], repo, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
|
@ -224,7 +224,7 @@ func ProcRecive(ctx *context.PrivateContext, opts *private.HookOptions) []privat
|
|||
}
|
||||
|
||||
pr.HeadCommitID = opts.NewCommitIDs[i]
|
||||
if err = pull_service.UpdateRef(pr); err != nil {
|
||||
if err = pull_service.UpdateRef(ctx, pr); err != nil {
|
||||
log.Error("Failed to update pull ref. Error: %v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
|
||||
"Err": fmt.Sprintf("Failed to update pull ref. Error: %v", err),
|
||||
|
@ -249,7 +249,7 @@ func ProcRecive(ctx *context.PrivateContext, opts *private.HookOptions) []privat
|
|||
})
|
||||
return nil
|
||||
}
|
||||
comment, err := models.CreatePushPullComment(pusher, pr, oldCommitID, opts.NewCommitIDs[i])
|
||||
comment, err := models.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
|
||||
if err == nil && comment != nil {
|
||||
notification.NotifyPullRequestPushCommits(pusher, pr, comment)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue