mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add context.Context
to more methods (#21546)
This PR adds a context parameter to a bunch of methods. Some helper `xxxCtx()` methods got replaced with the normal name now. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -676,7 +676,7 @@ func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeRef
|
||||
}
|
||||
|
||||
if versionDeleted {
|
||||
notification.NotifyPackageDelete(apictx.Doer, pd)
|
||||
notification.NotifyPackageDelete(apictx, apictx.Doer, pd)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -42,7 +42,7 @@ func NodeInfo(ctx *context.APIContext) {
|
||||
usersActiveMonth := int(user_model.CountUsers(&user_model.CountUserFilter{LastLoginSince: &timeOneMonthAgo}))
|
||||
usersActiveHalfyear := int(user_model.CountUsers(&user_model.CountUserFilter{LastLoginSince: &timeHaveYearAgo}))
|
||||
|
||||
allIssues, _ := issues_model.CountIssues(&issues_model.IssuesOptions{})
|
||||
allIssues, _ := issues_model.CountIssues(ctx, &issues_model.IssuesOptions{})
|
||||
allComments, _ := issues_model.CountComments(&issues_model.FindCommentsOptions{})
|
||||
|
||||
nodeInfoUsage = structs.NodeInfoUsage{
|
||||
|
@@ -109,7 +109,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
|
||||
}
|
||||
opts.RepoID = ctx.Repo.Repository.ID
|
||||
|
||||
totalCount, err := activities_model.CountNotifications(opts)
|
||||
totalCount, err := activities_model.CountNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
@@ -120,7 +120,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
err = nl.LoadAttributes()
|
||||
err = nl.LoadAttributes(ctx)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
@@ -217,12 +217,12 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
||||
changed := make([]*structs.NotificationThread, 0, len(nl))
|
||||
|
||||
for _, n := range nl {
|
||||
notif, err := activities_model.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
|
||||
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
_ = notif.LoadAttributes()
|
||||
_ = notif.LoadAttributes(ctx)
|
||||
changed = append(changed, convert.ToNotificationThread(notif))
|
||||
}
|
||||
ctx.JSON(http.StatusResetContent, changed)
|
||||
|
@@ -42,7 +42,7 @@ func GetThread(ctx *context.APIContext) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
if err := n.LoadAttributes(); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
||||
if err := n.LoadAttributes(ctx); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
@@ -89,12 +89,12 @@ func ReadThread(ctx *context.APIContext) {
|
||||
targetStatus = activities_model.NotificationStatusRead
|
||||
}
|
||||
|
||||
notif, err := activities_model.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
|
||||
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
if err = notif.LoadAttributes(); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
||||
if err = notif.LoadAttributes(ctx); err != nil && !issues_model.IsErrCommentNotExist(err) {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func ReadThread(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
func getThread(ctx *context.APIContext) *activities_model.Notification {
|
||||
n, err := activities_model.GetNotificationByID(ctx.ParamsInt64(":id"))
|
||||
n, err := activities_model.GetNotificationByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if db.IsErrNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "GetNotificationByID", err)
|
||||
|
@@ -69,7 +69,7 @@ func ListNotifications(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
totalCount, err := activities_model.CountNotifications(opts)
|
||||
totalCount, err := activities_model.CountNotifications(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
@@ -80,7 +80,7 @@ func ListNotifications(ctx *context.APIContext) {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
err = nl.LoadAttributes()
|
||||
err = nl.LoadAttributes(ctx)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
@@ -162,12 +162,12 @@ func ReadNotifications(ctx *context.APIContext) {
|
||||
changed := make([]*structs.NotificationThread, 0, len(nl))
|
||||
|
||||
for _, n := range nl {
|
||||
notif, err := activities_model.SetNotificationStatus(n.ID, ctx.Doer, targetStatus)
|
||||
notif, err := activities_model.SetNotificationStatus(ctx, n.ID, ctx.Doer, targetStatus)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
_ = notif.LoadAttributes()
|
||||
_ = notif.LoadAttributes(ctx)
|
||||
changed = append(changed, convert.ToNotificationThread(notif))
|
||||
}
|
||||
|
||||
|
@@ -542,7 +542,7 @@ func GetTeamRepos(ctx *context.APIContext) {
|
||||
}
|
||||
repos := make([]*api.Repository, len(teamRepos))
|
||||
for i, repo := range teamRepos {
|
||||
access, err := access_model.AccessLevel(ctx.Doer, repo)
|
||||
access, err := access_model.AccessLevel(ctx, ctx.Doer, repo)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
|
||||
return
|
||||
@@ -593,7 +593,7 @@ func GetTeamRepo(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
access, err := access_model.AccessLevel(ctx.Doer, repo)
|
||||
access, err := access_model.AccessLevel(ctx, ctx.Doer, repo)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
|
||||
return
|
||||
@@ -650,7 +650,7 @@ func AddTeamRepository(ctx *context.APIContext) {
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if access, err := access_model.AccessLevel(ctx.Doer, repo); err != nil {
|
||||
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
return
|
||||
} else if access < perm.AccessModeAdmin {
|
||||
@@ -700,7 +700,7 @@ func RemoveTeamRepository(ctx *context.APIContext) {
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if access, err := access_model.AccessLevel(ctx.Doer, repo); err != nil {
|
||||
if access, err := access_model.AccessLevel(ctx, ctx.Doer, repo); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
return
|
||||
} else if access < perm.AccessModeAdmin {
|
||||
|
@@ -427,7 +427,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
requiredApprovals = form.RequiredApprovals
|
||||
}
|
||||
|
||||
whitelistUsers, err := user_model.GetUserIDsByNames(form.PushWhitelistUsernames, false)
|
||||
whitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.PushWhitelistUsernames, false)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
||||
@@ -436,7 +436,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
||||
return
|
||||
}
|
||||
mergeWhitelistUsers, err := user_model.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
|
||||
mergeWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
||||
@@ -445,7 +445,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserIDsByNames", err)
|
||||
return
|
||||
}
|
||||
approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
|
||||
approvalsWhitelistUsers, err := user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
||||
@@ -656,7 +656,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
|
||||
var whitelistUsers []int64
|
||||
if form.PushWhitelistUsernames != nil {
|
||||
whitelistUsers, err = user_model.GetUserIDsByNames(form.PushWhitelistUsernames, false)
|
||||
whitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.PushWhitelistUsernames, false)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
||||
@@ -670,7 +670,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
}
|
||||
var mergeWhitelistUsers []int64
|
||||
if form.MergeWhitelistUsernames != nil {
|
||||
mergeWhitelistUsers, err = user_model.GetUserIDsByNames(form.MergeWhitelistUsernames, false)
|
||||
mergeWhitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.MergeWhitelistUsernames, false)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
||||
@@ -684,7 +684,7 @@ func EditBranchProtection(ctx *context.APIContext) {
|
||||
}
|
||||
var approvalsWhitelistUsers []int64
|
||||
if form.ApprovalsWhitelistUsernames != nil {
|
||||
approvalsWhitelistUsers, err = user_model.GetUserIDsByNames(form.ApprovalsWhitelistUsernames, false)
|
||||
approvalsWhitelistUsers, err = user_model.GetUserIDsByNames(ctx, form.ApprovalsWhitelistUsernames, false)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "User does not exist", err)
|
||||
|
@@ -59,7 +59,7 @@ func ListForks(ctx *context.APIContext) {
|
||||
}
|
||||
apiForks := make([]*api.Repository, len(forks))
|
||||
for i, fork := range forks {
|
||||
access, err := access_model.AccessLevel(ctx.Doer, fork)
|
||||
access, err := access_model.AccessLevel(ctx, ctx.Doer, fork)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
return
|
||||
|
@@ -179,7 +179,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||
repoCond := repo_model.SearchRepositoryCondition(opts)
|
||||
repoIDs, _, err := repo_model.SearchRepositoryIDs(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err)
|
||||
ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||
issuesOpt.ReviewRequestedID = ctxUserID
|
||||
}
|
||||
|
||||
if issues, err = issues_model.Issues(issuesOpt); err != nil {
|
||||
if issues, err = issues_model.Issues(ctx, issuesOpt); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "Issues", err)
|
||||
return
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||
issuesOpt.ListOptions = db.ListOptions{
|
||||
Page: -1,
|
||||
}
|
||||
if filteredCount, err = issues_model.CountIssues(issuesOpt); err != nil {
|
||||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CountIssues", err)
|
||||
return
|
||||
}
|
||||
@@ -284,7 +284,7 @@ func SearchIssues(ctx *context.APIContext) {
|
||||
|
||||
ctx.SetLinkHeader(int(filteredCount), limit)
|
||||
ctx.SetTotalCountHeader(filteredCount)
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues))
|
||||
}
|
||||
|
||||
// ListIssues list the issues of a repository
|
||||
@@ -477,7 +477,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||
MentionedID: mentionedByID,
|
||||
}
|
||||
|
||||
if issues, err = issues_model.Issues(issuesOpt); err != nil {
|
||||
if issues, err = issues_model.Issues(ctx, issuesOpt); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "Issues", err)
|
||||
return
|
||||
}
|
||||
@@ -485,7 +485,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||
issuesOpt.ListOptions = db.ListOptions{
|
||||
Page: -1,
|
||||
}
|
||||
if filteredCount, err = issues_model.CountIssues(issuesOpt); err != nil {
|
||||
if filteredCount, err = issues_model.CountIssues(ctx, issuesOpt); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CountIssues", err)
|
||||
return
|
||||
}
|
||||
@@ -493,7 +493,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||
|
||||
ctx.SetLinkHeader(int(filteredCount), listOptions.PageSize)
|
||||
ctx.SetTotalCountHeader(filteredCount)
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues))
|
||||
}
|
||||
|
||||
func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
|
||||
@@ -555,7 +555,7 @@ func GetIssue(ctx *context.APIContext) {
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssue(issue))
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssue(ctx, issue))
|
||||
}
|
||||
|
||||
// CreateIssue create an issue of a repository
|
||||
@@ -612,7 +612,7 @@ func CreateIssue(ctx *context.APIContext) {
|
||||
var err error
|
||||
if ctx.Repo.CanWrite(unit.TypeIssues) {
|
||||
issue.MilestoneID = form.Milestone
|
||||
assigneeIDs, err = issues_model.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
|
||||
assigneeIDs, err = issues_model.MakeIDsFromAPIAssigneesToAdd(ctx, form.Assignee, form.Assignees)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
||||
@@ -671,7 +671,7 @@ func CreateIssue(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueByID", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(issue))
|
||||
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, issue))
|
||||
}
|
||||
|
||||
// EditIssue modify an issue of a repository
|
||||
@@ -823,11 +823,11 @@ func EditIssue(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if titleChanged {
|
||||
notification.NotifyIssueChangeTitle(ctx.Doer, issue, oldTitle)
|
||||
notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
|
||||
}
|
||||
|
||||
if statusChangeComment != nil {
|
||||
notification.NotifyIssueChangeStatus(ctx.Doer, issue, statusChangeComment, issue.IsClosed)
|
||||
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
|
||||
}
|
||||
|
||||
// Refetch from database to assign some automatic values
|
||||
@@ -836,11 +836,11 @@ func EditIssue(ctx *context.APIContext) {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
if err = issue.LoadMilestone(); err != nil {
|
||||
if err = issue.LoadMilestone(ctx); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(issue))
|
||||
ctx.JSON(http.StatusCreated, convert.ToAPIIssue(ctx, issue))
|
||||
}
|
||||
|
||||
func DeleteIssue(ctx *context.APIContext) {
|
||||
|
@@ -91,7 +91,7 @@ func ListIssueComments(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := issues_model.CommentList(comments).LoadPosters(); err != nil {
|
||||
if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
|
||||
return
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := issues_model.CommentList(comments).LoadPosters(); err != nil {
|
||||
if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
|
||||
return
|
||||
}
|
||||
@@ -187,7 +187,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
||||
for _, comment := range comments {
|
||||
if comment.Type != issues_model.CommentTypeCode && isXRefCommentAccessible(ctx, ctx.Doer, comment, issue.RepoID) {
|
||||
comment.Issue = issue
|
||||
apiComments = append(apiComments, convert.ToTimelineComment(comment, ctx.Doer))
|
||||
apiComments = append(apiComments, convert.ToTimelineComment(ctx, comment, ctx.Doer))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,21 +281,21 @@ func ListRepoIssueComments(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = issues_model.CommentList(comments).LoadPosters(); err != nil {
|
||||
if err = issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
|
||||
return
|
||||
}
|
||||
|
||||
apiComments := make([]*api.Comment, len(comments))
|
||||
if err := issues_model.CommentList(comments).LoadIssues(); err != nil {
|
||||
if err := issues_model.CommentList(comments).LoadIssues(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssues", err)
|
||||
return
|
||||
}
|
||||
if err := issues_model.CommentList(comments).LoadPosters(); err != nil {
|
||||
if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
|
||||
return
|
||||
}
|
||||
if _, err := issues_model.CommentList(comments).Issues().LoadRepositories(); err != nil {
|
||||
if _, err := issues_model.CommentList(comments).Issues().LoadRepositories(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadRepositories", err)
|
||||
return
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func CreateIssueComment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
comment, err := comment_service.CreateIssueComment(ctx.Doer, ctx.Repo.Repository, issue, form.Body, nil)
|
||||
comment, err := comment_service.CreateIssueComment(ctx, ctx.Doer, ctx.Repo.Repository, issue, form.Body, nil)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CreateIssueComment", err)
|
||||
return
|
||||
@@ -409,7 +409,7 @@ func GetIssueComment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = comment.LoadIssue(); err != nil {
|
||||
if err = comment.LoadIssue(ctx); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
@@ -423,7 +423,7 @@ func GetIssueComment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := comment.LoadPoster(); err != nil {
|
||||
if err := comment.LoadPoster(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "comment.LoadPoster", err)
|
||||
return
|
||||
}
|
||||
@@ -548,7 +548,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||
|
||||
oldContent := comment.Content
|
||||
comment.Content = form.Body
|
||||
if err := comment_service.UpdateComment(comment, ctx.Doer, oldContent); err != nil {
|
||||
if err := comment_service.UpdateComment(ctx, comment, ctx.Doer, oldContent); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "UpdateComment", err)
|
||||
return
|
||||
}
|
||||
@@ -647,7 +647,7 @@ func deleteIssueComment(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = comment_service.DeleteComment(ctx.Doer, comment); err != nil {
|
||||
if err = comment_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteCommentByID", err)
|
||||
return
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := comment.LoadIssue(); err != nil {
|
||||
if err := comment.LoadIssue(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "comment.LoadIssue", err)
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||
return
|
||||
}
|
||||
|
||||
err = comment.LoadIssue()
|
||||
err = comment.LoadIssue(ctx)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "comment.LoadIssue() failed", err)
|
||||
}
|
||||
|
@@ -139,7 +139,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, trackedTimes))
|
||||
}
|
||||
|
||||
// AddTime add time manual to the given issue
|
||||
@@ -224,7 +224,7 @@ func AddTime(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTime(trackedTime))
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTime(ctx, trackedTime))
|
||||
}
|
||||
|
||||
// ResetIssueTime reset time manual to the given issue
|
||||
@@ -448,7 +448,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, trackedTimes))
|
||||
}
|
||||
|
||||
// ListTrackedTimesByRepository lists all tracked times of the repository
|
||||
@@ -558,7 +558,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, trackedTimes))
|
||||
}
|
||||
|
||||
// ListMyTrackedTimes lists all tracked times of the current user
|
||||
@@ -620,5 +620,5 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(count)
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(trackedTimes))
|
||||
ctx.JSON(http.StatusOK, convert.ToTrackedTimeList(ctx, trackedTimes))
|
||||
}
|
||||
|
@@ -195,7 +195,7 @@ func Migrate(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
notification.NotifyMigrateRepository(ctx.Doer, repoOwner, repo)
|
||||
notification.NotifyMigrateRepository(ctx, ctx.Doer, repoOwner, repo)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -109,19 +109,19 @@ func ListPullRequests(ctx *context.APIContext) {
|
||||
|
||||
apiPrs := make([]*api.PullRequest, len(prs))
|
||||
for i := range prs {
|
||||
if err = prs[i].LoadIssue(); err != nil {
|
||||
if err = prs[i].LoadIssue(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return
|
||||
}
|
||||
if err = prs[i].LoadAttributes(); err != nil {
|
||||
if err = prs[i].LoadAttributes(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
if err = prs[i].LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = prs[i].LoadBaseRepo(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
||||
return
|
||||
}
|
||||
if err = prs[i].LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = prs[i].LoadHeadRepo(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
return
|
||||
}
|
||||
@@ -173,11 +173,11 @@ func GetPullRequest(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
||||
return
|
||||
}
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
return
|
||||
}
|
||||
@@ -300,7 +300,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||
defer headGitRepo.Close()
|
||||
|
||||
// Check if another PR exists with the same targets
|
||||
existingPr, err := issues_model.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch, issues_model.PullRequestFlowGithub)
|
||||
existingPr, err := issues_model.GetUnmergedPullRequest(ctx, headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch, issues_model.PullRequestFlowGithub)
|
||||
if err != nil {
|
||||
if !issues_model.IsErrPullRequestNotExist(err) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUnmergedPullRequest", err)
|
||||
@@ -320,7 +320,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if len(form.Labels) > 0 {
|
||||
labels, err := issues_model.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
|
||||
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
|
||||
return
|
||||
@@ -334,7 +334,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
|
||||
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
|
||||
return
|
||||
@@ -389,7 +389,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// Get all assignee IDs
|
||||
assigneeIDs, err := issues_model.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
|
||||
assigneeIDs, err := issues_model.MakeIDsFromAPIAssigneesToAdd(ctx, form.Assignee, form.Assignees)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
|
||||
@@ -400,7 +400,7 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||
}
|
||||
// Check if the passed assignees is assignable
|
||||
for _, aID := range assigneeIDs {
|
||||
assignee, err := user_model.GetUserByID(aID)
|
||||
assignee, err := user_model.GetUserByIDCtx(ctx, aID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetUserByID", err)
|
||||
return
|
||||
@@ -483,7 +483,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
err = pr.LoadIssue()
|
||||
err = pr.LoadIssue(ctx)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return
|
||||
@@ -551,14 +551,14 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil {
|
||||
labels, err := issues_model.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
|
||||
labels, err := issues_model.GetLabelsInRepoByIDs(ctx, ctx.Repo.Repository.ID, form.Labels)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
|
||||
orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx, ctx.Repo.Owner.ID, form.Labels)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
|
||||
return
|
||||
@@ -591,11 +591,11 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
if titleChanged {
|
||||
notification.NotifyIssueChangeTitle(ctx.Doer, issue, oldTitle)
|
||||
notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
|
||||
}
|
||||
|
||||
if statusChangeComment != nil {
|
||||
notification.NotifyIssueChangeStatus(ctx.Doer, issue, statusChangeComment, issue.IsClosed)
|
||||
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
|
||||
}
|
||||
|
||||
// change pull target branch
|
||||
@@ -619,7 +619,7 @@ func EditPullRequest(ctx *context.APIContext) {
|
||||
}
|
||||
return
|
||||
}
|
||||
notification.NotifyPullRequestChangeTargetBranch(ctx.Doer, pr, form.Base)
|
||||
notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base)
|
||||
}
|
||||
|
||||
// update allow edits
|
||||
@@ -743,12 +743,12 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := pr.LoadIssueCtx(ctx); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return
|
||||
}
|
||||
@@ -811,7 +811,7 @@ func MergePullRequest(ctx *context.APIContext) {
|
||||
|
||||
message := strings.TrimSpace(form.MergeTitleField)
|
||||
if len(message) == 0 {
|
||||
message, err = pull_service.GetDefaultMergeMessage(ctx.Repo.GitRepo, pr, repo_model.MergeStyle(form.Do))
|
||||
message, err = pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pr, repo_model.MergeStyle(form.Do))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetDefaultMergeMessage", err)
|
||||
return
|
||||
@@ -1097,7 +1097,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = pr.LoadIssue(); err != nil {
|
||||
if err = pr.LoadIssue(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return
|
||||
}
|
||||
@@ -1107,11 +1107,11 @@ func UpdatePullRequest(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadBaseRepo", err)
|
||||
return
|
||||
}
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
|
||||
return
|
||||
}
|
||||
@@ -1267,7 +1267,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
@@ -1383,12 +1383,12 @@ func GetPullRequestFiles(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := pr.LoadBaseRepo(); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ func ListPullReviews(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = pr.LoadIssue(); err != nil {
|
||||
if err = pr.LoadIssue(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return
|
||||
}
|
||||
@@ -476,7 +476,7 @@ func SubmitPullReview(ctx *context.APIContext) {
|
||||
|
||||
// preparePullReviewType return ReviewType and false or nil and true if an error happen
|
||||
func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest, event api.ReviewStateType, body string, hasComments bool) (issues_model.ReviewType, bool) {
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return -1, true
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ func GetRelease(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := release.LoadAttributes(); err != nil {
|
||||
if err := release.LoadAttributes(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
@@ -123,14 +123,14 @@ func ListReleases(ctx *context.APIContext) {
|
||||
IsPreRelease: ctx.FormOptionalBool("pre-release"),
|
||||
}
|
||||
|
||||
releases, err := repo_model.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
|
||||
releases, err := repo_model.GetReleasesByRepoID(ctx, ctx.Repo.Repository.ID, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleasesByRepoID", err)
|
||||
return
|
||||
}
|
||||
rels := make([]*api.Release, len(releases))
|
||||
for i, release := range releases {
|
||||
if err := release.LoadAttributes(); err != nil {
|
||||
if err := release.LoadAttributes(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
@@ -313,7 +313,7 @@ func EditRelease(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
||||
return
|
||||
}
|
||||
if err := rel.LoadAttributes(); err != nil {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
@@ -114,7 +114,7 @@ func ListReleaseAttachments(ctx *context.APIContext) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
if err := release.LoadAttributes(); err != nil {
|
||||
if err := release.LoadAttributes(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
@@ -60,7 +60,7 @@ func GetReleaseByTag(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = release.LoadAttributes(); err != nil {
|
||||
if err = release.LoadAttributes(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
@@ -191,7 +191,7 @@ func Search(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
var err error
|
||||
repos, count, err := repo_model.SearchRepository(opts)
|
||||
repos, count, err := repo_model.SearchRepository(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||
OK: false,
|
||||
@@ -209,7 +209,7 @@ func Search(ctx *context.APIContext) {
|
||||
})
|
||||
return
|
||||
}
|
||||
accessMode, err := access_model.AccessLevel(ctx.Doer, repo)
|
||||
accessMode, err := access_model.AccessLevel(ctx, ctx.Doer, repo)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
||||
OK: false,
|
||||
|
@@ -86,7 +86,7 @@ func NewWikiPage(ctx *context.APIContext) {
|
||||
wikiPage := getWikiPage(ctx, wikiName)
|
||||
|
||||
if !ctx.Written() {
|
||||
notification.NotifyNewWikiPage(ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)
|
||||
notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)
|
||||
ctx.JSON(http.StatusCreated, wikiPage)
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func EditWikiPage(ctx *context.APIContext) {
|
||||
wikiPage := getWikiPage(ctx, newWikiName)
|
||||
|
||||
if !ctx.Written() {
|
||||
notification.NotifyEditWikiPage(ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)
|
||||
notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)
|
||||
ctx.JSON(http.StatusOK, wikiPage)
|
||||
}
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyDeleteWikiPage(ctx.Doer, ctx.Repo.Repository, wikiName)
|
||||
notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName)
|
||||
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
|
||||
|
||||
apiRepos := make([]*api.Repository, 0, len(repos))
|
||||
for i := range repos {
|
||||
access, err := access_model.AccessLevel(ctx.Doer, repos[i])
|
||||
access, err := access_model.AccessLevel(ctx, ctx.Doer, repos[i])
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
return
|
||||
@@ -112,7 +112,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
var err error
|
||||
repos, count, err := repo_model.SearchRepository(opts)
|
||||
repos, count, err := repo_model.SearchRepository(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "SearchRepository", err)
|
||||
return
|
||||
@@ -124,7 +124,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetOwner", err)
|
||||
return
|
||||
}
|
||||
accessMode, err := access_model.AccessLevel(ctx.Doer, repo)
|
||||
accessMode, err := access_model.AccessLevel(ctx, ctx.Doer, repo)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
std_context "context"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
@@ -20,15 +21,15 @@ import (
|
||||
|
||||
// getStarredRepos returns the repos that the user with the specified userID has
|
||||
// starred
|
||||
func getStarredRepos(user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, error) {
|
||||
starredRepos, err := repo_model.GetStarredRepos(user.ID, private, listOptions)
|
||||
func getStarredRepos(ctx std_context.Context, user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, error) {
|
||||
starredRepos, err := repo_model.GetStarredRepos(ctx, user.ID, private, listOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repos := make([]*api.Repository, len(starredRepos))
|
||||
for i, starred := range starredRepos {
|
||||
access, err := access_model.AccessLevel(user, starred)
|
||||
access, err := access_model.AccessLevel(ctx, user, starred)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -63,7 +64,7 @@ func GetStarredRepos(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
private := ctx.ContextUser.ID == ctx.Doer.ID
|
||||
repos, err := getStarredRepos(ctx.ContextUser, private, utils.GetListOptions(ctx))
|
||||
repos, err := getStarredRepos(ctx, ctx.ContextUser, private, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
||||
return
|
||||
@@ -93,7 +94,7 @@ func GetMyStarredRepos(ctx *context.APIContext) {
|
||||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
repos, err := getStarredRepos(ctx.Doer, true, utils.GetListOptions(ctx))
|
||||
repos, err := getStarredRepos(ctx, ctx.Doer, true, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getStarredRepos", err)
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
std_context "context"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
@@ -18,15 +19,15 @@ import (
|
||||
)
|
||||
|
||||
// getWatchedRepos returns the repos that the user with the specified userID is watching
|
||||
func getWatchedRepos(user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, int64, error) {
|
||||
watchedRepos, total, err := repo_model.GetWatchedRepos(user.ID, private, listOptions)
|
||||
func getWatchedRepos(ctx std_context.Context, user *user_model.User, private bool, listOptions db.ListOptions) ([]*api.Repository, int64, error) {
|
||||
watchedRepos, total, err := repo_model.GetWatchedRepos(ctx, user.ID, private, listOptions)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
repos := make([]*api.Repository, len(watchedRepos))
|
||||
for i, watched := range watchedRepos {
|
||||
access, err := access_model.AccessLevel(user, watched)
|
||||
access, err := access_model.AccessLevel(ctx, user, watched)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@@ -61,7 +62,7 @@ func GetWatchedRepos(ctx *context.APIContext) {
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
private := ctx.ContextUser.ID == ctx.Doer.ID
|
||||
repos, total, err := getWatchedRepos(ctx.ContextUser, private, utils.GetListOptions(ctx))
|
||||
repos, total, err := getWatchedRepos(ctx, ctx.ContextUser, private, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||
}
|
||||
@@ -90,7 +91,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
|
||||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
repos, total, err := getWatchedRepos(ctx.Doer, true, utils.GetListOptions(ctx))
|
||||
repos, total, err := getWatchedRepos(ctx, ctx.Doer, true, utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user