mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions
This commit is contained in:
@@ -64,7 +64,7 @@ func uploadAttachment(ctx *context.Context, repoID int64, allowedTypes string) {
|
||||
// DeleteAttachment response for deleting issue's attachment
|
||||
func DeleteAttachment(ctx *context.Context) {
|
||||
file := ctx.FormString("file")
|
||||
attach, err := repo_model.GetAttachmentByUUID(file)
|
||||
attach, err := repo_model.GetAttachmentByUUID(ctx, file)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
@@ -85,7 +85,7 @@ func DeleteAttachment(ctx *context.Context) {
|
||||
|
||||
// GetAttachment serve attachements
|
||||
func GetAttachment(ctx *context.Context) {
|
||||
attach, err := repo_model.GetAttachmentByUUID(ctx.Params(":uuid"))
|
||||
attach, err := repo_model.GetAttachmentByUUID(ctx, ctx.Params(":uuid"))
|
||||
if err != nil {
|
||||
if repo_model.IsErrAttachmentNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
|
@@ -335,7 +335,7 @@ func Diff(ctx *context.Context) {
|
||||
ctx.Data["Commit"] = commit
|
||||
ctx.Data["Diff"] = diff
|
||||
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, commitID, db.ListOptions{})
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptions{})
|
||||
if err != nil {
|
||||
log.Error("GetLatestCommitStatus: %v", err)
|
||||
}
|
||||
|
@@ -254,7 +254,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
|
||||
} else if len(headInfos) == 2 {
|
||||
headInfosSplit := strings.Split(headInfos[0], "/")
|
||||
if len(headInfosSplit) == 1 {
|
||||
ci.HeadUser, err = user_model.GetUserByName(headInfos[0])
|
||||
ci.HeadUser, err = user_model.GetUserByName(ctx, headInfos[0])
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.NotFound("GetUserByName", nil)
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -130,7 +130,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
|
||||
var comment *models.Comment
|
||||
if history.CommentID != 0 {
|
||||
var err error
|
||||
if comment, err = models.GetCommentByID(history.CommentID); err != nil {
|
||||
if comment, err = models.GetCommentByID(ctx, history.CommentID); err != nil {
|
||||
log.Error("can not get comment for issue content history %v. err=%v", historyID, err)
|
||||
return
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func SoftDeleteContentHistory(ctx *context.Context) {
|
||||
var history *issuesModel.ContentHistory
|
||||
var err error
|
||||
if commentID != 0 {
|
||||
if comment, err = models.GetCommentByID(commentID); err != nil {
|
||||
if comment, err = models.GetCommentByID(ctx, commentID); err != nil {
|
||||
log.Error("can not get comment for issue content history %v. err=%v", historyID, err)
|
||||
return
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ func InitializeLabels(ctx *context.Context) {
|
||||
|
||||
// RetrieveLabels find all the labels of a repository and organization
|
||||
func RetrieveLabels(ctx *context.Context) {
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
labels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("RetrieveLabels.GetLabels", err)
|
||||
return
|
||||
@@ -69,7 +69,7 @@ func RetrieveLabels(ctx *context.Context) {
|
||||
ctx.Data["Labels"] = labels
|
||||
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
orgLabels, err := models.GetLabelsByOrgID(ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
orgLabels, err := models.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLabelsByOrgID", err)
|
||||
return
|
||||
@@ -127,7 +127,7 @@ func NewLabel(ctx *context.Context) {
|
||||
// UpdateLabel update a label's name and color
|
||||
func UpdateLabel(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateLabelForm)
|
||||
l, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, form.ID)
|
||||
l, err := models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, form.ID)
|
||||
if err != nil {
|
||||
switch {
|
||||
case models.IsErrRepoLabelNotExist(err):
|
||||
@@ -177,7 +177,7 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
case "attach", "detach", "toggle":
|
||||
label, err := models.GetLabelByID(ctx.FormInt64("id"))
|
||||
label, err := models.GetLabelByID(ctx, ctx.FormInt64("id"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoLabelNotExist(err) {
|
||||
ctx.Error(http.StatusNotFound, "GetLabelByID")
|
||||
@@ -191,7 +191,7 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||
// detach if any issues already have label, otherwise attach
|
||||
action = "attach"
|
||||
for _, issue := range issues {
|
||||
if models.HasIssueLabel(issue.ID, label.ID) {
|
||||
if models.HasIssueLabel(ctx, issue.ID, label.ID) {
|
||||
action = "detach"
|
||||
break
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@ func GetActiveStopwatch(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
_, sw, err := models.HasUserStopwatch(ctx.Doer.ID)
|
||||
_, sw, err := models.HasUserStopwatch(ctx, ctx.Doer.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("HasUserStopwatch", err)
|
||||
return
|
||||
|
@@ -70,7 +70,7 @@ func Projects(ctx *context.Context) {
|
||||
total = repo.NumClosedProjects
|
||||
}
|
||||
|
||||
projects, count, err := project_model.GetProjects(project_model.SearchOptions{
|
||||
projects, count, err := project_model.GetProjects(ctx, project_model.SearchOptions{
|
||||
RepoID: repo.ID,
|
||||
Page: page,
|
||||
IsClosed: util.OptionalBoolOf(isShowClosed),
|
||||
@@ -182,7 +182,7 @@ func ChangeProjectStatus(ctx *context.Context) {
|
||||
|
||||
// DeleteProject delete a project
|
||||
func DeleteProject(ctx *context.Context) {
|
||||
p, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
@@ -213,7 +213,7 @@ func EditProject(ctx *context.Context) {
|
||||
ctx.Data["PageIsEditProjects"] = true
|
||||
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
|
||||
|
||||
p, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
@@ -245,7 +245,7 @@ func EditProjectPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
p, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
p, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
@@ -261,7 +261,7 @@ func EditProjectPost(ctx *context.Context) {
|
||||
|
||||
p.Title = form.Title
|
||||
p.Description = form.Content
|
||||
if err = project_model.UpdateProject(p); err != nil {
|
||||
if err = project_model.UpdateProject(ctx, p); err != nil {
|
||||
ctx.ServerError("UpdateProjects", err)
|
||||
return
|
||||
}
|
||||
@@ -272,7 +272,7 @@ func EditProjectPost(ctx *context.Context) {
|
||||
|
||||
// ViewProject renders the project board for a project
|
||||
func ViewProject(ctx *context.Context) {
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
@@ -286,7 +286,7 @@ func ViewProject(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
boards, err := project_model.GetBoards(project.ID)
|
||||
boards, err := project_model.GetBoards(ctx, project.ID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectBoards", err)
|
||||
return
|
||||
@@ -385,7 +385,7 @@ func DeleteProjectBoard(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
@@ -395,7 +395,7 @@ func DeleteProjectBoard(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pb, err := project_model.GetBoard(ctx.ParamsInt64(":boardID"))
|
||||
pb, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectBoard", err)
|
||||
return
|
||||
@@ -434,7 +434,7 @@ func AddBoardToProjectPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
@@ -474,7 +474,7 @@ func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Pr
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("", nil)
|
||||
@@ -484,7 +484,7 @@ func checkProjectBoardChangePermissions(ctx *context.Context) (*project_model.Pr
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
board, err := project_model.GetBoard(ctx.ParamsInt64(":boardID"))
|
||||
board, err := project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetProjectBoard", err)
|
||||
return nil, nil
|
||||
@@ -523,7 +523,7 @@ func EditProjectBoard(ctx *context.Context) {
|
||||
board.Sorting = form.Sorting
|
||||
}
|
||||
|
||||
if err := project_model.UpdateBoard(board); err != nil {
|
||||
if err := project_model.UpdateBoard(ctx, board); err != nil {
|
||||
ctx.ServerError("UpdateProjectBoard", err)
|
||||
return
|
||||
}
|
||||
@@ -566,7 +566,7 @@ func MoveIssues(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
project, err := project_model.GetProjectByID(ctx.ParamsInt64(":id"))
|
||||
project, err := project_model.GetProjectByID(ctx, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectNotExist(err) {
|
||||
ctx.NotFound("ProjectNotExist", nil)
|
||||
@@ -589,7 +589,7 @@ func MoveIssues(ctx *context.Context) {
|
||||
Title: ctx.Tr("repo.projects.type.uncategorized"),
|
||||
}
|
||||
} else {
|
||||
board, err = project_model.GetBoard(ctx.ParamsInt64(":boardID"))
|
||||
board, err = project_model.GetBoard(ctx, ctx.ParamsInt64(":boardID"))
|
||||
if err != nil {
|
||||
if project_model.IsErrProjectBoardNotExist(err) {
|
||||
ctx.NotFound("ProjectBoardNotExist", nil)
|
||||
@@ -622,7 +622,7 @@ func MoveIssues(ctx *context.Context) {
|
||||
issueIDs = append(issueIDs, issue.IssueID)
|
||||
sortedIssueIDs[issue.Sorting] = issue.IssueID
|
||||
}
|
||||
movedIssues, err := models.GetIssuesByIDs(issueIDs)
|
||||
movedIssues, err := models.GetIssuesByIDs(ctx, issueIDs)
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.NotFound("IssueNotExisting", nil)
|
||||
|
@@ -377,7 +377,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
|
||||
|
||||
if len(compareInfo.Commits) != 0 {
|
||||
sha := compareInfo.Commits[0].ID.String()
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, sha, db.ListOptions{})
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLatestCommitStatus", err)
|
||||
return nil
|
||||
@@ -438,7 +438,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
||||
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
|
||||
return nil
|
||||
}
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(repo.ID, sha, db.ListOptions{})
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLatestCommitStatus", err)
|
||||
return nil
|
||||
@@ -528,7 +528,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
|
||||
return nil
|
||||
}
|
||||
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(repo.ID, sha, db.ListOptions{})
|
||||
commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetLatestCommitStatus", err)
|
||||
return nil
|
||||
@@ -767,7 +767,7 @@ func ViewPullFiles(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
currentReview, err := models.GetCurrentReview(ctx.Doer, issue)
|
||||
currentReview, err := models.GetCurrentReview(ctx, ctx.Doer, issue)
|
||||
if err != nil && !models.IsErrReviewNotExist(err) {
|
||||
ctx.ServerError("GetCurrentReview", err)
|
||||
return
|
||||
@@ -1354,7 +1354,7 @@ func DownloadPullPatch(ctx *context.Context) {
|
||||
|
||||
// DownloadPullDiffOrPatch render a pull's raw diff or patch
|
||||
func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
@@ -1447,7 +1447,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
|
||||
func SetAllowEdits(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.UpdateAllowEditsForm)
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
ctx.NotFound("GetPullRequestByIndex", err)
|
||||
|
@@ -31,7 +31,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
|
||||
if !issue.IsPull {
|
||||
return
|
||||
}
|
||||
currentReview, err := models.GetCurrentReview(ctx.Doer, issue)
|
||||
currentReview, err := models.GetCurrentReview(ctx, ctx.Doer, issue)
|
||||
if err != nil && !models.IsErrReviewNotExist(err) {
|
||||
ctx.ServerError("GetCurrentReview", err)
|
||||
return
|
||||
@@ -107,7 +107,7 @@ func UpdateResolveConversation(ctx *context.Context) {
|
||||
action := ctx.FormString("action")
|
||||
commentID := ctx.FormInt64("comment_id")
|
||||
|
||||
comment, err := models.GetCommentByID(commentID)
|
||||
comment, err := models.GetCommentByID(ctx, commentID)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetIssueByID", err)
|
||||
return
|
||||
|
@@ -126,7 +126,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
|
||||
return
|
||||
}
|
||||
|
||||
if err = models.GetReleaseAttachments(releases...); err != nil {
|
||||
if err = models.GetReleaseAttachments(ctx, releases...); err != nil {
|
||||
ctx.ServerError("GetReleaseAttachments", err)
|
||||
return
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func SingleRelease(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = models.GetReleaseAttachments(release)
|
||||
err = models.GetReleaseAttachments(ctx, release)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetReleaseAttachments", err)
|
||||
return
|
||||
|
@@ -285,9 +285,9 @@ func Action(ctx *context.Context) {
|
||||
var err error
|
||||
switch ctx.Params(":action") {
|
||||
case "watch":
|
||||
err = repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
case "unwatch":
|
||||
err = repo_model.WatchRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
||||
case "star":
|
||||
err = repo_model.StarRepo(ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
||||
case "unstar":
|
||||
@@ -369,7 +369,7 @@ func RedirectDownload(ctx *context.Context) {
|
||||
}
|
||||
if len(releases) == 1 {
|
||||
release := releases[0]
|
||||
att, err := repo_model.GetAttachmentByReleaseIDFileName(release.ID, fileName)
|
||||
att, err := repo_model.GetAttachmentByReleaseIDFileName(ctx, release.ID, fileName)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusNotFound)
|
||||
return
|
||||
|
@@ -72,14 +72,14 @@ func Settings(ctx *context.Context) {
|
||||
ctx.Data["CodeIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
||||
if ctx.Doer.IsAdmin {
|
||||
if setting.Indexer.RepoIndexerEnabled {
|
||||
status, err := repo_model.GetIndexerStatus(ctx.Repo.Repository, repo_model.RepoIndexerTypeCode)
|
||||
status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeCode)
|
||||
if err != nil {
|
||||
ctx.ServerError("repo.indexer_status", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["CodeIndexerStatus"] = status
|
||||
}
|
||||
status, err := repo_model.GetIndexerStatus(ctx.Repo.Repository, repo_model.RepoIndexerTypeStats)
|
||||
status, err := repo_model.GetIndexerStatus(ctx, ctx.Repo.Repository, repo_model.RepoIndexerTypeStats)
|
||||
if err != nil {
|
||||
ctx.ServerError("repo.indexer_status", err)
|
||||
return
|
||||
@@ -195,7 +195,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
|
||||
ctx.Repo.Mirror.Interval = interval
|
||||
ctx.Repo.Mirror.ScheduleNextUpdate()
|
||||
if err := repo_model.UpdateMirror(ctx.Repo.Mirror); err != nil {
|
||||
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
|
||||
ctx.Data["Err_Interval"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
|
||||
return
|
||||
@@ -241,7 +241,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
|
||||
ctx.Repo.Mirror.LFS = form.LFS
|
||||
ctx.Repo.Mirror.LFSEndpoint = form.LFSEndpoint
|
||||
if err := repo_model.UpdateMirror(ctx.Repo.Mirror); err != nil {
|
||||
if err := repo_model.UpdateMirror(ctx, ctx.Repo.Mirror); err != nil {
|
||||
ctx.ServerError("UpdateMirror", err)
|
||||
return
|
||||
}
|
||||
@@ -642,7 +642,7 @@ func SettingsPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
newOwner, err := user_model.GetUserByName(ctx.FormString("new_owner_name"))
|
||||
newOwner, err := user_model.GetUserByName(ctx, ctx.FormString("new_owner_name"))
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_owner_name"), tplSettingsOptions, nil)
|
||||
@@ -840,7 +840,7 @@ func Collaboration(ctx *context.Context) {
|
||||
}
|
||||
ctx.Data["Collaborators"] = users
|
||||
|
||||
teams, err := organization.GetRepoTeams(ctx.Repo.Repository)
|
||||
teams, err := organization.GetRepoTeams(ctx, ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetRepoTeams", err)
|
||||
return
|
||||
@@ -863,7 +863,7 @@ func CollaborationPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
u, err := user_model.GetUserByName(name)
|
||||
u, err := user_model.GetUserByName(ctx, name)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
|
||||
@@ -983,7 +983,7 @@ func DeleteTeam(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
team, err := organization.GetTeamByID(ctx.FormInt64("id"))
|
||||
team, err := organization.GetTeamByID(ctx, ctx.FormInt64("id"))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetTeamByID", err)
|
||||
return
|
||||
@@ -1215,6 +1215,7 @@ func selectPushMirrorByForm(form *forms.RepoSettingForm, repo *repo_model.Reposi
|
||||
|
||||
for _, m := range pushMirrors {
|
||||
if m.ID == id {
|
||||
m.Repo = repo
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
|
@@ -111,7 +111,7 @@ func SettingsProtectedBranch(c *context.Context) {
|
||||
c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + branch
|
||||
c.Data["PageIsSettingsBranches"] = true
|
||||
|
||||
protectBranch, err := models.GetProtectedBranchBy(c.Repo.Repository.ID, branch)
|
||||
protectBranch, err := models.GetProtectedBranchBy(c, c.Repo.Repository.ID, branch)
|
||||
if err != nil {
|
||||
if !git.IsErrBranchNotExist(err) {
|
||||
c.ServerError("GetProtectBranchOfRepoByName", err)
|
||||
@@ -184,7 +184,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx.Repo.Repository.ID, branch)
|
||||
protectBranch, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch)
|
||||
if err != nil {
|
||||
if !git.IsErrBranchNotExist(err) {
|
||||
ctx.ServerError("GetProtectBranchOfRepoByName", err)
|
||||
|
@@ -684,7 +684,7 @@ func checkHomeCodeViewable(ctx *context.Context) {
|
||||
|
||||
if ctx.IsSigned {
|
||||
// Set repo notification-status read if unread
|
||||
if err := models.SetRepoReadBy(ctx.Repo.Repository.ID, ctx.Doer.ID); err != nil {
|
||||
if err := models.SetRepoReadBy(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID); err != nil {
|
||||
ctx.ServerError("ReadBy", err)
|
||||
return
|
||||
}
|
||||
@@ -839,7 +839,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
|
||||
ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(latestCommit)
|
||||
}
|
||||
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
|
||||
statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{})
|
||||
if err != nil {
|
||||
log.Error("GetLatestCommitStatus: %v", err)
|
||||
}
|
||||
@@ -901,7 +901,7 @@ func renderCode(ctx *context.Context) {
|
||||
// it's possible for a repository to be non-empty by that flag but still 500
|
||||
// because there are no branches - only tags -or the default branch is non-extant as it has been 0-pushed.
|
||||
ctx.Repo.Repository.IsEmpty = false
|
||||
if err = repo_model.UpdateRepositoryCols(ctx.Repo.Repository, "is_empty"); err != nil {
|
||||
if err = repo_model.UpdateRepositoryCols(ctx, ctx.Repo.Repository, "is_empty"); err != nil {
|
||||
ctx.ServerError("UpdateRepositoryCols", err)
|
||||
return
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ func Webhooks(ctx *context.Context) {
|
||||
ctx.Data["BaseLinkNew"] = ctx.Repo.RepoLink + "/settings/hooks"
|
||||
ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/")
|
||||
|
||||
ws, err := webhook.ListWebhooksByOpts(&webhook.ListWebhookOptions{RepoID: ctx.Repo.Repository.ID})
|
||||
ws, err := webhook.ListWebhooksByOpts(ctx, &webhook.ListWebhookOptions{RepoID: ctx.Repo.Repository.ID})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetWebhooksByRepoID", err)
|
||||
return
|
||||
|
Reference in New Issue
Block a user