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
This commit is contained in:
parent
d81e31ad78
commit
fd7d83ace6
232 changed files with 1463 additions and 2108 deletions
|
@ -85,7 +85,7 @@ func AdoptRepository(ctx *context.APIContext) {
|
|||
ownerName := ctx.Params(":username")
|
||||
repoName := ctx.Params(":reponame")
|
||||
|
||||
ctxUser, err := user_model.GetUserByName(ownerName)
|
||||
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -96,7 +96,7 @@ func AdoptRepository(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// check not a repo
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, repoName)
|
||||
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -147,7 +147,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
|||
ownerName := ctx.Params(":username")
|
||||
repoName := ctx.Params(":reponame")
|
||||
|
||||
ctxUser, err := user_model.GetUserByName(ownerName)
|
||||
ctxUser, err := user_model.GetUserByName(ctx, ownerName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -158,7 +158,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// check not a repo
|
||||
has, err := repo_model.IsRepositoryExist(ctxUser, repoName)
|
||||
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -269,7 +269,7 @@ func EditUser(ctx *context.APIContext) {
|
|||
ctx.ContextUser.IsRestricted = *form.Restricted
|
||||
}
|
||||
|
||||
if err := user_model.UpdateUser(ctx.ContextUser, emailChanged); err != nil {
|
||||
if err := user_model.UpdateUser(ctx, ctx.ContextUser, emailChanged); err != nil {
|
||||
if user_model.IsErrEmailAlreadyUsed(err) ||
|
||||
user_model.IsErrEmailCharIsNotSupported(err) ||
|
||||
user_model.IsErrEmailInvalid(err) {
|
||||
|
|
|
@ -108,7 +108,7 @@ func sudo() func(ctx *context.APIContext) {
|
|||
|
||||
if len(sudo) > 0 {
|
||||
if ctx.IsSigned && ctx.Doer.IsAdmin {
|
||||
user, err := user_model.GetUserByName(sudo)
|
||||
user, err := user_model.GetUserByName(ctx, sudo)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
@ -143,7 +143,7 @@ func repoAssignment() func(ctx *context.APIContext) {
|
|||
if ctx.IsSigned && ctx.Doer.LowerName == strings.ToLower(userName) {
|
||||
owner = ctx.Doer
|
||||
} else {
|
||||
owner, err = user_model.GetUserByName(userName)
|
||||
owner, err = user_model.GetUserByName(ctx, userName)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
|
||||
|
@ -467,7 +467,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
if assignTeam {
|
||||
ctx.Org.Team, err = organization.GetTeamByID(ctx.ParamsInt64(":teamid"))
|
||||
ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.ParamsInt64(":teamid"))
|
||||
if err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -22,7 +22,7 @@ func NewAvailable(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/NotificationCount"
|
||||
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx.Doer)})
|
||||
ctx.JSON(http.StatusOK, api.NotificationCount{New: models.CountUnread(ctx, ctx.Doer.ID)})
|
||||
}
|
||||
|
||||
func getFindNotificationOptions(ctx *context.APIContext) *models.FindNotificationOptions {
|
||||
|
|
|
@ -115,7 +115,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -203,7 +203,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
|||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
|
||||
log.Error("%v", opts.Status)
|
||||
}
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -75,7 +75,7 @@ func ListNotifications(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
@ -148,7 +148,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
statuses := ctx.FormStrings("status-types")
|
||||
opts.Status = statusStringsToNotificationStatuses(statuses, []string{"unread"})
|
||||
}
|
||||
nl, err := models.GetNotifications(opts)
|
||||
nl, err := models.GetNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -51,7 +51,7 @@ func ListHooks(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
orgHooks, err := webhook.ListWebhooksByOpts(opts)
|
||||
orgHooks, err := webhook.ListWebhooksByOpts(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
|
|
|
@ -43,7 +43,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/LabelList"
|
||||
|
||||
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
labels, err := models.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err)
|
||||
return
|
||||
|
@ -136,9 +136,9 @@ func GetLabel(ctx *context.APIContext) {
|
|||
)
|
||||
strID := ctx.Params(":id")
|
||||
if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil {
|
||||
label, err = models.GetLabelInOrgByName(ctx.Org.Organization.ID, strID)
|
||||
label, err = models.GetLabelInOrgByName(ctx, ctx.Org.Organization.ID, strID)
|
||||
} else {
|
||||
label, err = models.GetLabelInOrgByID(ctx.Org.Organization.ID, intID)
|
||||
label, err = models.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, intID)
|
||||
}
|
||||
if err != nil {
|
||||
if models.IsErrOrgLabelNotExist(err) {
|
||||
|
@ -183,7 +183,7 @@ func EditLabel(ctx *context.APIContext) {
|
|||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
form := web.GetForm(ctx).(*api.EditLabelOption)
|
||||
label, err := models.GetLabelInOrgByID(ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
|
||||
label, err := models.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrOrgLabelNotExist(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -213,7 +213,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
|
|||
|
||||
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
|
||||
|
||||
app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{
|
||||
app, err := auth.CreateOAuth2Application(ctx, auth.CreateOAuth2ApplicationOptions{
|
||||
Name: data.Name,
|
||||
UserID: ctx.Doer.ID,
|
||||
RedirectURIs: data.RedirectURIs,
|
||||
|
@ -320,7 +320,7 @@ func GetOauth2Application(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
appID := ctx.ParamsInt64(":id")
|
||||
app, err := auth.GetOAuth2ApplicationByID(appID)
|
||||
app, err := auth.GetOAuth2ApplicationByID(ctx, appID)
|
||||
if err != nil {
|
||||
if auth.IsErrOauthClientIDInvalid(err) || auth.IsErrOAuthApplicationNotFound(err) {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// GetUserByParamsName get user by name
|
||||
func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User {
|
||||
username := ctx.Params(name)
|
||||
user, err := user_model.GetUserByName(username)
|
||||
user, err := user_model.GetUserByName(ctx, username)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
if redirectUserID, err2 := user_model.LookupUserRedirect(username); err2 == nil {
|
||||
|
|
|
@ -74,7 +74,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
|
|||
ctx.Doer.KeepActivityPrivate = *form.HideActivity
|
||||
}
|
||||
|
||||
if err := user_model.UpdateUser(ctx.Doer, false); err != nil {
|
||||
if err := user_model.UpdateUser(ctx, ctx.Doer, false); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ func IsStarring(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if repo_model.IsStaring(ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
if repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
|
||||
ctx.Status(http.StatusNoContent)
|
||||
} else {
|
||||
ctx.NotFound()
|
||||
|
|
|
@ -98,7 +98,7 @@ func GetInfo(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if !user_model.IsUserVisibleToViewer(ctx.ContextUser, ctx.Doer) {
|
||||
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
|
||||
// fake ErrUserNotExist error message to not leak information about existence
|
||||
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.Params(":username")})
|
||||
return
|
||||
|
|
|
@ -156,7 +156,7 @@ func Watch(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/WatchInfo"
|
||||
|
||||
err := repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
err := repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
|
||||
return
|
||||
|
@ -191,7 +191,7 @@ func Unwatch(ctx *context.APIContext) {
|
|||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
||||
err := repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err := repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue