aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/issue.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-05-20 22:08:52 +0800
committerGitHub <noreply@github.com>2022-05-20 22:08:52 +0800
commitfd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch)
tree50038348ec10485f72344f3ac80324e04abc1283 /routers/web/repo/issue.go
parentd81e31ad7826a81fc7139f329f250594610a274b (diff)
downloadgitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz
gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions
Diffstat (limited to 'routers/web/repo/issue.go')
-rw-r--r--routers/web/repo/issue.go64
1 files changed, 32 insertions, 32 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index f50b30da1c..079ccbf6cf 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -255,7 +255,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
}
issueList := models.IssueList(issues)
- approvalCounts, err := issueList.GetApprovalCounts()
+ approvalCounts, err := issueList.GetApprovalCounts(ctx)
if err != nil {
ctx.ServerError("ApprovalCounts", err)
return
@@ -294,14 +294,14 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
return
}
- labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
+ labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return
}
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
+ orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
@@ -343,7 +343,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
}
if ctx.Repo.CanWriteIssuesOrPulls(ctx.Params(":type") == "pulls") {
- projects, _, err := project_model.GetProjects(project_model.SearchOptions{
+ projects, _, err := project_model.GetProjects(ctx, project_model.SearchOptions{
RepoID: repo.ID,
Type: project_model.TypeRepository,
IsClosed: util.OptionalBoolOf(isShowClosed),
@@ -453,7 +453,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
var err error
- ctx.Data["OpenProjects"], _, err = project_model.GetProjects(project_model.SearchOptions{
+ ctx.Data["OpenProjects"], _, err = project_model.GetProjects(ctx, project_model.SearchOptions{
RepoID: repo.ID,
Page: -1,
IsClosed: util.OptionalBoolFalse,
@@ -464,7 +464,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
return
}
- ctx.Data["ClosedProjects"], _, err = project_model.GetProjects(project_model.SearchOptions{
+ ctx.Data["ClosedProjects"], _, err = project_model.GetProjects(ctx, project_model.SearchOptions{
RepoID: repo.ID,
Page: -1,
IsClosed: util.OptionalBoolTrue,
@@ -673,14 +673,14 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull
return nil
}
- labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
+ labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return nil
}
ctx.Data["Labels"] = labels
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
+ orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
return nil
}
@@ -761,10 +761,10 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs,
ctx.Data[issueTemplateTitleKey] = meta.Title
ctx.Data[ctxDataKey] = templateBody
labelIDs := make([]string, 0, len(meta.Labels))
- if repoLabels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, "", db.ListOptions{}); err == nil {
+ if repoLabels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, "", db.ListOptions{}); err == nil {
ctx.Data["Labels"] = repoLabels
if ctx.Repo.Owner.IsOrganization() {
- if orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}); err == nil {
+ if orgLabels, err := models.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}); err == nil {
ctx.Data["OrgLabels"] = orgLabels
repoLabels = append(repoLabels, orgLabels...)
}
@@ -818,7 +818,7 @@ func NewIssue(ctx *context.Context) {
projectID := ctx.FormInt64("project")
if projectID > 0 {
- project, err := project_model.GetProjectByID(projectID)
+ project, err := project_model.GetProjectByID(ctx, projectID)
if err != nil {
log.Error("GetProjectByID: %d: %v", projectID, err)
} else if project.RepoID != ctx.Repo.Repository.ID {
@@ -930,7 +930,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
}
if form.ProjectID > 0 {
- p, err := project_model.GetProjectByID(form.ProjectID)
+ p, err := project_model.GetProjectByID(ctx, form.ProjectID)
if err != nil {
ctx.ServerError("GetProjectByID", err)
return nil, nil, 0, 0
@@ -1237,7 +1237,7 @@ func ViewIssue(ctx *context.Context) {
for i := range issue.Labels {
labelIDMark[issue.Labels[i].ID] = true
}
- labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
+ labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return
@@ -1245,7 +1245,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["Labels"] = labels
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
+ orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
@@ -1277,7 +1277,7 @@ func ViewIssue(ctx *context.Context) {
if issue.IsPull {
canChooseReviewer := ctx.Repo.CanWrite(unit.TypePullRequests)
if !canChooseReviewer && ctx.Doer != nil && ctx.IsSigned {
- canChooseReviewer, err = models.IsOfficialReviewer(issue, ctx.Doer)
+ canChooseReviewer, err = models.IsOfficialReviewer(ctx, issue, ctx.Doer)
if err != nil {
ctx.ServerError("IsOfficialReviewer", err)
return
@@ -1312,7 +1312,7 @@ func ViewIssue(ctx *context.Context) {
if !ctx.Data["IsStopwatchRunning"].(bool) {
var exists bool
var sw *models.Stopwatch
- if exists, sw, err = models.HasUserStopwatch(ctx.Doer.ID); err != nil {
+ if exists, sw, err = models.HasUserStopwatch(ctx, ctx.Doer.ID); err != nil {
ctx.ServerError("HasUserStopwatch", err)
return
}
@@ -1688,12 +1688,12 @@ func ViewIssue(ctx *context.Context) {
}
// Get Dependencies
- ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies()
+ ctx.Data["BlockedByDependencies"], err = issue.BlockedByDependencies(ctx)
if err != nil {
ctx.ServerError("BlockedByDependencies", err)
return
}
- ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies()
+ ctx.Data["BlockingDependencies"], err = issue.BlockingDependencies(ctx)
if err != nil {
ctx.ServerError("BlockingDependencies", err)
return
@@ -1767,7 +1767,7 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
}
issueIDs = append(issueIDs, issueID)
}
- issues, err := models.GetIssuesByIDs(issueIDs)
+ issues, err := models.GetIssuesByIDs(ctx, issueIDs)
if err != nil {
ctx.ServerError("GetIssuesByIDs", err)
return nil
@@ -1873,7 +1873,7 @@ func UpdateIssueContent(ctx *context.Context) {
// when update the request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates
if !ctx.FormBool("ignore_attachments") {
- if err := updateAttachments(issue, ctx.FormStrings("files[]")); err != nil {
+ if err := updateAttachments(ctx, issue, ctx.FormStrings("files[]")); err != nil {
ctx.ServerError("UpdateAttachments", err)
return
}
@@ -2047,7 +2047,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
return
}
- team, err := organization.GetTeamByID(-reviewID)
+ team, err := organization.GetTeamByID(ctx, -reviewID)
if err != nil {
ctx.ServerError("GetTeamByID", err)
return
@@ -2160,7 +2160,7 @@ func SearchIssues(ctx *context.Context) {
opts.AllLimited = true
}
if ctx.FormString("owner") != "" {
- owner, err := user_model.GetUserByName(ctx.FormString("owner"))
+ owner, err := user_model.GetUserByName(ctx, ctx.FormString("owner"))
if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusBadRequest, "Owner not found", err.Error())
@@ -2179,7 +2179,7 @@ func SearchIssues(ctx *context.Context) {
ctx.Error(http.StatusBadRequest, "", "Owner organisation is required for filtering on team")
return
}
- team, err := organization.GetTeam(opts.OwnerID, ctx.FormString("team"))
+ team, err := organization.GetTeam(ctx, opts.OwnerID, ctx.FormString("team"))
if err != nil {
if organization.IsErrTeamNotExist(err) {
ctx.Error(http.StatusBadRequest, "Team not found", err.Error())
@@ -2307,7 +2307,7 @@ func getUserIDForFilter(ctx *context.Context, queryName string) int64 {
return 0
}
- user, err := user_model.GetUserByName(userName)
+ user, err := user_model.GetUserByName(ctx, userName)
if user_model.IsErrUserNotExist(err) {
ctx.NotFound("", err)
return 0
@@ -2631,7 +2631,7 @@ func NewComment(ctx *context.Context) {
// UpdateCommentContent change comment of issue's content
func UpdateCommentContent(ctx *context.Context) {
- comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
+ comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
return
@@ -2672,7 +2672,7 @@ func UpdateCommentContent(ctx *context.Context) {
// when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates
if !ctx.FormBool("ignore_attachments") {
- if err := updateAttachments(comment, ctx.FormStrings("files[]")); err != nil {
+ if err := updateAttachments(ctx, comment, ctx.FormStrings("files[]")); err != nil {
ctx.ServerError("UpdateAttachments", err)
return
}
@@ -2697,7 +2697,7 @@ func UpdateCommentContent(ctx *context.Context) {
// DeleteComment delete comment of issue
func DeleteComment(ctx *context.Context) {
- comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
+ comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
return
@@ -2823,7 +2823,7 @@ func ChangeIssueReaction(ctx *context.Context) {
// ChangeCommentReaction create a reaction for comment
func ChangeCommentReaction(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.ReactionForm)
- comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
+ comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
return
@@ -2968,7 +2968,7 @@ func GetIssueAttachments(ctx *context.Context) {
// GetCommentAttachments returns attachments for the comment
func GetCommentAttachments(ctx *context.Context) {
- comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
+ comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
return
@@ -2986,7 +2986,7 @@ func GetCommentAttachments(ctx *context.Context) {
ctx.JSON(http.StatusOK, attachments)
}
-func updateAttachments(item interface{}, files []string) error {
+func updateAttachments(ctx *context.Context, item interface{}, files []string) error {
var attachments []*repo_model.Attachment
switch content := item.(type) {
case *models.Issue:
@@ -3020,9 +3020,9 @@ func updateAttachments(item interface{}, files []string) error {
}
switch content := item.(type) {
case *models.Issue:
- content.Attachments, err = repo_model.GetAttachmentsByIssueID(content.ID)
+ content.Attachments, err = repo_model.GetAttachmentsByIssueID(ctx, content.ID)
case *models.Comment:
- content.Attachments, err = repo_model.GetAttachmentsByCommentID(content.ID)
+ content.Attachments, err = repo_model.GetAttachmentsByCommentID(ctx, content.ID)
default:
return fmt.Errorf("unknown Type: %T", content)
}