diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-05-20 22:08:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 22:08:52 +0800 |
commit | fd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch) | |
tree | 50038348ec10485f72344f3ac80324e04abc1283 /routers/api/v1/repo | |
parent | d81e31ad7826a81fc7139f329f250594610a274b (diff) | |
download | gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip |
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context
* remove some unnecessary wrap functions
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r-- | routers/api/v1/repo/branch.go | 18 | ||||
-rw-r--r-- | routers/api/v1/repo/collaborators.go | 8 | ||||
-rw-r--r-- | routers/api/v1/repo/hook.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_comment.go | 12 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_label.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_reaction.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_subscription.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_tracked_time.go | 16 | ||||
-rw-r--r-- | routers/api/v1/repo/label.go | 8 | ||||
-rw-r--r-- | routers/api/v1/repo/language.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/migrate.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/mirror.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 22 | ||||
-rw-r--r-- | routers/api/v1/repo/pull_review.go | 18 | ||||
-rw-r--r-- | routers/api/v1/repo/release_attachment.go | 8 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/status.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/teams.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/transfer.go | 4 |
20 files changed, 78 insertions, 78 deletions
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index c030a896a7..09e6ccf238 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -70,7 +70,7 @@ func GetBranch(ctx *context.APIContext) { return } - branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branchName) + branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) return @@ -206,7 +206,7 @@ func CreateBranch(ctx *context.APIContext) { return } - branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch.Name) + branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name) if err != nil { ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) return @@ -271,7 +271,7 @@ func ListBranches(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "GetCommit", err) return } - branchProtection, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branches[i].Name) + branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name) if err != nil { ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) return @@ -320,7 +320,7 @@ func GetBranchProtection(ctx *context.APIContext) { repo := ctx.Repo.Repository bpName := ctx.Params(":name") - bp, err := models.GetProtectedBranchBy(repo.ID, bpName) + bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) return @@ -412,7 +412,7 @@ func CreateBranchProtection(ctx *context.APIContext) { return } - protectBranch, err := models.GetProtectedBranchBy(repo.ID, form.BranchName) + protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, form.BranchName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetProtectBranchOfRepoByName", err) return @@ -523,7 +523,7 @@ func CreateBranchProtection(ctx *context.APIContext) { } // Reload from db to get all whitelists - bp, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, form.BranchName) + bp, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) return @@ -575,7 +575,7 @@ func EditBranchProtection(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.EditBranchProtectionOption) repo := ctx.Repo.Repository bpName := ctx.Params(":name") - protectBranch, err := models.GetProtectedBranchBy(repo.ID, bpName) + protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) return @@ -758,7 +758,7 @@ func EditBranchProtection(ctx *context.APIContext) { } // Reload from db to ensure get all whitelists - bp, err := models.GetProtectedBranchBy(repo.ID, bpName) + bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetProtectedBranchBy", err) return @@ -802,7 +802,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { repo := ctx.Repo.Repository bpName := ctx.Params(":name") - bp, err := models.GetProtectedBranchBy(repo.ID, bpName) + bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) if err != nil { ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) return diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index fed2d9f055..248497a561 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -103,7 +103,7 @@ func IsCollaborator(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" - user, err := user_model.GetUserByName(ctx.Params(":collaborator")) + user, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator")) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) @@ -159,7 +159,7 @@ func AddCollaborator(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.AddCollaboratorOption) - collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator")) + collaborator, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator")) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) @@ -218,7 +218,7 @@ func DeleteCollaborator(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" - collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator")) + collaborator, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator")) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) @@ -271,7 +271,7 @@ func GetRepoPermissions(ctx *context.APIContext) { return } - collaborator, err := user_model.GetUserByName(ctx.Params(":collaborator")) + collaborator, err := user_model.GetUserByName(ctx, ctx.Params(":collaborator")) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusNotFound, "GetUserByName", err) diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go index 7ec6cd88ab..8a546e581a 100644 --- a/routers/api/v1/repo/hook.go +++ b/routers/api/v1/repo/hook.go @@ -60,7 +60,7 @@ func ListHooks(ctx *context.APIContext) { return } - hooks, err := webhook.ListWebhooksByOpts(opts) + hooks, err := webhook.ListWebhooksByOpts(ctx, opts) if err != nil { ctx.InternalServerError(err) return diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index b45069ad46..62959c3a76 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -145,7 +145,7 @@ func SearchIssues(ctx *context.APIContext) { opts.AllLimited = true } if ctx.FormString("owner") != "" { - owner, err := user_model.GetUserByName(ctx.FormString("owner")) + owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner")) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusBadRequest, "Owner not found", err) @@ -164,7 +164,7 @@ func SearchIssues(ctx *context.APIContext) { ctx.Error(http.StatusBadRequest, "", "Owner organisation is required for filtering on team") return } - team, err := organization.GetTeam(opts.OwnerID, ctx.FormString("team")) + team, err := organization.GetTeam(ctx, opts.OwnerID, ctx.FormString("team")) if err != nil { if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusBadRequest, "Team not found", err) @@ -502,7 +502,7 @@ func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 { return 0 } - user, err := user_model.GetUserByName(userName) + user, err := user_model.GetUserByName(ctx, userName) if user_model.IsErrUserNotExist(err) { ctx.NotFound(err) return 0 diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 6065adc27f..22533c3810 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -79,7 +79,7 @@ func ListIssueComments(ctx *context.APIContext) { Type: models.CommentTypeComment, } - comments, err := models.FindComments(opts) + comments, err := models.FindComments(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "FindComments", err) return @@ -172,7 +172,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) { Type: models.CommentTypeUnknown, } - comments, err := models.FindComments(opts) + comments, err := models.FindComments(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "FindComments", err) return @@ -269,7 +269,7 @@ func ListRepoIssueComments(ctx *context.APIContext) { Before: before, } - comments, err := models.FindComments(opts) + comments, err := models.FindComments(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "FindComments", err) return @@ -399,7 +399,7 @@ func GetIssueComment(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) + comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { ctx.NotFound(err) @@ -526,7 +526,7 @@ func EditIssueCommentDeprecated(ctx *context.APIContext) { } func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) { - comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) + comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { ctx.NotFound(err) @@ -629,7 +629,7 @@ func DeleteIssueCommentDeprecated(ctx *context.APIContext) { } func deleteIssueComment(ctx *context.APIContext) { - comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) + comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { ctx.NotFound(err) diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go index e314e756dd..0193eb4230 100644 --- a/routers/api/v1/repo/issue_label.go +++ b/routers/api/v1/repo/issue_label.go @@ -111,7 +111,7 @@ func AddIssueLabels(ctx *context.APIContext) { return } - labels, err = models.GetLabelsByIssueID(issue.ID) + labels, err = models.GetLabelsByIssueID(ctx, issue.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err) return @@ -173,7 +173,7 @@ func DeleteIssueLabel(ctx *context.APIContext) { return } - label, err := models.GetLabelByID(ctx.ParamsInt64(":id")) + label, err := models.GetLabelByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrLabelNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) @@ -237,7 +237,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) { return } - labels, err = models.GetLabelsByIssueID(issue.ID) + labels, err = models.GetLabelsByIssueID(ctx, issue.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err) return diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go index 5aa7366796..45be7a92dd 100644 --- a/routers/api/v1/repo/issue_reaction.go +++ b/routers/api/v1/repo/issue_reaction.go @@ -49,7 +49,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) { // "403": // "$ref": "#/responses/forbidden" - comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) + comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { ctx.NotFound(err) @@ -176,7 +176,7 @@ func DeleteIssueCommentReaction(ctx *context.APIContext) { } func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) { - comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) + comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { ctx.NotFound(err) diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go index f00c85b126..a608ba2278 100644 --- a/routers/api/v1/repo/issue_subscription.go +++ b/routers/api/v1/repo/issue_subscription.go @@ -116,7 +116,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { return } - user, err := user_model.GetUserByName(ctx.Params(":user")) + user, err := user_model.GetUserByName(ctx, ctx.Params(":user")) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.NotFound() @@ -263,7 +263,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { return } - iwl, err := models.GetIssueWatchers(issue.ID, utils.GetListOptions(ctx)) + iwl, err := models.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err) return @@ -284,7 +284,7 @@ func GetIssueSubscribers(ctx *context.APIContext) { apiUsers = append(apiUsers, convert.ToUser(v, ctx.Doer)) } - count, err := models.CountIssueWatchers(issue.ID) + count, err := models.CountIssueWatchers(ctx, issue.ID) if err != nil { ctx.Error(http.StatusInternalServerError, "CountIssueWatchers", err) return diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 8ccad87838..19e1a82590 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -94,7 +94,7 @@ func ListTrackedTimes(ctx *context.APIContext) { qUser := ctx.FormTrim("user") if qUser != "" { - user, err := user_model.GetUserByName(qUser) + user, err := user_model.GetUserByName(ctx, qUser) if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusNotFound, "User does not exist", err) } else if err != nil { @@ -128,7 +128,7 @@ func ListTrackedTimes(ctx *context.APIContext) { return } - trackedTimes, err := models.GetTrackedTimes(opts) + trackedTimes, err := models.GetTrackedTimes(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err) return @@ -203,7 +203,7 @@ func AddTime(ctx *context.APIContext) { if form.User != "" { if (ctx.IsUserRepoAdmin() && ctx.Doer.Name != form.User) || ctx.Doer.IsAdmin { // allow only RepoAdmin, Admin and User to add time - user, err = user_model.GetUserByName(form.User) + user, err = user_model.GetUserByName(ctx, form.User) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserByName", err) } @@ -415,7 +415,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { ctx.Error(http.StatusBadRequest, "", "time tracking disabled") return } - user, err := user_model.GetUserByName(ctx.Params(":timetrackingusername")) + user, err := user_model.GetUserByName(ctx, ctx.Params(":timetrackingusername")) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.NotFound(err) @@ -439,7 +439,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { RepositoryID: ctx.Repo.Repository.ID, } - trackedTimes, err := models.GetTrackedTimes(opts) + trackedTimes, err := models.GetTrackedTimes(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err) return @@ -512,7 +512,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { // Filters qUser := ctx.FormTrim("user") if qUser != "" { - user, err := user_model.GetUserByName(qUser) + user, err := user_model.GetUserByName(ctx, qUser) if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusNotFound, "User does not exist", err) } else if err != nil { @@ -547,7 +547,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { return } - trackedTimes, err := models.GetTrackedTimes(opts) + trackedTimes, err := models.GetTrackedTimes(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err) return @@ -609,7 +609,7 @@ func ListMyTrackedTimes(ctx *context.APIContext) { return } - trackedTimes, err := models.GetTrackedTimes(opts) + trackedTimes, err := models.GetTrackedTimes(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err) return diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index ab559a2eed..4332b8e627 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -49,7 +49,7 @@ func ListLabels(ctx *context.APIContext) { // "200": // "$ref": "#/responses/LabelList" - labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) + labels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err) return @@ -99,9 +99,9 @@ func GetLabel(ctx *context.APIContext) { ) strID := ctx.Params(":id") if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil { - label, err = models.GetLabelInRepoByName(ctx.Repo.Repository.ID, strID) + label, err = models.GetLabelInRepoByName(ctx, ctx.Repo.Repository.ID, strID) } else { - label, err = models.GetLabelInRepoByID(ctx.Repo.Repository.ID, intID) + label, err = models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, intID) } if err != nil { if models.IsErrRepoLabelNotExist(err) { @@ -206,7 +206,7 @@ func EditLabel(ctx *context.APIContext) { // "$ref": "#/responses/validationError" form := web.GetForm(ctx).(*api.EditLabelOption) - label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) + label, err := models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrRepoLabelNotExist(err) { ctx.NotFound() diff --git a/routers/api/v1/repo/language.go b/routers/api/v1/repo/language.go index f47b0a0e78..ca803cb68b 100644 --- a/routers/api/v1/repo/language.go +++ b/routers/api/v1/repo/language.go @@ -68,7 +68,7 @@ func GetLanguages(ctx *context.APIContext) { // "200": // "$ref": "#/responses/LanguageStatistics" - langs, err := repo_model.GetLanguageStats(ctx.Repo.Repository) + langs, err := repo_model.GetLanguageStats(ctx, ctx.Repo.Repository) if err != nil { log.Error("GetLanguageStats failed: %v", err) ctx.InternalServerError(err) diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index f5851bfcae..f868c53951 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -65,7 +65,7 @@ func Migrate(ctx *context.APIContext) { err error ) if len(form.RepoOwner) != 0 { - repoOwner, err = user_model.GetUserByName(form.RepoOwner) + repoOwner, err = user_model.GetUserByName(ctx, form.RepoOwner) } else if form.RepoOwnerID != 0 { repoOwner, err = user_model.GetUserByID(form.RepoOwnerID) } else { diff --git a/routers/api/v1/repo/mirror.go b/routers/api/v1/repo/mirror.go index d7facd24d9..1af63c55be 100644 --- a/routers/api/v1/repo/mirror.go +++ b/routers/api/v1/repo/mirror.go @@ -50,7 +50,7 @@ func MirrorSync(ctx *context.APIContext) { return } - if _, err := repo_model.GetMirrorByRepoID(repo.ID); err != nil { + if _, err := repo_model.GetMirrorByRepoID(ctx, repo.ID); err != nil { if errors.Is(err, repo_model.ErrMirrorNotExist) { ctx.Error(http.StatusBadRequest, "MirrorSync", "Repository is not a mirror") return diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index a01efda1bc..393f2d1576 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -160,7 +160,7 @@ func GetPullRequest(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -220,7 +220,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) { // "$ref": "#/responses/string" // "404": // "$ref": "#/responses/notFound" - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -470,7 +470,7 @@ func EditPullRequest(ctx *context.APIContext) { // "$ref": "#/responses/validationError" form := web.GetForm(ctx).(*api.EditPullRequestOption) - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -632,7 +632,7 @@ func EditPullRequest(ctx *context.APIContext) { } // Refetch from database - pr, err = models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pr.Index) + pr, err = models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pr.Index) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -676,7 +676,7 @@ func IsPullRequestMerged(ctx *context.APIContext) { // "404": // description: pull request has not been merged - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -730,7 +730,7 @@ func MergePullRequest(ctx *context.APIContext) { form := web.GetForm(ctx).(*forms.MergePullRequestForm) - pr, err := models.GetPullRequestByIndexCtx(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound("GetPullRequestByIndex", err) @@ -938,7 +938,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) headBranch = headInfos[0] } else if len(headInfos) == 2 { - headUser, err = user_model.GetUserByName(headInfos[0]) + headUser, err = user_model.GetUserByName(ctx, headInfos[0]) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByName") @@ -1079,7 +1079,7 @@ func UpdatePullRequest(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -1177,7 +1177,7 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) { // "$ref": "#/responses/notFound" pullIndex := ctx.ParamsInt64(":index") - pull, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pullIndex) + pull, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() @@ -1198,7 +1198,7 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) { } if ctx.Doer.ID != autoMerge.DoerID { - allowed, err := access_model.IsUserRepoAdminCtx(ctx, ctx.Repo.Repository, ctx.Doer) + allowed, err := access_model.IsUserRepoAdmin(ctx, ctx.Repo.Repository, ctx.Doer) if err != nil { ctx.InternalServerError(err) return @@ -1254,7 +1254,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound() diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go index 0cf540ce7e..5175fa921f 100644 --- a/routers/api/v1/repo/pull_review.go +++ b/routers/api/v1/repo/pull_review.go @@ -61,7 +61,7 @@ func ListPullReviews(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound("GetPullRequestByIndex", err) @@ -87,7 +87,7 @@ func ListPullReviews(ctx *context.APIContext) { IssueID: pr.IssueID, } - allReviews, err := models.FindReviews(opts) + allReviews, err := models.FindReviews(ctx, opts) if err != nil { ctx.InternalServerError(err) return @@ -307,7 +307,7 @@ func CreatePullReview(ctx *context.APIContext) { // "$ref": "#/responses/validationError" opts := web.GetForm(ctx).(*api.CreatePullReviewOptions) - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound("GetPullRequestByIndex", err) @@ -526,7 +526,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even // prepareSingleReview return review, related pull and false or nil, nil and true if an error happen func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullRequest, bool) { - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound("GetPullRequestByIndex", err) @@ -536,7 +536,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR return nil, nil, true } - review, err := models.GetReviewByID(ctx.ParamsInt64(":id")) + review, err := models.GetReviewByID(ctx, ctx.ParamsInt64(":id")) if err != nil { if models.IsErrReviewNotExist(err) { ctx.NotFound("GetReviewByID", err) @@ -648,7 +648,7 @@ func DeleteReviewRequests(ctx *context.APIContext) { } func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions, isAdd bool) { - pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { if models.IsErrPullRequestNotExist(err) { ctx.NotFound("GetPullRequestByIndex", err) @@ -676,7 +676,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions if strings.Contains(r, "@") { reviewer, err = user_model.GetUserByEmail(r) } else { - reviewer, err = user_model.GetUserByName(r) + reviewer, err = user_model.GetUserByName(ctx, r) } if err != nil { @@ -727,7 +727,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions teamReviewers := make([]*organization.Team, 0, len(opts.TeamReviewers)) for _, t := range opts.TeamReviewers { var teamReviewer *organization.Team - teamReviewer, err = organization.GetTeam(ctx.Repo.Owner.ID, t) + teamReviewer, err = organization.GetTeam(ctx, ctx.Repo.Owner.ID, t) if err != nil { if organization.IsErrTeamNotExist(err) { ctx.NotFound("TeamNotExist", fmt.Sprintf("Team '%s' not exist", t)) @@ -892,7 +892,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) { return } - if review, err = models.GetReviewByID(review.ID); err != nil { + if review, err = models.GetReviewByID(ctx, review.ID); err != nil { ctx.Error(http.StatusInternalServerError, "GetReviewByID", err) return } diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go index c172b66127..b7807e5e8b 100644 --- a/routers/api/v1/repo/release_attachment.go +++ b/routers/api/v1/repo/release_attachment.go @@ -55,7 +55,7 @@ func GetReleaseAttachment(ctx *context.APIContext) { releaseID := ctx.ParamsInt64(":id") attachID := ctx.ParamsInt64(":asset") - attach, err := repo_model.GetAttachmentByID(attachID) + attach, err := repo_model.GetAttachmentByID(ctx, attachID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err) return @@ -242,7 +242,7 @@ func EditReleaseAttachment(ctx *context.APIContext) { // Check if release exists an load release releaseID := ctx.ParamsInt64(":id") attachID := ctx.ParamsInt64(":asset") - attach, err := repo_model.GetAttachmentByID(attachID) + attach, err := repo_model.GetAttachmentByID(ctx, attachID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err) return @@ -257,7 +257,7 @@ func EditReleaseAttachment(ctx *context.APIContext) { attach.Name = form.Name } - if err := repo_model.UpdateAttachment(attach); err != nil { + if err := repo_model.UpdateAttachment(ctx, attach); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach) } ctx.JSON(http.StatusCreated, convert.ToReleaseAttachment(attach)) @@ -300,7 +300,7 @@ func DeleteReleaseAttachment(ctx *context.APIContext) { // Check if release exists an load release releaseID := ctx.ParamsInt64(":id") attachID := ctx.ParamsInt64(":asset") - attach, err := repo_model.GetAttachmentByID(attachID) + attach, err := repo_model.GetAttachmentByID(ctx, attachID) if err != nil { ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err) return diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index a11f579ee1..8485ffbac2 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -365,7 +365,7 @@ func Generate(ctx *context.APIContext) { ctxUser := ctx.Doer var err error if form.Owner != ctxUser.Name { - ctxUser, err = user_model.GetUserByName(form.Owner) + ctxUser, err = user_model.GetUserByName(ctx, form.Owner) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.JSON(http.StatusNotFound, map[string]interface{}{ @@ -962,7 +962,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error { } // get the mirror from the repo - mirror, err := repo_model.GetMirrorByRepoID(repo.ID) + mirror, err := repo_model.GetMirrorByRepoID(ctx, repo.ID) if err != nil { log.Error("Failed to get mirror: %s", err) ctx.Error(http.StatusInternalServerError, "MirrorInterval", err) @@ -1000,7 +1000,7 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error { } // finally update the mirror in the DB - if err := repo_model.UpdateMirror(mirror); err != nil { + if err := repo_model.UpdateMirror(ctx, mirror); err != nil { log.Error("Failed to Set Mirror Interval: %s", err) ctx.Error(http.StatusUnprocessableEntity, "MirrorInterval", err) return err diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index f4c0ebd38c..09597dc4e8 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -253,7 +253,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { repo := ctx.Repo.Repository - statuses, count, err := models.GetLatestCommitStatus(repo.ID, sha, utils.GetListOptions(ctx)) + statuses, count, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %v", repo.FullName(), sha, err)) return diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go index e414d8b60e..47c69d722b 100644 --- a/routers/api/v1/repo/teams.go +++ b/routers/api/v1/repo/teams.go @@ -41,7 +41,7 @@ func ListTeams(ctx *context.APIContext) { return } - teams, err := organization.GetRepoTeams(ctx.Repo.Repository) + teams, err := organization.GetRepoTeams(ctx, ctx.Repo.Repository) if err != nil { ctx.InternalServerError(err) return @@ -216,7 +216,7 @@ func changeRepoTeam(ctx *context.APIContext, add bool) { } func getTeamByParam(ctx *context.APIContext) *organization.Team { - team, err := organization.GetTeam(ctx.Repo.Owner.ID, ctx.Params(":team")) + team, err := organization.GetTeam(ctx, ctx.Repo.Owner.ID, ctx.Params(":team")) if err != nil { if organization.IsErrTeamNotExist(err) { ctx.Error(http.StatusNotFound, "TeamNotExit", err) diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index 241c578e60..067a4ebe19 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -57,7 +57,7 @@ func Transfer(ctx *context.APIContext) { opts := web.GetForm(ctx).(*api.TransferRepoOption) - newOwner, err := user_model.GetUserByName(opts.NewOwner) + newOwner, err := user_model.GetUserByName(ctx, opts.NewOwner) if err != nil { if user_model.IsErrUserNotExist(err) { ctx.Error(http.StatusNotFound, "", "The new owner does not exist or cannot be found") @@ -84,7 +84,7 @@ func Transfer(ctx *context.APIContext) { org := convert.ToOrganization(organization.OrgFromUser(newOwner)) for _, tID := range *opts.TeamIDs { - team, err := organization.GetTeamByID(tID) + team, err := organization.GetTeamByID(ctx, tID) if err != nil { ctx.Error(http.StatusUnprocessableEntity, "team", fmt.Errorf("team %d not found", tID)) return |