mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +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)
|
||||
}
|
||||
|
@@ -202,7 +202,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
||||
continue
|
||||
}
|
||||
|
||||
pr, err := issues_model.GetUnmergedPullRequest(repo.ID, baseRepo.ID, branch, baseRepo.DefaultBranch, issues_model.PullRequestFlowGithub)
|
||||
pr, err := issues_model.GetUnmergedPullRequest(ctx, repo.ID, baseRepo.ID, branch, baseRepo.DefaultBranch, issues_model.PullRequestFlowGithub)
|
||||
if err != nil && !issues_model.IsErrPullRequestNotExist(err) {
|
||||
log.Error("Failed to get active PR in: %-v Branch: %s to: %-v Branch: %s Error: %v", repo, branch, baseRepo, baseRepo.DefaultBranch, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
|
||||
|
@@ -372,7 +372,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName
|
||||
|
||||
if !ctx.gotProtectedTags {
|
||||
var err error
|
||||
ctx.protectedTags, err = git_model.GetProtectedTags(ctx.Repo.Repository.ID)
|
||||
ctx.protectedTags, err = git_model.GetProtectedTags(ctx, ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
log.Error("Unable to get protected tags for %-v Error: %v", ctx.Repo.Repository, err)
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
@@ -383,7 +383,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName
|
||||
ctx.gotProtectedTags = true
|
||||
}
|
||||
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(ctx.protectedTags, tagName, ctx.opts.UserID)
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(ctx, ctx.protectedTags, tagName, ctx.opts.UserID)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, private.Response{
|
||||
Err: err.Error(),
|
||||
|
@@ -98,7 +98,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
||||
language := ctx.FormTrim("language")
|
||||
ctx.Data["Language"] = language
|
||||
|
||||
repos, count, err = repo_model.SearchRepository(&repo_model.SearchRepoOptions{
|
||||
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: opts.PageSize,
|
||||
|
@@ -88,7 +88,7 @@ func HomeSitemap(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
_, cnt, err := repo_model.SearchRepository(&repo_model.SearchRepoOptions{
|
||||
_, cnt, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 1,
|
||||
},
|
||||
|
@@ -99,7 +99,7 @@ func Home(ctx *context.Context) {
|
||||
count int64
|
||||
err error
|
||||
)
|
||||
repos, count, err = repo_model.SearchRepository(&repo_model.SearchRepoOptions{
|
||||
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
Page: page,
|
||||
|
@@ -275,14 +275,14 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p
|
||||
mergeMovedOn := false
|
||||
if pr != nil {
|
||||
pr.HeadRepo = ctx.Repo.Repository
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
ctx.ServerError("pr.LoadIssue", err)
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
ctx.ServerError("LoadIssue", err)
|
||||
return nil
|
||||
}
|
||||
if repo, ok := repoIDToRepo[pr.BaseRepoID]; ok {
|
||||
pr.BaseRepo = repo
|
||||
} else if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
ctx.ServerError("pr.LoadBaseRepo", err)
|
||||
} else if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadBaseRepo", err)
|
||||
return nil
|
||||
} else {
|
||||
repoIDToRepo[pr.BaseRepoID] = pr.BaseRepo
|
||||
|
@@ -747,7 +747,7 @@ func CompareDiff(ctx *context.Context) {
|
||||
ctx.Data["HeadTags"] = headTags
|
||||
|
||||
if ctx.Data["PageIsComparePull"] == true {
|
||||
pr, err := issues_model.GetUnmergedPullRequest(ci.HeadRepo.ID, ctx.Repo.Repository.ID, ci.HeadBranch, ci.BaseBranch, issues_model.PullRequestFlowGithub)
|
||||
pr, err := issues_model.GetUnmergedPullRequest(ctx, ci.HeadRepo.ID, ctx.Repo.Repository.ID, ci.HeadBranch, ci.BaseBranch, issues_model.PullRequestFlowGithub)
|
||||
if err != nil {
|
||||
if !issues_model.IsErrPullRequestNotExist(err) {
|
||||
ctx.ServerError("GetUnmergedPullRequest", err)
|
||||
@@ -755,7 +755,7 @@ func CompareDiff(ctx *context.Context) {
|
||||
}
|
||||
} else {
|
||||
ctx.Data["HasPullRequest"] = true
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
ctx.ServerError("LoadIssue", err)
|
||||
return
|
||||
}
|
||||
|
@@ -246,7 +246,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||
if forceEmpty {
|
||||
issues = []*issues_model.Issue{}
|
||||
} else {
|
||||
issues, err = issues_model.Issues(&issues_model.IssuesOptions{
|
||||
issues, err = issues_model.Issues(ctx, &issues_model.IssuesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
Page: pager.Paginater.Current(),
|
||||
PageSize: setting.UI.IssuePagingNum,
|
||||
@@ -608,7 +608,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
|
||||
currentPullReviewers := make([]*repoReviewerSelection, 0, len(pullReviews))
|
||||
for _, item := range pullReviews {
|
||||
if item.Review.ReviewerID > 0 {
|
||||
if err = item.Review.LoadReviewer(); err != nil {
|
||||
if err = item.Review.LoadReviewer(ctx); err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
continue
|
||||
}
|
||||
@@ -617,7 +617,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
|
||||
}
|
||||
item.User = item.Review.Reviewer
|
||||
} else if item.Review.ReviewerTeamID > 0 {
|
||||
if err = item.Review.LoadReviewerTeam(); err != nil {
|
||||
if err = item.Review.LoadReviewerTeam(ctx); err != nil {
|
||||
if organization.IsErrTeamNotExist(err) {
|
||||
continue
|
||||
}
|
||||
@@ -1163,7 +1163,7 @@ func getBranchData(ctx *context.Context, issue *issues_model.Issue) {
|
||||
pull := issue.PullRequest
|
||||
ctx.Data["BaseBranch"] = pull.BaseBranch
|
||||
ctx.Data["HeadBranch"] = pull.HeadBranch
|
||||
ctx.Data["HeadUserName"] = pull.MustHeadUserName()
|
||||
ctx.Data["HeadUserName"] = pull.MustHeadUserName(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1426,13 +1426,13 @@ func ViewIssue(ctx *context.Context) {
|
||||
for _, comment = range issue.Comments {
|
||||
comment.Issue = issue
|
||||
|
||||
if err := comment.LoadPoster(); err != nil {
|
||||
if err := comment.LoadPoster(ctx); err != nil {
|
||||
ctx.ServerError("LoadPoster", err)
|
||||
return
|
||||
}
|
||||
|
||||
if comment.Type == issues_model.CommentTypeComment || comment.Type == issues_model.CommentTypeReview {
|
||||
if err := comment.LoadAttachments(); err != nil {
|
||||
if err := comment.LoadAttachments(ctx); err != nil {
|
||||
ctx.ServerError("LoadAttachments", err)
|
||||
return
|
||||
}
|
||||
@@ -1467,7 +1467,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
} else if comment.Type == issues_model.CommentTypeMilestone {
|
||||
if err = comment.LoadMilestone(); err != nil {
|
||||
if err = comment.LoadMilestone(ctx); err != nil {
|
||||
ctx.ServerError("LoadMilestone", err)
|
||||
return
|
||||
}
|
||||
@@ -1591,7 +1591,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
ctx.Data["AllowMerge"] = false
|
||||
|
||||
if ctx.IsSigned {
|
||||
if err := pull.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pull.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
} else if pull.HeadRepo != nil {
|
||||
perm, err := access_model.GetUserRepoPermission(ctx, pull.HeadRepo, ctx.Doer)
|
||||
@@ -1613,7 +1613,7 @@ func ViewIssue(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := pull.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pull.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
}
|
||||
perm, err := access_model.GetUserRepoPermission(ctx, pull.BaseRepo, ctx.Doer)
|
||||
@@ -1662,14 +1662,14 @@ func ViewIssue(ctx *context.Context) {
|
||||
|
||||
ctx.Data["MergeStyle"] = mergeStyle
|
||||
|
||||
defaultMergeMessage, err := pull_service.GetDefaultMergeMessage(ctx.Repo.GitRepo, pull, mergeStyle)
|
||||
defaultMergeMessage, err := pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pull, mergeStyle)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDefaultMergeMessage", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["DefaultMergeMessage"] = defaultMergeMessage
|
||||
|
||||
defaultSquashMergeMessage, err := pull_service.GetDefaultMergeMessage(ctx.Repo.GitRepo, pull, repo_model.MergeStyleSquash)
|
||||
defaultSquashMergeMessage, err := pull_service.GetDefaultMergeMessage(ctx, ctx.Repo.GitRepo, pull, repo_model.MergeStyleSquash)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDefaultSquashMergeMessage", err)
|
||||
return
|
||||
@@ -1885,7 +1885,7 @@ func GetIssueInfo(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssue(issue))
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssue(ctx, issue))
|
||||
}
|
||||
|
||||
// UpdateIssueTitle change issue's title
|
||||
@@ -2280,7 +2280,7 @@ func SearchIssues(ctx *context.Context) {
|
||||
repoCond := repo_model.SearchRepositoryCondition(opts)
|
||||
repoIDs, _, err := repo_model.SearchRepositoryIDs(opts)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err.Error())
|
||||
ctx.Error(http.StatusInternalServerError, "SearchRepositoryIDs", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2369,7 +2369,7 @@ func SearchIssues(ctx *context.Context) {
|
||||
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.Error())
|
||||
return
|
||||
}
|
||||
@@ -2377,14 +2377,14 @@ func SearchIssues(ctx *context.Context) {
|
||||
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.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(filteredCount)
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues))
|
||||
}
|
||||
|
||||
func getUserIDForFilter(ctx *context.Context, queryName string) int64 {
|
||||
@@ -2527,7 +2527,7 @@ func ListIssues(ctx *context.Context) {
|
||||
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, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -2535,14 +2535,14 @@ func ListIssues(ctx *context.Context) {
|
||||
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, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(filteredCount)
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues))
|
||||
}
|
||||
|
||||
// UpdateIssueStatus change issue's status
|
||||
@@ -2562,7 +2562,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
||||
log.Warn("Unrecognized action: %s", action)
|
||||
}
|
||||
|
||||
if _, err := issues_model.IssueList(issues).LoadRepositories(); err != nil {
|
||||
if _, err := issues_model.IssueList(issues).LoadRepositories(ctx); err != nil {
|
||||
ctx.ServerError("LoadRepositories", err)
|
||||
return
|
||||
}
|
||||
@@ -2646,7 +2646,7 @@ func NewComment(ctx *context.Context) {
|
||||
if form.Status == "reopen" && issue.IsPull {
|
||||
pull := issue.PullRequest
|
||||
var err error
|
||||
pr, err = issues_model.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch, pull.Flow)
|
||||
pr, err = issues_model.GetUnmergedPullRequest(ctx, pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch, pull.Flow)
|
||||
if err != nil {
|
||||
if !issues_model.IsErrPullRequestNotExist(err) {
|
||||
ctx.ServerError("GetUnmergedPullRequest", err)
|
||||
@@ -2706,7 +2706,7 @@ func NewComment(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
comment, err := comment_service.CreateIssueComment(ctx.Doer, ctx.Repo.Repository, issue, form.Content, attachments)
|
||||
comment, err := comment_service.CreateIssueComment(ctx, ctx.Doer, ctx.Repo.Repository, issue, form.Content, attachments)
|
||||
if err != nil {
|
||||
ctx.ServerError("CreateIssueComment", err)
|
||||
return
|
||||
@@ -2723,7 +2723,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := comment.LoadIssue(); err != nil {
|
||||
if err := comment.LoadIssue(ctx); err != nil {
|
||||
ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
|
||||
return
|
||||
}
|
||||
@@ -2746,12 +2746,12 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
if err = comment_service.UpdateComment(comment, ctx.Doer, oldContent); err != nil {
|
||||
if err = comment_service.UpdateComment(ctx, comment, ctx.Doer, oldContent); err != nil {
|
||||
ctx.ServerError("UpdateComment", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := comment.LoadAttachments(); err != nil {
|
||||
if err := comment.LoadAttachments(ctx); err != nil {
|
||||
ctx.ServerError("LoadAttachments", err)
|
||||
return
|
||||
}
|
||||
@@ -2789,7 +2789,7 @@ func DeleteComment(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := comment.LoadIssue(); err != nil {
|
||||
if err := comment.LoadIssue(ctx); err != nil {
|
||||
ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
|
||||
return
|
||||
}
|
||||
@@ -2802,8 +2802,8 @@ func DeleteComment(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = comment_service.DeleteComment(ctx.Doer, comment); err != nil {
|
||||
ctx.ServerError("DeleteCommentByID", err)
|
||||
if err = comment_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
|
||||
ctx.ServerError("DeleteComment", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2915,7 +2915,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := comment.LoadIssue(); err != nil {
|
||||
if err := comment.LoadIssue(ctx); err != nil {
|
||||
ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
|
||||
return
|
||||
}
|
||||
@@ -3061,7 +3061,7 @@ func GetCommentAttachments(ctx *context.Context) {
|
||||
}
|
||||
attachments := make([]*api.Attachment, 0)
|
||||
if comment.Type == issues_model.CommentTypeComment {
|
||||
if err := comment.LoadAttachments(); err != nil {
|
||||
if err := comment.LoadAttachments(ctx); err != nil {
|
||||
ctx.ServerError("LoadAttachments", err)
|
||||
return
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ func RetrieveLabels(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
for _, l := range orgLabels {
|
||||
l.CalOpenOrgIssues(ctx.Repo.Repository.ID, l.ID)
|
||||
l.CalOpenOrgIssues(ctx, ctx.Repo.Repository.ID, l.ID)
|
||||
}
|
||||
ctx.Data["OrgLabels"] = orgLabels
|
||||
|
||||
|
@@ -297,7 +297,7 @@ func ViewProject(ctx *context.Context) {
|
||||
boards[0].Title = ctx.Tr("repo.projects.type.uncategorized")
|
||||
}
|
||||
|
||||
issuesMap, err := issues_model.LoadIssuesFromBoardList(boards)
|
||||
issuesMap, err := issues_model.LoadIssuesFromBoardList(ctx, boards)
|
||||
if err != nil {
|
||||
ctx.ServerError("LoadIssuesOfBoards", err)
|
||||
return
|
||||
@@ -314,7 +314,7 @@ func ViewProject(ctx *context.Context) {
|
||||
}
|
||||
|
||||
if len(referencedIds) > 0 {
|
||||
if linkedPrs, err := issues_model.Issues(&issues_model.IssuesOptions{
|
||||
if linkedPrs, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
|
||||
IssueIDs: referencedIds,
|
||||
IsPull: util.OptionalBoolTrue,
|
||||
}); err == nil {
|
||||
|
@@ -281,7 +281,7 @@ func checkPullInfo(ctx *context.Context) *issues_model.Issue {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err = issue.LoadPoster(); err != nil {
|
||||
if err = issue.LoadPoster(ctx); err != nil {
|
||||
ctx.ServerError("LoadPoster", err)
|
||||
return nil
|
||||
}
|
||||
@@ -297,12 +297,12 @@ func checkPullInfo(ctx *context.Context) *issues_model.Issue {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = issue.LoadPullRequest(); err != nil {
|
||||
if err = issue.LoadPullRequest(ctx); err != nil {
|
||||
ctx.ServerError("LoadPullRequest", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = issue.PullRequest.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = issue.PullRequest.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadHeadRepo", err)
|
||||
return nil
|
||||
}
|
||||
@@ -319,12 +319,12 @@ func checkPullInfo(ctx *context.Context) *issues_model.Issue {
|
||||
}
|
||||
|
||||
func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
|
||||
if ctx.Repo.Owner.Name == pull.MustHeadUserName() {
|
||||
if ctx.Repo.Owner.Name == pull.MustHeadUserName(ctx) {
|
||||
ctx.Data["HeadTarget"] = pull.HeadBranch
|
||||
} else if pull.HeadRepo == nil {
|
||||
ctx.Data["HeadTarget"] = pull.MustHeadUserName() + ":" + pull.HeadBranch
|
||||
ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + ":" + pull.HeadBranch
|
||||
} else {
|
||||
ctx.Data["HeadTarget"] = pull.MustHeadUserName() + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
|
||||
ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
|
||||
}
|
||||
ctx.Data["BaseTarget"] = pull.BaseBranch
|
||||
ctx.Data["HeadBranchHTMLURL"] = pull.GetHeadBranchHTMLURL()
|
||||
@@ -416,12 +416,12 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
|
||||
repo := ctx.Repo.Repository
|
||||
pull := issue.PullRequest
|
||||
|
||||
if err := pull.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pull.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadHeadRepo", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := pull.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pull.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadBaseRepo", err)
|
||||
return nil
|
||||
}
|
||||
@@ -606,7 +606,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
|
||||
|
||||
if pull.IsWorkInProgress() {
|
||||
ctx.Data["IsPullWorkInProgress"] = true
|
||||
ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix()
|
||||
ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix(ctx)
|
||||
}
|
||||
|
||||
if pull.IsFilesConflicted() {
|
||||
@@ -834,11 +834,11 @@ func UpdatePullRequest(ctx *context.Context) {
|
||||
|
||||
rebase := ctx.FormString("style") == "rebase"
|
||||
|
||||
if err := issue.PullRequest.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := issue.PullRequest.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadBaseRepo", err)
|
||||
return
|
||||
}
|
||||
if err := issue.PullRequest.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := issue.PullRequest.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadHeadRepo", err)
|
||||
return
|
||||
}
|
||||
@@ -974,7 +974,7 @@ func MergePullRequest(ctx *context.Context) {
|
||||
message := strings.TrimSpace(form.MergeTitleField)
|
||||
if len(message) == 0 {
|
||||
var err error
|
||||
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.ServerError("GetDefaultMergeMessage", err)
|
||||
return
|
||||
@@ -1296,14 +1296,14 @@ func CleanUpPullRequest(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadHeadRepo", err)
|
||||
return
|
||||
} else if pr.HeadRepo == nil {
|
||||
// Forked repository has already been deleted
|
||||
ctx.NotFound("CleanUpPullRequest", nil)
|
||||
return
|
||||
} else if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
} else if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
ctx.ServerError("LoadBaseRepo", err)
|
||||
return
|
||||
} else if err = pr.HeadRepo.GetOwner(ctx); err != nil {
|
||||
@@ -1499,7 +1499,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
|
||||
}
|
||||
return
|
||||
}
|
||||
notification.NotifyPullRequestChangeTargetBranch(ctx.Doer, pr, targetBranch)
|
||||
notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch)
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"base_branch": pr.BaseBranch,
|
||||
|
@@ -114,7 +114,7 @@ func UpdateResolveConversation(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = comment.LoadIssue(); err != nil {
|
||||
if err = comment.LoadIssue(ctx); err != nil {
|
||||
ctx.ServerError("comment.LoadIssue", err)
|
||||
return
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
|
||||
ctx.Data["comments"] = comments
|
||||
ctx.Data["CanMarkConversation"] = true
|
||||
ctx.Data["Issue"] = comment.Issue
|
||||
if err = comment.Issue.LoadPullRequest(); err != nil {
|
||||
if err = comment.Issue.LoadPullRequest(ctx); err != nil {
|
||||
ctx.ServerError("comment.Issue.LoadPullRequest", err)
|
||||
return
|
||||
}
|
||||
|
@@ -130,7 +130,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
|
||||
opts.IncludeDrafts = writeAccess
|
||||
}
|
||||
|
||||
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.ServerError("GetReleasesByRepoID", err)
|
||||
return
|
||||
@@ -266,7 +266,7 @@ func LatestRelease(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := release.LoadAttributes(); err != nil {
|
||||
if err := release.LoadAttributes(ctx); err != nil {
|
||||
ctx.ServerError("LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
@@ -289,7 +289,7 @@ func NewRelease(ctx *context.Context) {
|
||||
|
||||
if rel != nil {
|
||||
rel.Repo = ctx.Repo.Repository
|
||||
if err := rel.LoadAttributes(); err != nil {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
ctx.ServerError("LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
@@ -454,7 +454,7 @@ func EditRelease(ctx *context.Context) {
|
||||
ctx.Data["IsDraft"] = rel.IsDraft
|
||||
|
||||
rel.Repo = ctx.Repo.Repository
|
||||
if err := rel.LoadAttributes(); err != nil {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
ctx.ServerError("LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
|
@@ -540,7 +540,7 @@ func SearchRepo(ctx *context.Context) {
|
||||
}
|
||||
|
||||
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,
|
||||
|
@@ -124,7 +124,7 @@ func DeleteProtectedTagPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := git_model.DeleteProtectedTag(pt); err != nil {
|
||||
if err := git_model.DeleteProtectedTag(ctx, pt); err != nil {
|
||||
ctx.ServerError("DeleteProtectedTag", err)
|
||||
return
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func setTagsContext(ctx *context.Context) error {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.settings")
|
||||
ctx.Data["PageIsSettingsTags"] = true
|
||||
|
||||
protectedTags, err := git_model.GetProtectedTags(ctx.Repo.Repository.ID)
|
||||
protectedTags, err := git_model.GetProtectedTags(ctx, ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProtectedTags", err)
|
||||
return err
|
||||
|
@@ -706,7 +706,7 @@ func NewWikiPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyNewWikiPage(ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)
|
||||
notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)
|
||||
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(wikiName))
|
||||
}
|
||||
@@ -750,7 +750,7 @@ func EditWikiPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyEditWikiPage(ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)
|
||||
notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)
|
||||
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(newWikiName))
|
||||
}
|
||||
@@ -767,7 +767,7 @@ func DeleteWikiPagePost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyDeleteWikiPage(ctx.Doer, ctx.Repo.Repository, wikiName)
|
||||
notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName)
|
||||
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": ctx.Repo.RepoLink + "/wiki/",
|
||||
|
@@ -202,7 +202,7 @@ func Milestones(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
showRepos, _, err := repo_model.SearchRepositoryByCondition(&repoOpts, userRepoCond, false)
|
||||
showRepos, _, err := repo_model.SearchRepositoryByCondition(ctx, &repoOpts, userRepoCond, false)
|
||||
if err != nil {
|
||||
ctx.ServerError("SearchRepositoryByCondition", err)
|
||||
return
|
||||
@@ -461,7 +461,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
// USING NON-FINAL STATE OF opts FOR A QUERY.
|
||||
var issueCountByRepo map[int64]int64
|
||||
if !forceEmpty {
|
||||
issueCountByRepo, err = issues_model.CountIssuesByRepo(opts)
|
||||
issueCountByRepo, err = issues_model.CountIssuesByRepo(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.ServerError("CountIssuesByRepo", err)
|
||||
return
|
||||
@@ -504,7 +504,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
// USING FINAL STATE OF opts FOR A QUERY.
|
||||
var issues []*issues_model.Issue
|
||||
if !forceEmpty {
|
||||
issues, err = issues_model.Issues(opts)
|
||||
issues, err = issues_model.Issues(ctx, opts)
|
||||
if err != nil {
|
||||
ctx.ServerError("Issues", err)
|
||||
return
|
||||
|
@@ -33,20 +33,20 @@ const (
|
||||
)
|
||||
|
||||
// GetNotificationCount is the middleware that sets the notification count in the context
|
||||
func GetNotificationCount(c *context.Context) {
|
||||
if strings.HasPrefix(c.Req.URL.Path, "/api") {
|
||||
func GetNotificationCount(ctx *context.Context) {
|
||||
if strings.HasPrefix(ctx.Req.URL.Path, "/api") {
|
||||
return
|
||||
}
|
||||
|
||||
if !c.IsSigned {
|
||||
if !ctx.IsSigned {
|
||||
return
|
||||
}
|
||||
|
||||
c.Data["NotificationUnreadCount"] = func() int64 {
|
||||
count, err := activities_model.GetNotificationCount(c, c.Doer, activities_model.NotificationStatusUnread)
|
||||
ctx.Data["NotificationUnreadCount"] = func() int64 {
|
||||
count, err := activities_model.GetNotificationCount(ctx, ctx.Doer, activities_model.NotificationStatusUnread)
|
||||
if err != nil {
|
||||
if err != goctx.Canceled {
|
||||
log.Error("Unable to GetNotificationCount for user:%-v: %v", c.Doer, err)
|
||||
log.Error("Unable to GetNotificationCount for user:%-v: %v", ctx.Doer, err)
|
||||
}
|
||||
return -1
|
||||
}
|
||||
@@ -56,25 +56,25 @@ func GetNotificationCount(c *context.Context) {
|
||||
}
|
||||
|
||||
// Notifications is the notifications page
|
||||
func Notifications(c *context.Context) {
|
||||
getNotifications(c)
|
||||
if c.Written() {
|
||||
func Notifications(ctx *context.Context) {
|
||||
getNotifications(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
if c.FormBool("div-only") {
|
||||
c.Data["SequenceNumber"] = c.FormString("sequence-number")
|
||||
c.HTML(http.StatusOK, tplNotificationDiv)
|
||||
if ctx.FormBool("div-only") {
|
||||
ctx.Data["SequenceNumber"] = ctx.FormString("sequence-number")
|
||||
ctx.HTML(http.StatusOK, tplNotificationDiv)
|
||||
return
|
||||
}
|
||||
c.HTML(http.StatusOK, tplNotification)
|
||||
ctx.HTML(http.StatusOK, tplNotification)
|
||||
}
|
||||
|
||||
func getNotifications(c *context.Context) {
|
||||
func getNotifications(ctx *context.Context) {
|
||||
var (
|
||||
keyword = c.FormTrim("q")
|
||||
keyword = ctx.FormTrim("q")
|
||||
status activities_model.NotificationStatus
|
||||
page = c.FormInt("page")
|
||||
perPage = c.FormInt("perPage")
|
||||
page = ctx.FormInt("page")
|
||||
perPage = ctx.FormInt("perPage")
|
||||
)
|
||||
if page < 1 {
|
||||
page = 1
|
||||
@@ -90,74 +90,74 @@ func getNotifications(c *context.Context) {
|
||||
status = activities_model.NotificationStatusUnread
|
||||
}
|
||||
|
||||
total, err := activities_model.GetNotificationCount(c, c.Doer, status)
|
||||
total, err := activities_model.GetNotificationCount(ctx, ctx.Doer, status)
|
||||
if err != nil {
|
||||
c.ServerError("ErrGetNotificationCount", err)
|
||||
ctx.ServerError("ErrGetNotificationCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
// redirect to last page if request page is more than total pages
|
||||
pager := context.NewPagination(int(total), perPage, page, 5)
|
||||
if pager.Paginater.Current() < page {
|
||||
c.Redirect(fmt.Sprintf("%s/notifications?q=%s&page=%d", setting.AppSubURL, url.QueryEscape(c.FormString("q")), pager.Paginater.Current()))
|
||||
ctx.Redirect(fmt.Sprintf("%s/notifications?q=%s&page=%d", setting.AppSubURL, url.QueryEscape(ctx.FormString("q")), pager.Paginater.Current()))
|
||||
return
|
||||
}
|
||||
|
||||
statuses := []activities_model.NotificationStatus{status, activities_model.NotificationStatusPinned}
|
||||
notifications, err := activities_model.NotificationsForUser(c, c.Doer, statuses, page, perPage)
|
||||
notifications, err := activities_model.NotificationsForUser(ctx, ctx.Doer, statuses, page, perPage)
|
||||
if err != nil {
|
||||
c.ServerError("ErrNotificationsForUser", err)
|
||||
ctx.ServerError("ErrNotificationsForUser", err)
|
||||
return
|
||||
}
|
||||
|
||||
failCount := 0
|
||||
|
||||
repos, failures, err := notifications.LoadRepos()
|
||||
repos, failures, err := notifications.LoadRepos(ctx)
|
||||
if err != nil {
|
||||
c.ServerError("LoadRepos", err)
|
||||
ctx.ServerError("LoadRepos", err)
|
||||
return
|
||||
}
|
||||
notifications = notifications.Without(failures)
|
||||
if err := repos.LoadAttributes(); err != nil {
|
||||
c.ServerError("LoadAttributes", err)
|
||||
if err := repos.LoadAttributes(); err != nil { // TODO
|
||||
ctx.ServerError("LoadAttributes", err)
|
||||
return
|
||||
}
|
||||
failCount += len(failures)
|
||||
|
||||
failures, err = notifications.LoadIssues()
|
||||
failures, err = notifications.LoadIssues(ctx)
|
||||
if err != nil {
|
||||
c.ServerError("LoadIssues", err)
|
||||
ctx.ServerError("LoadIssues", err)
|
||||
return
|
||||
}
|
||||
notifications = notifications.Without(failures)
|
||||
failCount += len(failures)
|
||||
|
||||
failures, err = notifications.LoadComments()
|
||||
failures, err = notifications.LoadComments(ctx)
|
||||
if err != nil {
|
||||
c.ServerError("LoadComments", err)
|
||||
ctx.ServerError("LoadComments", err)
|
||||
return
|
||||
}
|
||||
notifications = notifications.Without(failures)
|
||||
failCount += len(failures)
|
||||
|
||||
if failCount > 0 {
|
||||
c.Flash.Error(fmt.Sprintf("ERROR: %d notifications were removed due to missing parts - check the logs", failCount))
|
||||
ctx.Flash.Error(fmt.Sprintf("ERROR: %d notifications were removed due to missing parts - check the logs", failCount))
|
||||
}
|
||||
|
||||
c.Data["Title"] = c.Tr("notifications")
|
||||
c.Data["Keyword"] = keyword
|
||||
c.Data["Status"] = status
|
||||
c.Data["Notifications"] = notifications
|
||||
ctx.Data["Title"] = ctx.Tr("notifications")
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Status"] = status
|
||||
ctx.Data["Notifications"] = notifications
|
||||
|
||||
pager.SetDefaultParams(c)
|
||||
c.Data["Page"] = pager
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
}
|
||||
|
||||
// NotificationStatusPost is a route for changing the status of a notification
|
||||
func NotificationStatusPost(c *context.Context) {
|
||||
func NotificationStatusPost(ctx *context.Context) {
|
||||
var (
|
||||
notificationID = c.FormInt64("notification_id")
|
||||
statusStr = c.FormString("status")
|
||||
notificationID = ctx.FormInt64("notification_id")
|
||||
statusStr = ctx.FormString("status")
|
||||
status activities_model.NotificationStatus
|
||||
)
|
||||
|
||||
@@ -169,56 +169,56 @@ func NotificationStatusPost(c *context.Context) {
|
||||
case "pinned":
|
||||
status = activities_model.NotificationStatusPinned
|
||||
default:
|
||||
c.ServerError("InvalidNotificationStatus", errors.New("Invalid notification status"))
|
||||
ctx.ServerError("InvalidNotificationStatus", errors.New("Invalid notification status"))
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := activities_model.SetNotificationStatus(notificationID, c.Doer, status); err != nil {
|
||||
c.ServerError("SetNotificationStatus", err)
|
||||
if _, err := activities_model.SetNotificationStatus(ctx, notificationID, ctx.Doer, status); err != nil {
|
||||
ctx.ServerError("SetNotificationStatus", err)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.FormBool("noredirect") {
|
||||
url := fmt.Sprintf("%s/notifications?page=%s", setting.AppSubURL, url.QueryEscape(c.FormString("page")))
|
||||
c.Redirect(url, http.StatusSeeOther)
|
||||
if !ctx.FormBool("noredirect") {
|
||||
url := fmt.Sprintf("%s/notifications?page=%s", setting.AppSubURL, url.QueryEscape(ctx.FormString("page")))
|
||||
ctx.Redirect(url, http.StatusSeeOther)
|
||||
}
|
||||
|
||||
getNotifications(c)
|
||||
if c.Written() {
|
||||
getNotifications(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
c.Data["Link"] = setting.AppURL + "notifications"
|
||||
c.Data["SequenceNumber"] = c.Req.PostFormValue("sequence-number")
|
||||
ctx.Data["Link"] = setting.AppURL + "notifications"
|
||||
ctx.Data["SequenceNumber"] = ctx.Req.PostFormValue("sequence-number")
|
||||
|
||||
c.HTML(http.StatusOK, tplNotificationDiv)
|
||||
ctx.HTML(http.StatusOK, tplNotificationDiv)
|
||||
}
|
||||
|
||||
// NotificationPurgePost is a route for 'purging' the list of notifications - marking all unread as read
|
||||
func NotificationPurgePost(c *context.Context) {
|
||||
err := activities_model.UpdateNotificationStatuses(c.Doer, activities_model.NotificationStatusUnread, activities_model.NotificationStatusRead)
|
||||
func NotificationPurgePost(ctx *context.Context) {
|
||||
err := activities_model.UpdateNotificationStatuses(ctx, ctx.Doer, activities_model.NotificationStatusUnread, activities_model.NotificationStatusRead)
|
||||
if err != nil {
|
||||
c.ServerError("ErrUpdateNotificationStatuses", err)
|
||||
ctx.ServerError("UpdateNotificationStatuses", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.Redirect(setting.AppSubURL+"/notifications", http.StatusSeeOther)
|
||||
ctx.Redirect(setting.AppSubURL+"/notifications", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// NotificationSubscriptions returns the list of subscribed issues
|
||||
func NotificationSubscriptions(c *context.Context) {
|
||||
page := c.FormInt("page")
|
||||
func NotificationSubscriptions(ctx *context.Context) {
|
||||
page := ctx.FormInt("page")
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
sortType := c.FormString("sort")
|
||||
c.Data["SortType"] = sortType
|
||||
sortType := ctx.FormString("sort")
|
||||
ctx.Data["SortType"] = sortType
|
||||
|
||||
state := c.FormString("state")
|
||||
state := ctx.FormString("state")
|
||||
if !util.IsStringInSlice(state, []string{"all", "open", "closed"}, true) {
|
||||
state = "all"
|
||||
}
|
||||
c.Data["State"] = state
|
||||
ctx.Data["State"] = state
|
||||
var showClosed util.OptionalBool
|
||||
switch state {
|
||||
case "all":
|
||||
@@ -230,7 +230,7 @@ func NotificationSubscriptions(c *context.Context) {
|
||||
}
|
||||
|
||||
var issueTypeBool util.OptionalBool
|
||||
issueType := c.FormString("issueType")
|
||||
issueType := ctx.FormString("issueType")
|
||||
switch issueType {
|
||||
case "issues":
|
||||
issueTypeBool = util.OptionalBoolFalse
|
||||
@@ -239,71 +239,71 @@ func NotificationSubscriptions(c *context.Context) {
|
||||
default:
|
||||
issueTypeBool = util.OptionalBoolNone
|
||||
}
|
||||
c.Data["IssueType"] = issueType
|
||||
ctx.Data["IssueType"] = issueType
|
||||
|
||||
var labelIDs []int64
|
||||
selectedLabels := c.FormString("labels")
|
||||
c.Data["Labels"] = selectedLabels
|
||||
selectedLabels := ctx.FormString("labels")
|
||||
ctx.Data["Labels"] = selectedLabels
|
||||
if len(selectedLabels) > 0 && selectedLabels != "0" {
|
||||
var err error
|
||||
labelIDs, err = base.StringsToInt64s(strings.Split(selectedLabels, ","))
|
||||
if err != nil {
|
||||
c.ServerError("StringsToInt64s", err)
|
||||
ctx.ServerError("StringsToInt64s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
count, err := issues_model.CountIssues(&issues_model.IssuesOptions{
|
||||
SubscriberID: c.Doer.ID,
|
||||
count, err := issues_model.CountIssues(ctx, &issues_model.IssuesOptions{
|
||||
SubscriberID: ctx.Doer.ID,
|
||||
IsClosed: showClosed,
|
||||
IsPull: issueTypeBool,
|
||||
LabelIDs: labelIDs,
|
||||
})
|
||||
if err != nil {
|
||||
c.ServerError("CountIssues", err)
|
||||
ctx.ServerError("CountIssues", err)
|
||||
return
|
||||
}
|
||||
issues, err := issues_model.Issues(&issues_model.IssuesOptions{
|
||||
issues, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: setting.UI.IssuePagingNum,
|
||||
Page: page,
|
||||
},
|
||||
SubscriberID: c.Doer.ID,
|
||||
SubscriberID: ctx.Doer.ID,
|
||||
SortType: sortType,
|
||||
IsClosed: showClosed,
|
||||
IsPull: issueTypeBool,
|
||||
LabelIDs: labelIDs,
|
||||
})
|
||||
if err != nil {
|
||||
c.ServerError("Issues", err)
|
||||
ctx.ServerError("Issues", err)
|
||||
return
|
||||
}
|
||||
|
||||
commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(c, issues)
|
||||
commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues)
|
||||
if err != nil {
|
||||
c.ServerError("GetIssuesAllCommitStatus", err)
|
||||
ctx.ServerError("GetIssuesAllCommitStatus", err)
|
||||
return
|
||||
}
|
||||
c.Data["CommitLastStatus"] = lastStatus
|
||||
c.Data["CommitStatuses"] = commitStatuses
|
||||
c.Data["Issues"] = issues
|
||||
ctx.Data["CommitLastStatus"] = lastStatus
|
||||
ctx.Data["CommitStatuses"] = commitStatuses
|
||||
ctx.Data["Issues"] = issues
|
||||
|
||||
c.Data["IssueRefEndNames"], c.Data["IssueRefURLs"] = issue_service.GetRefEndNamesAndURLs(issues, "")
|
||||
ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] = issue_service.GetRefEndNamesAndURLs(issues, "")
|
||||
|
||||
commitStatus, err := pull_service.GetIssuesLastCommitStatus(c, issues)
|
||||
commitStatus, err := pull_service.GetIssuesLastCommitStatus(ctx, issues)
|
||||
if err != nil {
|
||||
c.ServerError("GetIssuesLastCommitStatus", err)
|
||||
ctx.ServerError("GetIssuesLastCommitStatus", err)
|
||||
return
|
||||
}
|
||||
c.Data["CommitStatus"] = commitStatus
|
||||
ctx.Data["CommitStatus"] = commitStatus
|
||||
|
||||
issueList := issues_model.IssueList(issues)
|
||||
approvalCounts, err := issueList.GetApprovalCounts(c)
|
||||
approvalCounts, err := issueList.GetApprovalCounts(ctx)
|
||||
if err != nil {
|
||||
c.ServerError("ApprovalCounts", err)
|
||||
ctx.ServerError("ApprovalCounts", err)
|
||||
return
|
||||
}
|
||||
c.Data["ApprovalCounts"] = func(issueID int64, typ string) int64 {
|
||||
ctx.Data["ApprovalCounts"] = func(issueID int64, typ string) int64 {
|
||||
counts, ok := approvalCounts[issueID]
|
||||
if !ok || len(counts) == 0 {
|
||||
return 0
|
||||
@@ -322,32 +322,32 @@ func NotificationSubscriptions(c *context.Context) {
|
||||
return 0
|
||||
}
|
||||
|
||||
c.Data["Status"] = 1
|
||||
c.Data["Title"] = c.Tr("notification.subscriptions")
|
||||
ctx.Data["Status"] = 1
|
||||
ctx.Data["Title"] = ctx.Tr("notification.subscriptions")
|
||||
|
||||
// redirect to last page if request page is more than total pages
|
||||
pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
|
||||
if pager.Paginater.Current() < page {
|
||||
c.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current()))
|
||||
ctx.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current()))
|
||||
return
|
||||
}
|
||||
pager.AddParam(c, "sort", "SortType")
|
||||
pager.AddParam(c, "state", "State")
|
||||
c.Data["Page"] = pager
|
||||
pager.AddParam(ctx, "sort", "SortType")
|
||||
pager.AddParam(ctx, "state", "State")
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
c.HTML(http.StatusOK, tplNotificationSubscriptions)
|
||||
ctx.HTML(http.StatusOK, tplNotificationSubscriptions)
|
||||
}
|
||||
|
||||
// NotificationWatching returns the list of watching repos
|
||||
func NotificationWatching(c *context.Context) {
|
||||
page := c.FormInt("page")
|
||||
func NotificationWatching(ctx *context.Context) {
|
||||
page := ctx.FormInt("page")
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
var orderBy db.SearchOrderBy
|
||||
c.Data["SortType"] = c.FormString("sort")
|
||||
switch c.FormString("sort") {
|
||||
ctx.Data["SortType"] = ctx.FormString("sort")
|
||||
switch ctx.FormString("sort") {
|
||||
case "newest":
|
||||
orderBy = db.SearchOrderByNewest
|
||||
case "oldest":
|
||||
@@ -369,41 +369,41 @@ func NotificationWatching(c *context.Context) {
|
||||
case "fewestforks":
|
||||
orderBy = db.SearchOrderByForks
|
||||
default:
|
||||
c.Data["SortType"] = "recentupdate"
|
||||
ctx.Data["SortType"] = "recentupdate"
|
||||
orderBy = db.SearchOrderByRecentUpdated
|
||||
}
|
||||
|
||||
repos, count, err := repo_model.SearchRepository(&repo_model.SearchRepoOptions{
|
||||
repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
Page: page,
|
||||
},
|
||||
Actor: c.Doer,
|
||||
Keyword: c.FormTrim("q"),
|
||||
Actor: ctx.Doer,
|
||||
Keyword: ctx.FormTrim("q"),
|
||||
OrderBy: orderBy,
|
||||
Private: c.IsSigned,
|
||||
WatchedByID: c.Doer.ID,
|
||||
Private: ctx.IsSigned,
|
||||
WatchedByID: ctx.Doer.ID,
|
||||
Collaborate: util.OptionalBoolFalse,
|
||||
TopicOnly: c.FormBool("topic"),
|
||||
TopicOnly: ctx.FormBool("topic"),
|
||||
IncludeDescription: setting.UI.SearchRepoDescription,
|
||||
})
|
||||
if err != nil {
|
||||
c.ServerError("ErrSearchRepository", err)
|
||||
ctx.ServerError("SearchRepository", err)
|
||||
return
|
||||
}
|
||||
total := int(count)
|
||||
c.Data["Total"] = total
|
||||
c.Data["Repos"] = repos
|
||||
ctx.Data["Total"] = total
|
||||
ctx.Data["Repos"] = repos
|
||||
|
||||
// redirect to last page if request page is more than total pages
|
||||
pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5)
|
||||
pager.SetDefaultParams(c)
|
||||
c.Data["Page"] = pager
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
c.Data["Status"] = 2
|
||||
c.Data["Title"] = c.Tr("notification.watching")
|
||||
ctx.Data["Status"] = 2
|
||||
ctx.Data["Title"] = ctx.Tr("notification.watching")
|
||||
|
||||
c.HTML(http.StatusOK, tplNotificationSubscriptions)
|
||||
ctx.HTML(http.StatusOK, tplNotificationSubscriptions)
|
||||
}
|
||||
|
||||
// NewAvailable returns the notification counts
|
||||
|
@@ -203,7 +203,7 @@ func Profile(ctx *context.Context) {
|
||||
}
|
||||
case "stars":
|
||||
ctx.Data["PageIsProfileStarList"] = true
|
||||
repos, count, err = repo_model.SearchRepository(&repo_model.SearchRepoOptions{
|
||||
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
Page: page,
|
||||
@@ -235,7 +235,7 @@ func Profile(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
case "watching":
|
||||
repos, count, err = repo_model.SearchRepository(&repo_model.SearchRepoOptions{
|
||||
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
Page: page,
|
||||
@@ -257,7 +257,7 @@ func Profile(ctx *context.Context) {
|
||||
|
||||
total = int(count)
|
||||
default:
|
||||
repos, count, err = repo_model.SearchRepository(&repo_model.SearchRepoOptions{
|
||||
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: setting.UI.User.RepoPagingNum,
|
||||
Page: page,
|
||||
|
Reference in New Issue
Block a user