forked from forgejo/forgejo
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
|
@ -97,7 +97,7 @@ func ListPullReviews(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
apiReviews, err := convert.ToPullReviewList(allReviews, ctx.User)
|
||||
apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
||||
return
|
||||
|
@ -148,7 +148,7 @@ func GetPullReview(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
apiReview, err := convert.ToPullReview(review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
@ -198,7 +198,7 @@ func GetPullReviewComments(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
apiComments, err := convert.ToPullReviewCommentList(review, ctx.User)
|
||||
apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewCommentList", err)
|
||||
return
|
||||
|
@ -328,12 +328,13 @@ func CreatePullReview(ctx *context.APIContext) {
|
|||
|
||||
// if CommitID is empty, set it as lastCommitID
|
||||
if opts.CommitID == "" {
|
||||
gitRepo, err := git.OpenRepository(pr.Issue.Repo.RepoPath())
|
||||
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo.RepoPath())
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "git.OpenRepository", err)
|
||||
return
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
defer closer.Close()
|
||||
|
||||
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
|
||||
if err != nil {
|
||||
|
@ -351,7 +352,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
|||
line = c.OldLineNum * -1
|
||||
}
|
||||
|
||||
if _, err := pull_service.CreateCodeComment(
|
||||
if _, err := pull_service.CreateCodeComment(ctx,
|
||||
ctx.User,
|
||||
ctx.Repo.GitRepo,
|
||||
pr.Issue,
|
||||
|
@ -368,14 +369,14 @@ func CreatePullReview(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// create review and associate all pending review comments
|
||||
review, _, err := pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
|
||||
review, _, err := pull_service.SubmitReview(ctx, ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
||||
return
|
||||
}
|
||||
|
||||
// convert response
|
||||
apiReview, err := convert.ToPullReview(review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
@ -456,14 +457,14 @@ func SubmitPullReview(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// create review and associate all pending review comments
|
||||
review, _, err = pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
|
||||
review, _, err = pull_service.SubmitReview(ctx, ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
|
||||
return
|
||||
}
|
||||
|
||||
// convert response
|
||||
apiReview, err := convert.ToPullReview(review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
@ -555,7 +556,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
|
|||
return nil, nil, true
|
||||
}
|
||||
|
||||
if err := review.LoadAttributes(); err != nil && !user_model.IsErrUserNotExist(err) {
|
||||
if err := review.LoadAttributes(ctx); err != nil && !user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "ReviewLoadAttributes", err)
|
||||
return nil, nil, true
|
||||
}
|
||||
|
@ -765,7 +766,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
|||
}
|
||||
|
||||
if isAdd {
|
||||
apiReviews, err := convert.ToPullReviewList(reviews, ctx.User)
|
||||
apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
|
||||
return
|
||||
|
@ -883,7 +884,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
|||
return
|
||||
}
|
||||
|
||||
_, err := pull_service.DismissReview(review.ID, msg, ctx.User, isDismiss)
|
||||
_, err := pull_service.DismissReview(ctx, review.ID, msg, ctx.User, isDismiss)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
|
||||
return
|
||||
|
@ -895,7 +896,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
|||
}
|
||||
|
||||
// convert response
|
||||
apiReview, err := convert.ToPullReview(review, ctx.User)
|
||||
apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue