summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-01-19 23:26:57 +0000
committerGitHub <noreply@github.com>2022-01-19 23:26:57 +0000
commit5cb0c9aa0d7eed087055b1efca79628957207d36 (patch)
treed117a514e1f17e5f6bfcda1be273f6a971112663 /routers/api/v1/repo
parent4563148a61ba892e8f2bb66342f00a950bcd5315 (diff)
downloadgitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz
gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip
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>
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/blob.go2
-rw-r--r--routers/api/v1/repo/branch.go8
-rw-r--r--routers/api/v1/repo/commits.go31
-rw-r--r--routers/api/v1/repo/file.go8
-rw-r--r--routers/api/v1/repo/notes.go4
-rw-r--r--routers/api/v1/repo/pull.go33
-rw-r--r--routers/api/v1/repo/pull_review.go29
-rw-r--r--routers/api/v1/repo/release.go2
-rw-r--r--routers/api/v1/repo/release_tags.go2
-rw-r--r--routers/api/v1/repo/repo.go4
-rw-r--r--routers/api/v1/repo/status.go2
-rw-r--r--routers/api/v1/repo/tag.go4
-rw-r--r--routers/api/v1/repo/tree.go2
-rw-r--r--routers/api/v1/repo/wiki.go8
14 files changed, 65 insertions, 74 deletions
diff --git a/routers/api/v1/repo/blob.go b/routers/api/v1/repo/blob.go
index e3ce0e1916..19d893a68b 100644
--- a/routers/api/v1/repo/blob.go
+++ b/routers/api/v1/repo/blob.go
@@ -45,7 +45,7 @@ func GetBlob(ctx *context.APIContext) {
ctx.Error(http.StatusBadRequest, "", "sha not provided")
return
}
- if blob, err := files_service.GetBlobBySHA(ctx.Repo.Repository, sha); err != nil {
+ if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, sha); err != nil {
ctx.Error(http.StatusBadRequest, "", err)
} else {
ctx.JSON(http.StatusOK, blob)
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index 56266b406a..c5480bf2c5 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -53,7 +53,7 @@ func GetBranch(ctx *context.APIContext) {
branchName := ctx.Params("*")
- branch, err := repo_service.GetBranch(ctx.Repo.Repository, branchName)
+ branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
if err != nil {
if git.IsErrBranchNotExist(err) {
ctx.NotFound(err)
@@ -176,7 +176,7 @@ func CreateBranch(ctx *context.APIContext) {
opt.OldBranchName = ctx.Repo.Repository.DefaultBranch
}
- err := repo_service.CreateNewBranch(ctx.User, ctx.Repo.Repository, opt.OldBranchName, opt.BranchName)
+ err := repo_service.CreateNewBranch(ctx, ctx.User, ctx.Repo.Repository, opt.OldBranchName, opt.BranchName)
if err != nil {
if models.IsErrBranchDoesNotExist(err) {
@@ -198,7 +198,7 @@ func CreateBranch(ctx *context.APIContext) {
return
}
- branch, err := repo_service.GetBranch(ctx.Repo.Repository, opt.BranchName)
+ branch, err := ctx.Repo.GitRepo.GetBranch(opt.BranchName)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetBranch", err)
return
@@ -257,7 +257,7 @@ func ListBranches(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
skip, _ := listOptions.GetStartEnd()
- branches, totalNumOfBranches, err := repo_service.GetBranches(ctx.Repo.Repository, skip, listOptions.PageSize)
+ branches, totalNumOfBranches, err := ctx.Repo.GitRepo.GetBranches(skip, listOptions.PageSize)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetBranches", err)
return
diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go
index a2b4298602..b6c47e0685 100644
--- a/routers/api/v1/repo/commits.go
+++ b/routers/api/v1/repo/commits.go
@@ -62,13 +62,7 @@ func GetSingleCommit(ctx *context.APIContext) {
}
func getCommit(ctx *context.APIContext, identifier string) {
- gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
- return
- }
- defer gitRepo.Close()
- commit, err := gitRepo.GetCommit(identifier)
+ commit, err := ctx.Repo.GitRepo.GetCommit(identifier)
if err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound(identifier)
@@ -78,7 +72,7 @@ func getCommit(ctx *context.APIContext, identifier string) {
return
}
- json, err := convert.ToCommit(ctx.Repo.Repository, commit, nil)
+ json, err := convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil)
if err != nil {
ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
@@ -136,13 +130,6 @@ func GetAllCommits(ctx *context.APIContext) {
return
}
- gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
- if err != nil {
- ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
- return
- }
- defer gitRepo.Close()
-
listOptions := utils.GetListOptions(ctx)
if listOptions.Page <= 0 {
listOptions.Page = 1
@@ -158,26 +145,27 @@ func GetAllCommits(ctx *context.APIContext) {
var (
commitsCountTotal int64
commits []*git.Commit
+ err error
)
if len(path) == 0 {
var baseCommit *git.Commit
if len(sha) == 0 {
// no sha supplied - use default branch
- head, err := gitRepo.GetHEADBranch()
+ head, err := ctx.Repo.GitRepo.GetHEADBranch()
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetHEADBranch", err)
return
}
- baseCommit, err = gitRepo.GetBranchCommit(head.Name)
+ baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(head.Name)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
}
} else {
// get commit specified by sha
- baseCommit, err = gitRepo.GetCommit(sha)
+ baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
return
@@ -202,7 +190,7 @@ func GetAllCommits(ctx *context.APIContext) {
sha = ctx.Repo.Repository.DefaultBranch
}
- commitsCountTotal, err = gitRepo.FileCommitsCount(sha, path)
+ commitsCountTotal, err = ctx.Repo.GitRepo.FileCommitsCount(sha, path)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FileCommitsCount", err)
return
@@ -211,7 +199,7 @@ func GetAllCommits(ctx *context.APIContext) {
return
}
- commits, err = gitRepo.CommitsByFileAndRange(sha, path, listOptions.Page)
+ commits, err = ctx.Repo.GitRepo.CommitsByFileAndRange(sha, path, listOptions.Page)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CommitsByFileAndRange", err)
return
@@ -225,7 +213,7 @@ func GetAllCommits(ctx *context.APIContext) {
apiCommits := make([]*api.Commit, len(commits))
for i, commit := range commits {
// Create json struct
- apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, commit, userCache)
+ apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache)
if err != nil {
ctx.Error(http.StatusInternalServerError, "toCommit", err)
return
@@ -282,6 +270,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
if err := git.GetRawDiff(
+ ctx,
repoPath,
ctx.Params(":sha"),
git.RawDiffType(ctx.Params(":diffType")),
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index f02c7ea345..a27e383bc3 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -122,7 +122,7 @@ func GetArchive(ctx *context.APIContext) {
repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
if ctx.Repo.GitRepo == nil {
- gitRepo, err := git.OpenRepository(repoPath)
+ gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return
@@ -402,7 +402,7 @@ func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoF
}
opts.Content = string(content)
- return files_service.CreateOrUpdateRepoFile(ctx.Repo.Repository, ctx.User, opts)
+ return files_service.CreateOrUpdateRepoFile(ctx, ctx.Repo.Repository, ctx.User, opts)
}
// DeleteFile Delete a file in a repository
@@ -489,7 +489,7 @@ func DeleteFile(ctx *context.APIContext) {
opts.Message = ctx.Tr("repo.editor.delete", opts.TreePath)
}
- if fileResponse, err := files_service.DeleteRepoFile(ctx.Repo.Repository, ctx.User, opts); err != nil {
+ if fileResponse, err := files_service.DeleteRepoFile(ctx, ctx.Repo.Repository, ctx.User, opts); err != nil {
if git.IsErrBranchNotExist(err) || models.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) {
ctx.Error(http.StatusNotFound, "DeleteFile", err)
return
@@ -555,7 +555,7 @@ func GetContents(ctx *context.APIContext) {
treePath := ctx.Params("*")
ref := ctx.FormTrim("ref")
- if fileList, err := files_service.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
+ if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound("GetContentsOrList", err)
return
diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go
index a5f9512983..edcb27b1ec 100644
--- a/routers/api/v1/repo/notes.go
+++ b/routers/api/v1/repo/notes.go
@@ -55,7 +55,7 @@ func GetNote(ctx *context.APIContext) {
}
func getNote(ctx *context.APIContext, identifier string) {
- gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
+ gitRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return
@@ -72,7 +72,7 @@ func getNote(ctx *context.APIContext, identifier string) {
return
}
- cmt, err := convert.ToCommit(ctx.Repo.Repository, note.Commit, nil)
+ cmt, err := convert.ToCommit(ctx.Repo.Repository, gitRepo, note.Commit, nil)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ToCommit", err)
return
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 158abd4651..52ff8425de 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -119,7 +119,7 @@ func ListPullRequests(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
return
}
- apiPrs[i] = convert.ToAPIPullRequest(prs[i], ctx.User)
+ apiPrs[i] = convert.ToAPIPullRequest(ctx, prs[i], ctx.User)
}
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
@@ -175,7 +175,7 @@ func GetPullRequest(ctx *context.APIContext) {
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
return
}
- ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr, ctx.User))
+ ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.User))
}
// DownloadPullDiffOrPatch render a pull's raw diff or patch
@@ -235,7 +235,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
binary := ctx.FormBool("binary")
- if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch, binary); err != nil {
+ if err := pull_service.DownloadDiffOrPatch(ctx, pr, ctx, patch, binary); err != nil {
ctx.InternalServerError(err)
return
}
@@ -411,7 +411,7 @@ func CreatePullRequest(ctx *context.APIContext) {
}
}
- if err := pull_service.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, assigneeIDs); err != nil {
+ if err := pull_service.NewPullRequest(ctx, repo, prIssue, labelIDs, []string{}, pr, assigneeIDs); err != nil {
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
return
@@ -421,7 +421,7 @@ func CreatePullRequest(ctx *context.APIContext) {
}
log.Trace("Pull request created: %d/%d", repo.ID, prIssue.ID)
- ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(pr, ctx.User))
+ ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.User))
}
// EditPullRequest does what it says
@@ -598,7 +598,7 @@ func EditPullRequest(ctx *context.APIContext) {
ctx.Error(http.StatusNotFound, "NewBaseBranchNotExist", fmt.Errorf("new base '%s' not exist", form.Base))
return
}
- if err := pull_service.ChangeTargetBranch(pr, ctx.User, form.Base); err != nil {
+ if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.User, form.Base); err != nil {
if models.IsErrPullRequestAlreadyExists(err) {
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
return
@@ -628,7 +628,7 @@ func EditPullRequest(ctx *context.APIContext) {
}
// TODO this should be 200, not 201
- ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(pr, ctx.User))
+ ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.User))
}
// IsPullRequestMerged checks if a PR exists given an index
@@ -792,7 +792,7 @@ func MergePullRequest(ctx *context.APIContext) {
return
}
- if err := pull_service.CheckPRReadyToMerge(pr, false); err != nil {
+ if err := pull_service.CheckPRReadyToMerge(ctx, pr, false); err != nil {
if !models.IsErrNotAllowedToMerge(err) {
ctx.Error(http.StatusInternalServerError, "CheckPRReadyToMerge", err)
return
@@ -810,7 +810,7 @@ func MergePullRequest(ctx *context.APIContext) {
}
}
- if _, err := pull_service.IsSignedIfRequired(pr, ctx.User); err != nil {
+ if _, err := pull_service.IsSignedIfRequired(ctx, pr, ctx.User); err != nil {
if !asymkey_service.IsErrWontSign(err) {
ctx.Error(http.StatusInternalServerError, "IsSignedIfRequired", err)
return
@@ -838,7 +838,7 @@ func MergePullRequest(ctx *context.APIContext) {
message += "\n\n" + form.MergeMessageField
}
- if err := pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message); err != nil {
+ if err := pull_service.Merge(ctx, pr, ctx.User, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message); err != nil {
if models.IsErrInvalidMergeStyle(err) {
ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
return
@@ -888,7 +888,7 @@ func MergePullRequest(ctx *context.APIContext) {
if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil {
headRepo = ctx.Repo.GitRepo
} else {
- headRepo, err = git.OpenRepository(pr.HeadRepo.RepoPath())
+ headRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath())
if err != nil {
ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
return
@@ -982,7 +982,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headRepo = ctx.Repo.Repository
headGitRepo = ctx.Repo.GitRepo
} else {
- headGitRepo, err = git.OpenRepository(repo_model.RepoPath(headUser.Name, headRepo.Name))
+ headGitRepo, err = git.OpenRepositoryCtx(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name))
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return nil, nil, nil, nil, "", ""
@@ -1135,7 +1135,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
// default merge commit message
message := fmt.Sprintf("Merge branch '%s' into %s", pr.BaseBranch, pr.HeadBranch)
- if err = pull_service.Update(pr, ctx.User, message, rebase); err != nil {
+ if err = pull_service.Update(ctx, pr, ctx.User, message, rebase); err != nil {
if models.IsErrMergeConflicts(err) {
ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
return
@@ -1204,12 +1204,13 @@ func GetPullRequestCommits(ctx *context.APIContext) {
}
var prInfo *git.CompareInfo
- baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
+ baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
if err != nil {
ctx.ServerError("OpenRepository", err)
return
}
- defer baseGitRepo.Close()
+ defer closer.Close()
+
if pr.HasMerged {
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName(), false, false)
} else {
@@ -1236,7 +1237,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
apiCommits := make([]*api.Commit, 0, end-start)
for i := start; i < end; i++ {
- apiCommit, err := convert.ToCommit(ctx.Repo.Repository, commits[i], userCache)
+ apiCommit, err := convert.ToCommit(ctx.Repo.Repository, baseGitRepo, commits[i], userCache)
if err != nil {
ctx.ServerError("toCommit", err)
return
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go
index ec5f045647..9eb63bafad 100644
--- a/routers/api/v1/repo/pull_review.go
+++ b/routers/api/v1/repo/pull_review.go
@@ -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
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go
index 299eaddbc8..3cdd798151 100644
--- a/routers/api/v1/repo/release.go
+++ b/routers/api/v1/repo/release.go
@@ -356,7 +356,7 @@ func DeleteRelease(ctx *context.APIContext) {
ctx.NotFound()
return
}
- if err := releaseservice.DeleteReleaseByID(id, ctx.User, false); err != nil {
+ if err := releaseservice.DeleteReleaseByID(ctx, id, ctx.User, false); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
return
}
diff --git a/routers/api/v1/repo/release_tags.go b/routers/api/v1/repo/release_tags.go
index 4b853d44bb..d77bdf0331 100644
--- a/routers/api/v1/repo/release_tags.go
+++ b/routers/api/v1/repo/release_tags.go
@@ -110,7 +110,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
return
}
- if err = releaseservice.DeleteReleaseByID(release.ID, ctx.User, false); err != nil {
+ if err = releaseservice.DeleteReleaseByID(ctx, release.ID, ctx.User, false); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 340ba0f6d5..5f17dc9268 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -704,7 +704,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
if ctx.Repo.GitRepo == nil && !repo.IsEmpty {
var err error
- ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath())
+ ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
if err != nil {
ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err)
return err
@@ -1023,7 +1023,7 @@ func Delete(ctx *context.APIContext) {
ctx.Repo.GitRepo.Close()
}
- if err := repo_service.DeleteRepository(ctx.User, repo, true); err != nil {
+ if err := repo_service.DeleteRepository(ctx, ctx.User, repo, true); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
return
}
diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go
index 9d0fbbddad..72d790794e 100644
--- a/routers/api/v1/repo/status.go
+++ b/routers/api/v1/repo/status.go
@@ -62,7 +62,7 @@ func NewCommitStatus(ctx *context.APIContext) {
Description: form.Description,
Context: form.Context,
}
- if err := files_service.CreateCommitStatus(ctx.Repo.Repository, ctx.User, sha, status); err != nil {
+ if err := files_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.User, sha, status); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
return
}
diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go
index 13a625bafb..a60f4f320f 100644
--- a/routers/api/v1/repo/tag.go
+++ b/routers/api/v1/repo/tag.go
@@ -191,7 +191,7 @@ func CreateTag(ctx *context.APIContext) {
return
}
- if err := releaseservice.CreateNewTag(ctx.User, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
+ if err := releaseservice.CreateNewTag(ctx, ctx.User, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
if models.IsErrTagAlreadyExists(err) {
ctx.Error(http.StatusConflict, "tag exist", err)
return
@@ -255,7 +255,7 @@ func DeleteTag(ctx *context.APIContext) {
return
}
- if err = releaseservice.DeleteReleaseByID(tag.ID, ctx.User, true); err != nil {
+ if err = releaseservice.DeleteReleaseByID(ctx, tag.ID, ctx.User, true); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
}
diff --git a/routers/api/v1/repo/tree.go b/routers/api/v1/repo/tree.go
index 411d87d6c5..b8294ebe31 100644
--- a/routers/api/v1/repo/tree.go
+++ b/routers/api/v1/repo/tree.go
@@ -60,7 +60,7 @@ func GetTree(ctx *context.APIContext) {
ctx.Error(http.StatusBadRequest, "", "sha not provided")
return
}
- if tree, err := files_service.GetTreeBySHA(ctx.Repo.Repository, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
+ if tree, err := files_service.GetTreeBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
ctx.Error(http.StatusBadRequest, "", err.Error())
} else {
ctx.SetTotalCountHeader(int64(tree.TotalCount))
diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go
index bef32f367b..94f1dbe0ea 100644
--- a/routers/api/v1/repo/wiki.go
+++ b/routers/api/v1/repo/wiki.go
@@ -71,7 +71,7 @@ func NewWikiPage(ctx *context.APIContext) {
}
form.ContentBase64 = string(content)
- if err := wiki_service.AddWikiPage(ctx.User, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
+ if err := wiki_service.AddWikiPage(ctx, ctx.User, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
if models.IsErrWikiReservedName(err) {
ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
} else if models.IsErrWikiAlreadyExist(err) {
@@ -144,7 +144,7 @@ func EditWikiPage(ctx *context.APIContext) {
}
form.ContentBase64 = string(content)
- if err := wiki_service.EditWikiPage(ctx.User, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
+ if err := wiki_service.EditWikiPage(ctx, ctx.User, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
ctx.Error(http.StatusInternalServerError, "EditWikiPage", err)
return
}
@@ -233,7 +233,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
wikiName := wiki_service.NormalizeWikiName(ctx.Params(":pageName"))
- if err := wiki_service.DeleteWikiPage(ctx.User, ctx.Repo.Repository, wikiName); err != nil {
+ if err := wiki_service.DeleteWikiPage(ctx, ctx.User, ctx.Repo.Repository, wikiName); err != nil {
if err.Error() == "file does not exist" {
ctx.NotFound(err)
return
@@ -458,7 +458,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
// The caller is responsible for closing the returned repo again
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
- wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
+ wikiRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
if err != nil {
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {