Merge branch 'main' into fix-tmpl

This commit is contained in:
wxiaoguang 2024-12-24 21:52:40 +08:00 committed by GitHub
commit a12c2c667b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
105 changed files with 485 additions and 496 deletions

View File

@ -233,72 +233,34 @@ func parseDiffStat(stdout string) (numFiles, totalAdditions, totalDeletions int,
return numFiles, totalAdditions, totalDeletions, err return numFiles, totalAdditions, totalDeletions, err
} }
// GetDiffOrPatch generates either diff or formatted patch data between given revisions
func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, patch, binary bool) error {
if patch {
return repo.GetPatch(base, head, w)
}
if binary {
return repo.GetDiffBinary(base, head, w)
}
return repo.GetDiff(base, head, w)
}
// GetDiff generates and returns patch data between given revisions, optimized for human readability // GetDiff generates and returns patch data between given revisions, optimized for human readability
func (repo *Repository) GetDiff(base, head string, w io.Writer) error { func (repo *Repository) GetDiff(compareArg string, w io.Writer) error {
stderr := new(bytes.Buffer) stderr := new(bytes.Buffer)
err := NewCommand(repo.Ctx, "diff", "-p").AddDynamicArguments(base + "..." + head). return NewCommand(repo.Ctx, "diff", "-p").AddDynamicArguments(compareArg).
Run(&RunOpts{ Run(&RunOpts{
Dir: repo.Path, Dir: repo.Path,
Stdout: w, Stdout: w,
Stderr: stderr, Stderr: stderr,
}) })
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
return NewCommand(repo.Ctx, "diff", "-p").AddDynamicArguments(base, head).
Run(&RunOpts{
Dir: repo.Path,
Stdout: w,
})
}
return err
} }
// GetDiffBinary generates and returns patch data between given revisions, including binary diffs. // GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
func (repo *Repository) GetDiffBinary(base, head string, w io.Writer) error { func (repo *Repository) GetDiffBinary(compareArg string, w io.Writer) error {
stderr := new(bytes.Buffer) return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram").AddDynamicArguments(compareArg).Run(&RunOpts{
err := NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram").AddDynamicArguments(base + "..." + head).
Run(&RunOpts{
Dir: repo.Path,
Stdout: w,
Stderr: stderr,
})
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram").AddDynamicArguments(base, head).
Run(&RunOpts{
Dir: repo.Path, Dir: repo.Path,
Stdout: w, Stdout: w,
}) })
} }
return err
}
// GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply` // GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply`
func (repo *Repository) GetPatch(base, head string, w io.Writer) error { func (repo *Repository) GetPatch(compareArg string, w io.Writer) error {
stderr := new(bytes.Buffer) stderr := new(bytes.Buffer)
err := NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout").AddDynamicArguments(base + "..." + head). return NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout").AddDynamicArguments(compareArg).
Run(&RunOpts{ Run(&RunOpts{
Dir: repo.Path, Dir: repo.Path,
Stdout: w, Stdout: w,
Stderr: stderr, Stderr: stderr,
}) })
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
return NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout").AddDynamicArguments(base, head).
Run(&RunOpts{
Dir: repo.Path,
Stdout: w,
})
}
return err
} }
// GetFilesChangedBetween returns a list of all files that have been changed between the given commits // GetFilesChangedBetween returns a list of all files that have been changed between the given commits
@ -329,21 +291,6 @@ func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, err
return split, err return split, err
} }
// GetDiffFromMergeBase generates and return patch data from merge base to head
func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error {
stderr := new(bytes.Buffer)
err := NewCommand(repo.Ctx, "diff", "-p", "--binary").AddDynamicArguments(base + "..." + head).
Run(&RunOpts{
Dir: repo.Path,
Stdout: w,
Stderr: stderr,
})
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
return repo.GetDiffBinary(base, head, w)
}
return err
}
// ReadPatchCommit will check if a diff patch exists and return stats // ReadPatchCommit will check if a diff patch exists and return stats
func (repo *Repository) ReadPatchCommit(prID int64) (commitSHA string, err error) { func (repo *Repository) ReadPatchCommit(prID int64) (commitSHA string, err error) {
// Migrated repositories download patches to "pulls" location // Migrated repositories download patches to "pulls" location

View File

@ -28,7 +28,7 @@ func TestGetFormatPatch(t *testing.T) {
defer repo.Close() defer repo.Close()
rd := &bytes.Buffer{} rd := &bytes.Buffer{}
err = repo.GetPatch("8d92fc95^", "8d92fc95", rd) err = repo.GetPatch("8d92fc95^...8d92fc95", rd)
if err != nil { if err != nil {
assert.NoError(t, err) assert.NoError(t, err)
return return

View File

@ -235,3 +235,9 @@ func checkOverlappedPath(name, path string) {
} }
configuredPaths[path] = name configuredPaths[path] = name
} }
func PanicInDevOrTesting(msg string, a ...any) {
if !IsProd || IsInTesting {
panic(fmt.Sprintf(msg, a...))
}
}

View File

@ -331,7 +331,5 @@ func QueryBuild(a ...any) template.URL {
} }
func panicIfDevOrTesting() { func panicIfDevOrTesting() {
if !setting.IsProd || setting.IsInTesting { setting.PanicInDevOrTesting("legacy template functions are for backward compatibility only, do not use them in new code")
panic("legacy template functions are for backward compatibility only, do not use them in new code")
}
} }

View File

@ -80,8 +80,8 @@ func AdoptRepository(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// "403": // "403":
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
ownerName := ctx.PathParam(":username") ownerName := ctx.PathParam("username")
repoName := ctx.PathParam(":reponame") repoName := ctx.PathParam("reponame")
ctxUser, err := user_model.GetUserByName(ctx, ownerName) ctxUser, err := user_model.GetUserByName(ctx, ownerName)
if err != nil { if err != nil {
@ -142,8 +142,8 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "403": // "403":
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
ownerName := ctx.PathParam(":username") ownerName := ctx.PathParam("username")
repoName := ctx.PathParam(":reponame") repoName := ctx.PathParam("reponame")
ctxUser, err := user_model.GetUserByName(ctx, ownerName) ctxUser, err := user_model.GetUserByName(ctx, ownerName)
if err != nil { if err != nil {

View File

@ -74,7 +74,7 @@ func PostCronTask(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
task := cron.GetTask(ctx.PathParam(":task")) task := cron.GetTask(ctx.PathParam("task"))
if task == nil { if task == nil {
ctx.NotFound() ctx.NotFound()
return return

View File

@ -38,7 +38,7 @@ func GetAllEmails(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx) listOptions := utils.GetListOptions(ctx)
emails, maxResults, err := user_model.SearchEmails(ctx, &user_model.SearchEmailOptions{ emails, maxResults, err := user_model.SearchEmails(ctx, &user_model.SearchEmailOptions{
Keyword: ctx.PathParam(":email"), Keyword: ctx.PathParam("email"),
ListOptions: listOptions, ListOptions: listOptions,
}) })
if err != nil { if err != nil {
@ -82,6 +82,6 @@ func SearchEmail(ctx *context.APIContext) {
// "403": // "403":
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
ctx.SetPathParam(":email", ctx.FormTrim("q")) ctx.SetPathParam("email", ctx.FormTrim("q"))
GetAllEmails(ctx) GetAllEmails(ctx)
} }

View File

@ -73,7 +73,7 @@ func GetHook(ctx *context.APIContext) {
// "200": // "200":
// "$ref": "#/responses/Hook" // "$ref": "#/responses/Hook"
hookID := ctx.PathParamInt64(":id") hookID := ctx.PathParamInt64("id")
hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID) hook, err := webhook.GetSystemOrDefaultWebhook(ctx, hookID)
if err != nil { if err != nil {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
@ -142,7 +142,7 @@ func EditHook(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.EditHookOption) form := web.GetForm(ctx).(*api.EditHookOption)
// TODO in body params // TODO in body params
hookID := ctx.PathParamInt64(":id") hookID := ctx.PathParamInt64("id")
utils.EditSystemHook(ctx, form, hookID) utils.EditSystemHook(ctx, form, hookID)
} }
@ -164,7 +164,7 @@ func DeleteHook(ctx *context.APIContext) {
// "204": // "204":
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
hookID := ctx.PathParamInt64(":id") hookID := ctx.PathParamInt64("id")
if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil { if err := webhook.DeleteDefaultSystemWebhook(ctx, hookID); err != nil {
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
ctx.NotFound() ctx.NotFound()

View File

@ -375,7 +375,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := asymkey_service.DeletePublicKey(ctx, ctx.ContextUser, ctx.PathParamInt64(":id")); err != nil { if err := asymkey_service.DeletePublicKey(ctx, ctx.ContextUser, ctx.PathParamInt64("id")); err != nil {
if asymkey_model.IsErrKeyNotExist(err) { if asymkey_model.IsErrKeyNotExist(err) {
ctx.NotFound() ctx.NotFound()
} else if asymkey_model.IsErrKeyAccessDenied(err) { } else if asymkey_model.IsErrKeyAccessDenied(err) {

View File

@ -596,12 +596,12 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
var err error var err error
if assignOrg { if assignOrg {
ctx.Org.Organization, err = organization.GetOrgByName(ctx, ctx.PathParam(":org")) ctx.Org.Organization, err = organization.GetOrgByName(ctx, ctx.PathParam("org"))
if err != nil { if err != nil {
if organization.IsErrOrgNotExist(err) { if organization.IsErrOrgNotExist(err) {
redirectUserID, err := user_model.LookupUserRedirect(ctx, ctx.PathParam(":org")) redirectUserID, err := user_model.LookupUserRedirect(ctx, ctx.PathParam("org"))
if err == nil { if err == nil {
context.RedirectToUser(ctx.Base, ctx.PathParam(":org"), redirectUserID) context.RedirectToUser(ctx.Base, ctx.PathParam("org"), redirectUserID)
} else if user_model.IsErrUserRedirectNotExist(err) { } else if user_model.IsErrUserRedirectNotExist(err) {
ctx.NotFound("GetOrgByName", err) ctx.NotFound("GetOrgByName", err)
} else { } else {
@ -616,7 +616,7 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
} }
if assignTeam { if assignTeam {
ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.PathParamInt64(":teamid")) ctx.Org.Team, err = organization.GetTeamByID(ctx, ctx.PathParamInt64("teamid"))
if err != nil { if err != nil {
if organization.IsErrTeamNotExist(err) { if organization.IsErrTeamNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -101,7 +101,7 @@ func ReadThread(ctx *context.APIContext) {
} }
func getThread(ctx *context.APIContext) *activities_model.Notification { func getThread(ctx *context.APIContext) *activities_model.Notification {
n, err := activities_model.GetNotificationByID(ctx, ctx.PathParamInt64(":id")) n, err := activities_model.GetNotificationByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if db.IsErrNotExist(err) { if db.IsErrNotExist(err) {
ctx.Error(http.StatusNotFound, "GetNotificationByID", err) ctx.Error(http.StatusNotFound, "GetNotificationByID", err)

View File

@ -139,7 +139,7 @@ func GetLabel(ctx *context.APIContext) {
label *issues_model.Label label *issues_model.Label
err error err error
) )
strID := ctx.PathParam(":id") strID := ctx.PathParam("id")
if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil { if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil {
label, err = issues_model.GetLabelInOrgByName(ctx, ctx.Org.Organization.ID, strID) label, err = issues_model.GetLabelInOrgByName(ctx, ctx.Org.Organization.ID, strID)
} else { } else {
@ -190,7 +190,7 @@ func EditLabel(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditLabelOption) form := web.GetForm(ctx).(*api.EditLabelOption)
l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64(":id")) l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrOrgLabelNotExist(err) { if issues_model.IsErrOrgLabelNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -249,7 +249,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64(":id")); err != nil { if err := issues_model.DeleteLabel(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id")); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err) ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
return return
} }

View File

@ -143,7 +143,7 @@ func IsMember(ctx *context.APIContext) {
// "404": // "404":
// description: user is not a member // description: user is not a member
userToCheck := user.GetUserByParams(ctx) userToCheck := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -194,7 +194,7 @@ func IsPublicMember(ctx *context.APIContext) {
// "404": // "404":
// description: user is not a public member // description: user is not a public member
userToCheck := user.GetUserByParams(ctx) userToCheck := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -236,7 +236,7 @@ func PublicizeMember(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
userToPublicize := user.GetUserByParams(ctx) userToPublicize := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -278,7 +278,7 @@ func ConcealMember(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
userToConceal := user.GetUserByParams(ctx) userToConceal := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -318,7 +318,7 @@ func DeleteMember(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
member := user.GetUserByParams(ctx) member := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }

View File

@ -131,7 +131,7 @@ func GetUserOrgsPermissions(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
var o *user_model.User var o *user_model.User
if o = user.GetUserByParamsName(ctx, ":org"); o == nil { if o = user.GetUserByPathParam(ctx, "org"); o == nil {
return return
} }

View File

@ -449,7 +449,7 @@ func GetTeamMember(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
u := user.GetUserByParams(ctx) u := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -492,7 +492,7 @@ func AddTeamMember(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
u := user.GetUserByParams(ctx) u := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -532,7 +532,7 @@ func RemoveTeamMember(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
u := user.GetUserByParams(ctx) u := user.GetContextUserByPathParam(ctx)
if ctx.Written() { if ctx.Written() {
return return
} }
@ -645,7 +645,7 @@ func GetTeamRepo(ctx *context.APIContext) {
// getRepositoryByParams get repository by a team's organization ID and repo name // getRepositoryByParams get repository by a team's organization ID and repo name
func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository { func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository {
repo, err := repo_model.GetRepositoryByName(ctx, ctx.Org.Team.OrgID, ctx.PathParam(":reponame")) repo, err := repo_model.GetRepositoryByName(ctx, ctx.Org.Team.OrgID, ctx.PathParam("reponame"))
if err != nil { if err != nil {
if repo_model.IsErrRepoNotExist(err) { if repo_model.IsErrRepoNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -487,7 +487,7 @@ func GetBranchProtection(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
bpName := ctx.PathParam(":name") bpName := ctx.PathParam("name")
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
@ -805,7 +805,7 @@ func EditBranchProtection(ctx *context.APIContext) {
// "$ref": "#/responses/repoArchivedError" // "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.EditBranchProtectionOption) form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
bpName := ctx.PathParam(":name") bpName := ctx.PathParam("name")
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)
@ -1124,7 +1124,7 @@ func DeleteBranchProtection(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
bpName := ctx.PathParam(":name") bpName := ctx.PathParam("name")
bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName) bp, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err)

View File

@ -103,7 +103,7 @@ func IsCollaborator(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
user, err := user_model.GetUserByName(ctx, ctx.PathParam(":collaborator")) user, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err) ctx.Error(http.StatusUnprocessableEntity, "", err)
@ -163,7 +163,7 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.AddCollaboratorOption) form := web.GetForm(ctx).(*api.AddCollaboratorOption)
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam(":collaborator")) collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err) ctx.Error(http.StatusUnprocessableEntity, "", err)
@ -226,7 +226,7 @@ func DeleteCollaborator(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam(":collaborator")) collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err) ctx.Error(http.StatusUnprocessableEntity, "", err)
@ -274,12 +274,12 @@ func GetRepoPermissions(ctx *context.APIContext) {
// "403": // "403":
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
if !ctx.Doer.IsAdmin && ctx.Doer.LoginName != ctx.PathParam(":collaborator") && !ctx.IsUserRepoAdmin() { if !ctx.Doer.IsAdmin && ctx.Doer.LoginName != ctx.PathParam("collaborator") && !ctx.IsUserRepoAdmin() {
ctx.Error(http.StatusForbidden, "User", "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own") ctx.Error(http.StatusForbidden, "User", "Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own")
return return
} }
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam(":collaborator")) collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusNotFound, "GetUserByName", err) ctx.Error(http.StatusNotFound, "GetUserByName", err)

View File

@ -63,7 +63,7 @@ func GetSingleCommit(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
sha := ctx.PathParam(":sha") sha := ctx.PathParam("sha")
if !git.IsValidRefPattern(sha) { if !git.IsValidRefPattern(sha) {
ctx.Error(http.StatusUnprocessableEntity, "no valid ref or sha", fmt.Sprintf("no valid ref or sha: %s", sha)) ctx.Error(http.StatusUnprocessableEntity, "no valid ref or sha", fmt.Sprintf("no valid ref or sha: %s", sha))
return return
@ -312,8 +312,8 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
// "$ref": "#/responses/string" // "$ref": "#/responses/string"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
sha := ctx.PathParam(":sha") sha := ctx.PathParam("sha")
diffType := git.RawDiffType(ctx.PathParam(":diffType")) diffType := git.RawDiffType(ctx.PathParam("diffType"))
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil { if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, diffType, ctx.Resp); err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {

View File

@ -79,7 +79,7 @@ func GetGitHook(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
hookID := ctx.PathParam(":id") hookID := ctx.PathParam("id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID) hook, err := ctx.Repo.GitRepo.GetHook(hookID)
if err != nil { if err != nil {
if err == git.ErrNotValidHook { if err == git.ErrNotValidHook {
@ -126,7 +126,7 @@ func EditGitHook(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditGitHookOption) form := web.GetForm(ctx).(*api.EditGitHookOption)
hookID := ctx.PathParam(":id") hookID := ctx.PathParam("id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID) hook, err := ctx.Repo.GitRepo.GetHook(hookID)
if err != nil { if err != nil {
if err == git.ErrNotValidHook { if err == git.ErrNotValidHook {
@ -175,7 +175,7 @@ func DeleteGitHook(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
hookID := ctx.PathParam(":id") hookID := ctx.PathParam("id")
hook, err := ctx.Repo.GitRepo.GetHook(hookID) hook, err := ctx.Repo.GitRepo.GetHook(hookID)
if err != nil { if err != nil {
if err == git.ErrNotValidHook { if err == git.ErrNotValidHook {

View File

@ -109,7 +109,7 @@ func GetHook(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
repo := ctx.Repo repo := ctx.Repo
hookID := ctx.PathParamInt64(":id") hookID := ctx.PathParamInt64("id")
hook, err := utils.GetRepoHook(ctx, repo.Repository.ID, hookID) hook, err := utils.GetRepoHook(ctx, repo.Repository.ID, hookID)
if err != nil { if err != nil {
return return
@ -168,7 +168,7 @@ func TestHook(ctx *context.APIContext) {
ref = r ref = r
} }
hookID := ctx.PathParamInt64(":id") hookID := ctx.PathParamInt64("id")
hook, err := utils.GetRepoHook(ctx, ctx.Repo.Repository.ID, hookID) hook, err := utils.GetRepoHook(ctx, ctx.Repo.Repository.ID, hookID)
if err != nil { if err != nil {
return return
@ -263,7 +263,7 @@ func EditHook(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditHookOption) form := web.GetForm(ctx).(*api.EditHookOption)
hookID := ctx.PathParamInt64(":id") hookID := ctx.PathParamInt64("id")
utils.EditRepoHook(ctx, form, hookID) utils.EditRepoHook(ctx, form, hookID)
} }
@ -296,7 +296,7 @@ func DeleteHook(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := webhook.DeleteWebhookByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id")); err != nil { if err := webhook.DeleteWebhookByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
if webhook.IsErrWebhookNotExist(err) { if webhook.IsErrWebhookNotExist(err) {
ctx.NotFound() ctx.NotFound()
} else { } else {

View File

@ -18,7 +18,7 @@ func TestTestHook(t *testing.T) {
unittest.PrepareTestEnv(t) unittest.PrepareTestEnv(t)
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/wiki/_pages") ctx, _ := contexttest.MockAPIContext(t, "user2/repo1/wiki/_pages")
ctx.SetPathParam(":id", "1") ctx.SetPathParam("id", "1")
contexttest.LoadRepo(t, ctx, 1) contexttest.LoadRepo(t, ctx, 1)
contexttest.LoadRepoCommit(t, ctx) contexttest.LoadRepoCommit(t, ctx)
contexttest.LoadUser(t, ctx, 2) contexttest.LoadUser(t, ctx, 2)

View File

@ -613,7 +613,7 @@ func GetIssue(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -793,7 +793,7 @@ func EditIssue(ctx *context.APIContext) {
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
form := web.GetForm(ctx).(*api.EditIssueOption) form := web.GetForm(ctx).(*api.EditIssueOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -976,7 +976,7 @@ func DeleteIssue(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -1032,7 +1032,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditDeadlineOption) form := web.GetForm(ctx).(*api.EditDeadlineOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -68,7 +68,7 @@ func ListIssueComments(ctx *context.APIContext) {
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err) ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
return return
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err) ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err)
return return
@ -172,7 +172,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err) ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
return return
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err) ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err)
return return
@ -380,7 +380,7 @@ func CreateIssueComment(ctx *context.APIContext) {
// "$ref": "#/responses/repoArchivedError" // "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateIssueCommentOption) form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err) ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
return return
@ -445,7 +445,7 @@ func GetIssueComment(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -579,7 +579,7 @@ func EditIssueCommentDeprecated(ctx *context.APIContext) {
} }
func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) { func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -696,7 +696,7 @@ func DeleteIssueCommentDeprecated(ctx *context.APIContext) {
} }
func deleteIssueComment(ctx *context.APIContext) { func deleteIssueComment(ctx *context.APIContext) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)

View File

@ -61,7 +61,7 @@ func GetIssueDependencies(ctx *context.APIContext) {
return return
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("IsErrIssueNotExist", err) ctx.NotFound("IsErrIssueNotExist", err)
@ -499,7 +499,7 @@ func RemoveIssueBlocking(ctx *context.APIContext) {
} }
func getParamsIssue(ctx *context.APIContext) *issues_model.Issue { func getParamsIssue(ctx *context.APIContext) *issues_model.Issue {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("IsErrIssueNotExist", err) ctx.NotFound("IsErrIssueNotExist", err)

View File

@ -47,7 +47,7 @@ func ListIssueLabels(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -163,7 +163,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -178,7 +178,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
return return
} }
label, err := issues_model.GetLabelByID(ctx, ctx.PathParamInt64(":id")) label, err := issues_model.GetLabelByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrLabelNotExist(err) { if issues_model.IsErrLabelNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err) ctx.Error(http.StatusUnprocessableEntity, "", err)
@ -285,7 +285,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -309,7 +309,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
} }
func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (*issues_model.Issue, []*issues_model.Label, error) { func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (*issues_model.Issue, []*issues_model.Label, error) {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -41,7 +41,7 @@ func PinIssue(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -98,7 +98,7 @@ func UnpinIssue(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -159,7 +159,7 @@ func MoveIssuePin(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -169,7 +169,7 @@ func MoveIssuePin(ctx *context.APIContext) {
return return
} }
err = issue.MovePin(ctx, int(ctx.PathParamInt64(":position"))) err = issue.MovePin(ctx, int(ctx.PathParamInt64("position")))
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "MovePin", err) ctx.Error(http.StatusInternalServerError, "MovePin", err)
return return

View File

@ -51,7 +51,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -188,7 +188,7 @@ func DeleteIssueCommentReaction(ctx *context.APIContext) {
} }
func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) { func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrCommentNotExist(err) { if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -295,7 +295,7 @@ func GetIssueReactions(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -419,7 +419,7 @@ func DeleteIssueReaction(ctx *context.APIContext) {
} }
func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) { func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) {
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -161,7 +161,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
} }
func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_model.Issue, error) { func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_model.Issue, error) {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -104,7 +104,7 @@ func DelIssueSubscription(ctx *context.APIContext) {
} }
func setIssueSubscription(ctx *context.APIContext, watch bool) { func setIssueSubscription(ctx *context.APIContext, watch bool) {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -115,7 +115,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
return return
} }
user, err := user_model.GetUserByName(ctx, ctx.PathParam(":user")) user, err := user_model.GetUserByName(ctx, ctx.PathParam("user"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -185,7 +185,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -251,7 +251,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -75,7 +75,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
ctx.NotFound("Timetracker is disabled") ctx.NotFound("Timetracker is disabled")
return return
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -181,7 +181,7 @@ func AddTime(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.AddTimeOption) form := web.GetForm(ctx).(*api.AddTimeOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -264,7 +264,7 @@ func ResetIssueTime(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -337,7 +337,7 @@ func DeleteTime(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -356,7 +356,7 @@ func DeleteTime(ctx *context.APIContext) {
return return
} }
time, err := issues_model.GetTrackedTimeByID(ctx, ctx.PathParamInt64(":id")) time, err := issues_model.GetTrackedTimeByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if db.IsErrNotExist(err) { if db.IsErrNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)
@ -422,7 +422,7 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
ctx.Error(http.StatusBadRequest, "", "time tracking disabled") ctx.Error(http.StatusBadRequest, "", "time tracking disabled")
return return
} }
user, err := user_model.GetUserByName(ctx, ctx.PathParam(":timetrackingusername")) user, err := user_model.GetUserByName(ctx, ctx.PathParam("timetrackingusername"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.NotFound(err) ctx.NotFound(err)

View File

@ -143,7 +143,7 @@ func GetDeployKey(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
key, err := asymkey_model.GetDeployKeyByID(ctx, ctx.PathParamInt64(":id")) key, err := asymkey_model.GetDeployKeyByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if asymkey_model.IsErrDeployKeyNotExist(err) { if asymkey_model.IsErrDeployKeyNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -279,7 +279,7 @@ func DeleteDeploykey(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := asymkey_service.DeleteDeployKey(ctx, ctx.Repo.Repository, ctx.PathParamInt64(":id")); err != nil { if err := asymkey_service.DeleteDeployKey(ctx, ctx.Repo.Repository, ctx.PathParamInt64("id")); err != nil {
if asymkey_model.IsErrKeyAccessDenied(err) { if asymkey_model.IsErrKeyAccessDenied(err) {
ctx.Error(http.StatusForbidden, "", "You do not have access to this key") ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
} else { } else {

View File

@ -99,7 +99,7 @@ func GetLabel(ctx *context.APIContext) {
l *issues_model.Label l *issues_model.Label
err error err error
) )
strID := ctx.PathParam(":id") strID := ctx.PathParam("id")
if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil { if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil {
l, err = issues_model.GetLabelInRepoByName(ctx, ctx.Repo.Repository.ID, strID) l, err = issues_model.GetLabelInRepoByName(ctx, ctx.Repo.Repository.ID, strID)
} else { } else {
@ -212,7 +212,7 @@ func EditLabel(ctx *context.APIContext) {
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditLabelOption) form := web.GetForm(ctx).(*api.EditLabelOption)
l, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id")) l, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrRepoLabelNotExist(err) { if issues_model.IsErrRepoLabelNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -276,7 +276,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id")); err != nil { if err := issues_model.DeleteLabel(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err) ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
return return
} }

View File

@ -280,7 +280,7 @@ func DeleteMilestone(ctx *context.APIContext) {
// getMilestoneByIDOrName get milestone by ID and if not available by name // getMilestoneByIDOrName get milestone by ID and if not available by name
func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone { func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone {
mile := ctx.PathParam(":id") mile := ctx.PathParam("id")
mileID, _ := strconv.ParseInt(mile, 0, 64) mileID, _ := strconv.ParseInt(mile, 0, 64)
if mileID != 0 { if mileID != 0 {

View File

@ -223,7 +223,7 @@ func GetPushMirrorByName(ctx *context.APIContext) {
return return
} }
mirrorName := ctx.PathParam(":name") mirrorName := ctx.PathParam("name")
// Get push mirror of a specific repo by remoteName // Get push mirror of a specific repo by remoteName
pushMirror, exist, err := db.Get[repo_model.PushMirror](ctx, repo_model.PushMirrorOptions{ pushMirror, exist, err := db.Get[repo_model.PushMirror](ctx, repo_model.PushMirrorOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
@ -324,7 +324,7 @@ func DeletePushMirrorByRemoteName(ctx *context.APIContext) {
return return
} }
remoteName := ctx.PathParam(":name") remoteName := ctx.PathParam("name")
// Delete push mirror on repo by name. // Delete push mirror on repo by name.
err := repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{RepoID: ctx.Repo.Repository.ID, RemoteName: remoteName}) err := repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{RepoID: ctx.Repo.Repository.ID, RemoteName: remoteName})
if err != nil { if err != nil {

View File

@ -52,7 +52,7 @@ func GetNote(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
sha := ctx.PathParam(":sha") sha := ctx.PathParam("sha")
if !git.IsValidRefPattern(sha) { if !git.IsValidRefPattern(sha) {
ctx.Error(http.StatusUnprocessableEntity, "no valid ref or sha", fmt.Sprintf("no valid ref or sha: %s", sha)) ctx.Error(http.StatusUnprocessableEntity, "no valid ref or sha", fmt.Sprintf("no valid ref or sha: %s", sha))
return return

View File

@ -179,7 +179,7 @@ func GetPullRequest(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -264,7 +264,7 @@ func GetPullRequestByBaseHead(ctx *context.APIContext) {
headBranch = head headBranch = head
} }
pr, err := issues_model.GetPullRequestByBaseHeadInfo(ctx, ctx.Repo.Repository.ID, headRepoID, ctx.PathParam(":base"), headBranch) pr, err := issues_model.GetPullRequestByBaseHeadInfo(ctx, ctx.Repo.Repository.ID, headRepoID, ctx.PathParam("base"), headBranch)
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -324,7 +324,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
// "$ref": "#/responses/string" // "$ref": "#/responses/string"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -334,7 +334,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
return return
} }
var patch bool var patch bool
if ctx.PathParam(":diffType") == "diff" { if ctx.PathParam("diffType") == "diff" {
patch = false patch = false
} else { } else {
patch = true patch = true
@ -603,7 +603,7 @@ func EditPullRequest(ctx *context.APIContext) {
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditPullRequestOption) form := web.GetForm(ctx).(*api.EditPullRequestOption)
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -831,7 +831,7 @@ func IsPullRequestMerged(ctx *context.APIContext) {
// "404": // "404":
// description: pull request has not been merged // description: pull request has not been merged
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -889,7 +889,7 @@ func MergePullRequest(ctx *context.APIContext) {
form := web.GetForm(ctx).(*forms.MergePullRequestForm) form := web.GetForm(ctx).(*forms.MergePullRequestForm)
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)
@ -1256,7 +1256,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -1355,7 +1355,7 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) {
// "423": // "423":
// "$ref": "#/responses/repoArchivedError" // "$ref": "#/responses/repoArchivedError"
pullIndex := ctx.PathParamInt64(":index") pullIndex := ctx.PathParamInt64("index")
pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex) pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex)
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
@ -1441,7 +1441,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -1564,7 +1564,7 @@ func GetPullRequestFiles(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -61,7 +61,7 @@ func ListPullReviews(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)
@ -306,7 +306,7 @@ func CreatePullReview(ctx *context.APIContext) {
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.CreatePullReviewOptions) opts := web.GetForm(ctx).(*api.CreatePullReviewOptions)
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)
@ -533,7 +533,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest
// prepareSingleReview return review, related pull and false or nil, nil and true if an error happen // prepareSingleReview return review, related pull and false or nil, nil and true if an error happen
func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues_model.PullRequest, bool) { func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues_model.PullRequest, bool) {
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)
@ -543,7 +543,7 @@ func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues
return nil, nil, true return nil, nil, true
} }
review, err := issues_model.GetReviewByID(ctx, ctx.PathParamInt64(":id")) review, err := issues_model.GetReviewByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrReviewNotExist(err) { if issues_model.IsErrReviewNotExist(err) {
ctx.NotFound("GetReviewByID", err) ctx.NotFound("GetReviewByID", err)
@ -698,7 +698,7 @@ func parseReviewersByNames(ctx *context.APIContext, reviewerNames, teamReviewerN
} }
func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions, isAdd bool) { func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions, isAdd bool) {
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)

View File

@ -50,7 +50,7 @@ func GetRelease(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) release, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
if err != nil && !repo_model.IsErrReleaseNotExist(err) { if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err) ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err)
@ -319,7 +319,7 @@ func EditRelease(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditReleaseOption) form := web.GetForm(ctx).(*api.EditReleaseOption)
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
if err != nil && !repo_model.IsErrReleaseNotExist(err) { if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err) ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err)
@ -396,7 +396,7 @@ func DeleteRelease(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id) rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
if err != nil && !repo_model.IsErrReleaseNotExist(err) { if err != nil && !repo_model.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err) ctx.Error(http.StatusInternalServerError, "GetReleaseForRepoByID", err)

View File

@ -72,12 +72,12 @@ func GetReleaseAttachment(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
releaseID := ctx.PathParamInt64(":id") releaseID := ctx.PathParamInt64("id")
if !checkReleaseMatchRepo(ctx, releaseID) { if !checkReleaseMatchRepo(ctx, releaseID) {
return return
} }
attachID := ctx.PathParamInt64(":attachment_id") attachID := ctx.PathParamInt64("attachment_id")
attach, err := repo_model.GetAttachmentByID(ctx, attachID) attach, err := repo_model.GetAttachmentByID(ctx, attachID)
if err != nil { if err != nil {
if repo_model.IsErrAttachmentNotExist(err) { if repo_model.IsErrAttachmentNotExist(err) {
@ -126,7 +126,7 @@ func ListReleaseAttachments(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
releaseID := ctx.PathParamInt64(":id") releaseID := ctx.PathParamInt64("id")
release, err := repo_model.GetReleaseByID(ctx, releaseID) release, err := repo_model.GetReleaseByID(ctx, releaseID)
if err != nil { if err != nil {
if repo_model.IsErrReleaseNotExist(err) { if repo_model.IsErrReleaseNotExist(err) {
@ -199,7 +199,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
} }
// Check if release exists an load release // Check if release exists an load release
releaseID := ctx.PathParamInt64(":id") releaseID := ctx.PathParamInt64("id")
if !checkReleaseMatchRepo(ctx, releaseID) { if !checkReleaseMatchRepo(ctx, releaseID) {
return return
} }
@ -299,12 +299,12 @@ func EditReleaseAttachment(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.EditAttachmentOptions) form := web.GetForm(ctx).(*api.EditAttachmentOptions)
// Check if release exists an load release // Check if release exists an load release
releaseID := ctx.PathParamInt64(":id") releaseID := ctx.PathParamInt64("id")
if !checkReleaseMatchRepo(ctx, releaseID) { if !checkReleaseMatchRepo(ctx, releaseID) {
return return
} }
attachID := ctx.PathParamInt64(":attachment_id") attachID := ctx.PathParamInt64("attachment_id")
attach, err := repo_model.GetAttachmentByID(ctx, attachID) attach, err := repo_model.GetAttachmentByID(ctx, attachID)
if err != nil { if err != nil {
if repo_model.IsErrAttachmentNotExist(err) { if repo_model.IsErrAttachmentNotExist(err) {
@ -372,12 +372,12 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// Check if release exists an load release // Check if release exists an load release
releaseID := ctx.PathParamInt64(":id") releaseID := ctx.PathParamInt64("id")
if !checkReleaseMatchRepo(ctx, releaseID) { if !checkReleaseMatchRepo(ctx, releaseID) {
return return
} }
attachID := ctx.PathParamInt64(":attachment_id") attachID := ctx.PathParamInt64("attachment_id")
attach, err := repo_model.GetAttachmentByID(ctx, attachID) attach, err := repo_model.GetAttachmentByID(ctx, attachID)
if err != nil { if err != nil {
if repo_model.IsErrAttachmentNotExist(err) { if repo_model.IsErrAttachmentNotExist(err) {

View File

@ -41,7 +41,7 @@ func GetReleaseByTag(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
tag := ctx.PathParam(":tag") tag := ctx.PathParam("tag")
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag) release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag)
if err != nil { if err != nil {
@ -94,7 +94,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
tag := ctx.PathParam(":tag") tag := ctx.PathParam("tag")
release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag) release, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, tag)
if err != nil { if err != nil {

View File

@ -495,7 +495,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
// "403": // "403":
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
opt := web.GetForm(ctx).(*api.CreateRepoOption) opt := web.GetForm(ctx).(*api.CreateRepoOption)
org, err := organization.GetOrgByName(ctx, ctx.PathParam(":org")) org, err := organization.GetOrgByName(ctx, ctx.PathParam("org"))
if err != nil { if err != nil {
if organization.IsErrOrgNotExist(err) { if organization.IsErrOrgNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err) ctx.Error(http.StatusUnprocessableEntity, "", err)
@ -575,7 +575,7 @@ func GetByID(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
repo, err := repo_model.GetRepositoryByID(ctx, ctx.PathParamInt64(":id")) repo, err := repo_model.GetRepositoryByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if repo_model.IsErrRepoNotExist(err) { if repo_model.IsErrRepoNotExist(err) {
ctx.NotFound() ctx.NotFound()

View File

@ -357,7 +357,7 @@ func GetTagProtection(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
pt, err := git_model.GetProtectedTagByID(ctx, id) pt, err := git_model.GetProtectedTagByID(ctx, id)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err) ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)
@ -521,7 +521,7 @@ func EditTagProtection(ctx *context.APIContext) {
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
form := web.GetForm(ctx).(*api.EditTagProtectionOption) form := web.GetForm(ctx).(*api.EditTagProtectionOption)
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
pt, err := git_model.GetProtectedTagByID(ctx, id) pt, err := git_model.GetProtectedTagByID(ctx, id)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err) ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)
@ -616,7 +616,7 @@ func DeleteTagProtection(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
pt, err := git_model.GetProtectedTagByID(ctx, id) pt, err := git_model.GetProtectedTagByID(ctx, id)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err) ctx.Error(http.StatusInternalServerError, "GetProtectedTagByID", err)

View File

@ -221,7 +221,7 @@ func changeRepoTeam(ctx *context.APIContext, add bool) {
} }
func getTeamByParam(ctx *context.APIContext) *organization.Team { func getTeamByParam(ctx *context.APIContext) *organization.Team {
team, err := organization.GetTeam(ctx, ctx.Repo.Owner.ID, ctx.PathParam(":team")) team, err := organization.GetTeam(ctx, ctx.Repo.Owner.ID, ctx.PathParam("team"))
if err != nil { if err != nil {
if organization.IsErrTeamNotExist(err) { if organization.IsErrTeamNotExist(err) {
ctx.Error(http.StatusNotFound, "TeamNotExit", err) ctx.Error(http.StatusNotFound, "TeamNotExit", err)

View File

@ -162,7 +162,7 @@ func AddTopic(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/invalidTopicsError" // "$ref": "#/responses/invalidTopicsError"
topicName := strings.TrimSpace(strings.ToLower(ctx.PathParam(":topic"))) topicName := strings.TrimSpace(strings.ToLower(ctx.PathParam("topic")))
if !repo_model.ValidateTopic(topicName) { if !repo_model.ValidateTopic(topicName) {
ctx.JSON(http.StatusUnprocessableEntity, map[string]any{ ctx.JSON(http.StatusUnprocessableEntity, map[string]any{
@ -229,7 +229,7 @@ func DeleteTopic(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/invalidTopicsError" // "$ref": "#/responses/invalidTopicsError"
topicName := strings.TrimSpace(strings.ToLower(ctx.PathParam(":topic"))) topicName := strings.TrimSpace(strings.ToLower(ctx.PathParam("topic")))
if !repo_model.ValidateTopic(topicName) { if !repo_model.ValidateTopic(topicName) {
ctx.JSON(http.StatusUnprocessableEntity, map[string]any{ ctx.JSON(http.StatusUnprocessableEntity, map[string]any{

View File

@ -56,7 +56,7 @@ func GetTree(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
sha := ctx.PathParam(":sha") sha := ctx.PathParam("sha")
if len(sha) == 0 { if len(sha) == 0 {
ctx.Error(http.StatusBadRequest, "", "sha not provided") ctx.Error(http.StatusBadRequest, "", "sha not provided")
return return

View File

@ -136,7 +136,7 @@ func EditWikiPage(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.CreateWikiPageOptions) form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
oldWikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName")) oldWikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("pageName"))
newWikiName := wiki_service.UserTitleToWebPath("", form.Title) newWikiName := wiki_service.UserTitleToWebPath("", form.Title)
if len(newWikiName) == 0 { if len(newWikiName) == 0 {
@ -242,7 +242,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
// "423": // "423":
// "$ref": "#/responses/repoArchivedError" // "$ref": "#/responses/repoArchivedError"
wikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName")) wikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("pageName"))
if err := wiki_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName); err != nil { if err := wiki_service.DeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName); err != nil {
if err.Error() == "file does not exist" { if err.Error() == "file does not exist" {
@ -370,7 +370,7 @@ func GetWikiPage(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
// get requested pagename // get requested pagename
pageName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName")) pageName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("pageName"))
wikiPage := getWikiPage(ctx, pageName) wikiPage := getWikiPage(ctx, pageName)
if !ctx.Written() { if !ctx.Written() {
@ -420,7 +420,7 @@ func ListPageRevisions(ctx *context.APIContext) {
} }
// get requested pagename // get requested pagename
pageName := wiki_service.WebPathFromRequest(ctx.PathParamRaw(":pageName")) pageName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("pageName"))
if len(pageName) == 0 { if len(pageName) == 0 {
pageName = "Home" pageName = "Home"
} }

View File

@ -165,7 +165,7 @@ func DeleteAccessToken(ctx *context.APIContext) {
// "422": // "422":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
token := ctx.PathParam(":id") token := ctx.PathParam("id")
tokenID, _ := strconv.ParseInt(token, 0, 64) tokenID, _ := strconv.ParseInt(token, 0, 64)
if tokenID == 0 { if tokenID == 0 {
@ -306,7 +306,7 @@ func DeleteOauth2Application(ctx *context.APIContext) {
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
appID := ctx.PathParamInt64(":id") appID := ctx.PathParamInt64("id")
if err := auth_model.DeleteOAuth2Application(ctx, appID, ctx.Doer.ID); err != nil { if err := auth_model.DeleteOAuth2Application(ctx, appID, ctx.Doer.ID); err != nil {
if auth_model.IsErrOAuthApplicationNotFound(err) { if auth_model.IsErrOAuthApplicationNotFound(err) {
ctx.NotFound() ctx.NotFound()
@ -338,7 +338,7 @@ func GetOauth2Application(ctx *context.APIContext) {
// "$ref": "#/responses/OAuth2Application" // "$ref": "#/responses/OAuth2Application"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
appID := ctx.PathParamInt64(":id") appID := ctx.PathParamInt64("id")
app, err := auth_model.GetOAuth2ApplicationByID(ctx, appID) app, err := auth_model.GetOAuth2ApplicationByID(ctx, appID)
if err != nil { if err != nil {
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) { if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {
@ -382,7 +382,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
// "$ref": "#/responses/OAuth2Application" // "$ref": "#/responses/OAuth2Application"
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
appID := ctx.PathParamInt64(":id") appID := ctx.PathParamInt64("id")
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions) data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)

View File

@ -201,7 +201,7 @@ func CheckFollowing(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
target := GetUserByParamsName(ctx, ":target") target := GetUserByPathParam(ctx, "target") // FIXME: it is not right to call this function, it should load the "target" directly
if ctx.Written() { if ctx.Written() {
return return
} }

View File

@ -116,7 +116,7 @@ func GetGPGKey(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.PathParamInt64(":id")) key, err := asymkey_model.GetGPGKeyForUserByID(ctx, ctx.Doer.ID, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if asymkey_model.IsErrGPGKeyNotExist(err) { if asymkey_model.IsErrGPGKeyNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -280,7 +280,7 @@ func DeleteGPGKey(ctx *context.APIContext) {
return return
} }
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.PathParamInt64(":id")); err != nil { if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.PathParamInt64("id")); err != nil {
if asymkey_model.IsErrGPGKeyAccessDenied(err) { if asymkey_model.IsErrGPGKeyAccessDenied(err) {
ctx.Error(http.StatusForbidden, "", "You do not have access to this key") ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
} else { } else {

View File

@ -10,8 +10,9 @@ import (
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
) )
// GetUserByParamsName get user by name // GetUserByPathParam get user by the path param name
func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User { // it will redirect to the user's new name if the user's name has been changed
func GetUserByPathParam(ctx *context.APIContext, name string) *user_model.User {
username := ctx.PathParam(name) username := ctx.PathParam(name)
user, err := user_model.GetUserByName(ctx, username) user, err := user_model.GetUserByName(ctx, username)
if err != nil { if err != nil {
@ -29,7 +30,7 @@ func GetUserByParamsName(ctx *context.APIContext, name string) *user_model.User
return user return user
} }
// GetUserByParams returns user whose name is presented in URL (":username"). // GetContextUserByPathParam returns user whose name is presented in URL (path param "username").
func GetUserByParams(ctx *context.APIContext) *user_model.User { func GetContextUserByPathParam(ctx *context.APIContext) *user_model.User {
return GetUserByParamsName(ctx, ":username") return GetUserByPathParam(ctx, "username")
} }

View File

@ -179,7 +179,7 @@ func GetPublicKey(ctx *context.APIContext) {
// "404": // "404":
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.PathParamInt64(":id")) key, err := asymkey_model.GetPublicKeyByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if asymkey_model.IsErrKeyNotExist(err) { if asymkey_model.IsErrKeyNotExist(err) {
ctx.NotFound() ctx.NotFound()
@ -274,7 +274,7 @@ func DeletePublicKey(ctx *context.APIContext) {
return return
} }
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id) externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(ctx, id)
if err != nil { if err != nil {
if asymkey_model.IsErrKeyNotExist(err) { if asymkey_model.IsErrKeyNotExist(err) {

View File

@ -121,7 +121,7 @@ func GetInfo(ctx *context.APIContext) {
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) { if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
// fake ErrUserNotExist error message to not leak information about existence // fake ErrUserNotExist error message to not leak information about existence
ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.PathParam(":username")}) ctx.NotFound("GetUserByName", user_model.ErrUserNotExist{Name: ctx.PathParam("username")})
return return
} }
ctx.JSON(http.StatusOK, convert.ToUser(ctx, ctx.ContextUser, ctx.Doer)) ctx.JSON(http.StatusOK, convert.ToUser(ctx, ctx.ContextUser, ctx.Doer))

View File

@ -16,9 +16,9 @@ import (
// SetDefaultBranch updates the default branch // SetDefaultBranch updates the default branch
func SetDefaultBranch(ctx *gitea_context.PrivateContext) { func SetDefaultBranch(ctx *gitea_context.PrivateContext) {
ownerName := ctx.PathParam(":owner") ownerName := ctx.PathParam("owner")
repoName := ctx.PathParam(":repo") repoName := ctx.PathParam("repo")
branch := ctx.PathParam(":branch") branch := ctx.PathParam("branch")
ctx.Repo.Repository.DefaultBranch = branch ctx.Repo.Repository.DefaultBranch = branch
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil { if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {

View File

@ -40,8 +40,8 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
// b) our update function will likely change the repository in the db so we will need to refresh it // b) our update function will likely change the repository in the db so we will need to refresh it
// c) we don't always need the repo // c) we don't always need the repo
ownerName := ctx.PathParam(":owner") ownerName := ctx.PathParam("owner")
repoName := ctx.PathParam(":repo") repoName := ctx.PathParam("repo")
// defer getting the repository at this point - as we should only retrieve it if we're going to call update // defer getting the repository at this point - as we should only retrieve it if we're going to call update
var ( var (

View File

@ -18,8 +18,8 @@ import (
// RepoAssignment assigns the repository and git repository to the private context // RepoAssignment assigns the repository and git repository to the private context
func RepoAssignment(ctx *gitea_context.PrivateContext) { func RepoAssignment(ctx *gitea_context.PrivateContext) {
ownerName := ctx.PathParam(":owner") ownerName := ctx.PathParam("owner")
repoName := ctx.PathParam(":repo") repoName := ctx.PathParam("repo")
repo := loadRepository(ctx, ownerName, repoName) repo := loadRepository(ctx, ownerName, repoName)
if ctx.Written() { if ctx.Written() {

View File

@ -14,8 +14,8 @@ import (
// UpdatePublicKeyInRepo update public key and deploy key updates // UpdatePublicKeyInRepo update public key and deploy key updates
func UpdatePublicKeyInRepo(ctx *context.PrivateContext) { func UpdatePublicKeyInRepo(ctx *context.PrivateContext) {
keyID := ctx.PathParamInt64(":id") keyID := ctx.PathParamInt64("id")
repoID := ctx.PathParamInt64(":repoid") repoID := ctx.PathParamInt64("repoid")
if err := asymkey_model.UpdatePublicKeyUpdated(ctx, keyID); err != nil { if err := asymkey_model.UpdatePublicKeyUpdated(ctx, keyID); err != nil {
ctx.JSON(http.StatusInternalServerError, private.Response{ ctx.JSON(http.StatusInternalServerError, private.Response{
Err: err.Error(), Err: err.Error(),

View File

@ -25,7 +25,7 @@ import (
// ServNoCommand returns information about the provided keyid // ServNoCommand returns information about the provided keyid
func ServNoCommand(ctx *context.PrivateContext) { func ServNoCommand(ctx *context.PrivateContext) {
keyID := ctx.PathParamInt64(":keyid") keyID := ctx.PathParamInt64("keyid")
if keyID <= 0 { if keyID <= 0 {
ctx.JSON(http.StatusBadRequest, private.Response{ ctx.JSON(http.StatusBadRequest, private.Response{
UserMsg: fmt.Sprintf("Bad key id: %d", keyID), UserMsg: fmt.Sprintf("Bad key id: %d", keyID),
@ -77,9 +77,9 @@ func ServNoCommand(ctx *context.PrivateContext) {
// ServCommand returns information about the provided keyid // ServCommand returns information about the provided keyid
func ServCommand(ctx *context.PrivateContext) { func ServCommand(ctx *context.PrivateContext) {
keyID := ctx.PathParamInt64(":keyid") keyID := ctx.PathParamInt64("keyid")
ownerName := ctx.PathParam(":owner") ownerName := ctx.PathParam("owner")
repoName := ctx.PathParam(":repo") repoName := ctx.PathParam("repo")
mode := perm.AccessMode(ctx.FormInt("mode")) mode := perm.AccessMode(ctx.FormInt("mode"))
// Set the basic parts of the results to return // Set the basic parts of the results to return

View File

@ -337,7 +337,7 @@ func EditAuthSource(ctx *context.Context) {
oauth2providers := oauth2.GetSupportedOAuth2Providers() oauth2providers := oauth2.GetSupportedOAuth2Providers()
ctx.Data["OAuth2Providers"] = oauth2providers ctx.Data["OAuth2Providers"] = oauth2providers
source, err := auth.GetSourceByID(ctx, ctx.PathParamInt64(":authid")) source, err := auth.GetSourceByID(ctx, ctx.PathParamInt64("authid"))
if err != nil { if err != nil {
ctx.ServerError("auth.GetSourceByID", err) ctx.ServerError("auth.GetSourceByID", err)
return return
@ -371,7 +371,7 @@ func EditAuthSourcePost(ctx *context.Context) {
oauth2providers := oauth2.GetSupportedOAuth2Providers() oauth2providers := oauth2.GetSupportedOAuth2Providers()
ctx.Data["OAuth2Providers"] = oauth2providers ctx.Data["OAuth2Providers"] = oauth2providers
source, err := auth.GetSourceByID(ctx, ctx.PathParamInt64(":authid")) source, err := auth.GetSourceByID(ctx, ctx.PathParamInt64("authid"))
if err != nil { if err != nil {
ctx.ServerError("auth.GetSourceByID", err) ctx.ServerError("auth.GetSourceByID", err)
return return
@ -442,7 +442,7 @@ func EditAuthSourcePost(ctx *context.Context) {
// DeleteAuthSource response for deleting an auth source // DeleteAuthSource response for deleting an auth source
func DeleteAuthSource(ctx *context.Context) { func DeleteAuthSource(ctx *context.Context) {
source, err := auth.GetSourceByID(ctx, ctx.PathParamInt64(":authid")) source, err := auth.GetSourceByID(ctx, ctx.PathParamInt64("authid"))
if err != nil { if err != nil {
ctx.ServerError("auth.GetSourceByID", err) ctx.ServerError("auth.GetSourceByID", err)
return return
@ -454,7 +454,7 @@ func DeleteAuthSource(ctx *context.Context) {
} else { } else {
ctx.Flash.Error(fmt.Sprintf("auth_service.DeleteSource: %v", err)) ctx.Flash.Error(fmt.Sprintf("auth_service.DeleteSource: %v", err))
} }
ctx.JSONRedirect(setting.AppSubURL + "/-/admin/auths/" + url.PathEscape(ctx.PathParam(":authid"))) ctx.JSONRedirect(setting.AppSubURL + "/-/admin/auths/" + url.PathEscape(ctx.PathParam("authid")))
return return
} }
log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID) log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID)

View File

@ -219,7 +219,7 @@ func NewUserPost(ctx *context.Context) {
} }
func prepareUserInfo(ctx *context.Context) *user_model.User { func prepareUserInfo(ctx *context.Context) *user_model.User {
u, err := user_model.GetUserByID(ctx, ctx.PathParamInt64(":userid")) u, err := user_model.GetUserByID(ctx, ctx.PathParamInt64("userid"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) { if user_model.IsErrUserNotExist(err) {
ctx.Redirect(setting.AppSubURL + "/-/admin/users") ctx.Redirect(setting.AppSubURL + "/-/admin/users")
@ -481,12 +481,12 @@ func EditUserPost(ctx *context.Context) {
} }
ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success")) ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success"))
ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam(":userid"))) ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam("userid")))
} }
// DeleteUser response for deleting a user // DeleteUser response for deleting a user
func DeleteUser(ctx *context.Context) { func DeleteUser(ctx *context.Context) {
u, err := user_model.GetUserByID(ctx, ctx.PathParamInt64(":userid")) u, err := user_model.GetUserByID(ctx, ctx.PathParamInt64("userid"))
if err != nil { if err != nil {
ctx.ServerError("GetUserByID", err) ctx.ServerError("GetUserByID", err)
return return
@ -495,7 +495,7 @@ func DeleteUser(ctx *context.Context) {
// admin should not delete themself // admin should not delete themself
if u.ID == ctx.Doer.ID { if u.ID == ctx.Doer.ID {
ctx.Flash.Error(ctx.Tr("admin.users.cannot_delete_self")) ctx.Flash.Error(ctx.Tr("admin.users.cannot_delete_self"))
ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam(":userid"))) ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam("userid")))
return return
} }
@ -503,16 +503,16 @@ func DeleteUser(ctx *context.Context) {
switch { switch {
case repo_model.IsErrUserOwnRepos(err): case repo_model.IsErrUserOwnRepos(err):
ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo")) ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo"))
ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam(":userid"))) ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam("userid")))
case org_model.IsErrUserHasOrgs(err): case org_model.IsErrUserHasOrgs(err):
ctx.Flash.Error(ctx.Tr("admin.users.still_has_org")) ctx.Flash.Error(ctx.Tr("admin.users.still_has_org"))
ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam(":userid"))) ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam("userid")))
case packages_model.IsErrUserOwnPackages(err): case packages_model.IsErrUserOwnPackages(err):
ctx.Flash.Error(ctx.Tr("admin.users.still_own_packages")) ctx.Flash.Error(ctx.Tr("admin.users.still_own_packages"))
ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam(":userid"))) ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam("userid")))
case user_model.IsErrDeleteLastAdminUser(err): case user_model.IsErrDeleteLastAdminUser(err):
ctx.Flash.Error(ctx.Tr("auth.last_admin")) ctx.Flash.Error(ctx.Tr("auth.last_admin"))
ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam(":userid"))) ctx.Redirect(setting.AppSubURL + "/-/admin/users/" + url.PathEscape(ctx.PathParam("userid")))
default: default:
ctx.ServerError("DeleteUser", err) ctx.ServerError("DeleteUser", err)
} }

View File

@ -34,7 +34,7 @@ import (
// SignInOAuth handles the OAuth2 login buttons // SignInOAuth handles the OAuth2 login buttons
func SignInOAuth(ctx *context.Context) { func SignInOAuth(ctx *context.Context) {
provider := ctx.PathParam(":provider") provider := ctx.PathParam("provider")
authSource, err := auth.GetActiveOAuth2SourceByName(ctx, provider) authSource, err := auth.GetActiveOAuth2SourceByName(ctx, provider)
if err != nil { if err != nil {
@ -73,7 +73,7 @@ func SignInOAuth(ctx *context.Context) {
// SignInOAuthCallback handles the callback from the given provider // SignInOAuthCallback handles the callback from the given provider
func SignInOAuthCallback(ctx *context.Context) { func SignInOAuthCallback(ctx *context.Context) {
provider := ctx.PathParam(":provider") provider := ctx.PathParam("provider")
if ctx.Req.FormValue("error") != "" { if ctx.Req.FormValue("error") != "" {
var errorKeyValues []string var errorKeyValues []string

View File

@ -9,7 +9,7 @@ import (
// RenderBranchFeed render format for branch or file // RenderBranchFeed render format for branch or file
func RenderBranchFeed(ctx *context.Context) { func RenderBranchFeed(ctx *context.Context) {
_, _, showFeedType := GetFeedType(ctx.PathParam(":reponame"), ctx.Req) _, _, showFeedType := GetFeedType(ctx.PathParam("reponame"), ctx.Req)
if ctx.Repo.TreePath == "" { if ctx.Repo.TreePath == "" {
ShowBranchFeed(ctx, ctx.Repo.Repository, showFeedType) ShowBranchFeed(ctx, ctx.Repo.Repository, showFeedType)
} else { } else {

View File

@ -28,14 +28,14 @@ const (
// Home show organization home page // Home show organization home page
func Home(ctx *context.Context) { func Home(ctx *context.Context) {
uname := ctx.PathParam(":username") uname := ctx.PathParam("username")
if strings.HasSuffix(uname, ".keys") || strings.HasSuffix(uname, ".gpg") { if strings.HasSuffix(uname, ".keys") || strings.HasSuffix(uname, ".gpg") {
ctx.NotFound("", nil) ctx.NotFound("", nil)
return return
} }
ctx.SetPathParam(":org", uname) ctx.SetPathParam("org", uname)
context.HandleOrgAssignment(ctx) context.HandleOrgAssignment(ctx)
if ctx.Written() { if ctx.Written() {
return return

View File

@ -90,7 +90,7 @@ func MembersAction(ctx *context.Context) {
org := ctx.Org.Organization org := ctx.Org.Organization
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "private": case "private":
if ctx.Doer.ID != member.ID && !ctx.Org.IsOwner { if ctx.Doer.ID != member.ID && !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound) ctx.Error(http.StatusNotFound)
@ -131,7 +131,7 @@ func MembersAction(ctx *context.Context) {
} }
if err != nil { if err != nil {
log.Error("Action(%s): %v", ctx.PathParam(":action"), err) log.Error("Action(%s): %v", ctx.PathParam("action"), err)
ctx.JSON(http.StatusOK, map[string]any{ ctx.JSON(http.StatusOK, map[string]any{
"ok": false, "ok": false,
"err": err.Error(), "err": err.Error(),
@ -140,7 +140,7 @@ func MembersAction(ctx *context.Context) {
} }
redirect := ctx.Org.OrgLink + "/members" redirect := ctx.Org.OrgLink + "/members"
if ctx.PathParam(":action") == "leave" { if ctx.PathParam("action") == "leave" {
redirect = setting.AppSubURL + "/" redirect = setting.AppSubURL + "/"
} }

View File

@ -196,7 +196,7 @@ func NewProjectPost(ctx *context.Context) {
// ChangeProjectStatus updates the status of a project between "open" and "close" // ChangeProjectStatus updates the status of a project between "open" and "close"
func ChangeProjectStatus(ctx *context.Context) { func ChangeProjectStatus(ctx *context.Context) {
var toClose bool var toClose bool
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "open": case "open":
toClose = false toClose = false
case "close": case "close":
@ -205,7 +205,7 @@ func ChangeProjectStatus(ctx *context.Context) {
ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects") ctx.JSONRedirect(ctx.ContextUser.HomeLink() + "/-/projects")
return return
} }
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil { if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, 0, id, toClose); err != nil {
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
@ -216,7 +216,7 @@ func ChangeProjectStatus(ctx *context.Context) {
// DeleteProject delete a project // DeleteProject delete a project
func DeleteProject(ctx *context.Context) { func DeleteProject(ctx *context.Context) {
p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return return
@ -245,7 +245,7 @@ func RenderEditProject(ctx *context.Context) {
shared_user.RenderUserHeader(ctx) shared_user.RenderUserHeader(ctx)
p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return return
@ -269,7 +269,7 @@ func RenderEditProject(ctx *context.Context) {
// EditProjectPost response for editing a project // EditProjectPost response for editing a project
func EditProjectPost(ctx *context.Context) { func EditProjectPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CreateProjectForm) form := web.GetForm(ctx).(*forms.CreateProjectForm)
projectID := ctx.PathParamInt64(":id") projectID := ctx.PathParamInt64("id")
ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
ctx.Data["PageIsEditProjects"] = true ctx.Data["PageIsEditProjects"] = true
ctx.Data["PageIsViewProjects"] = true ctx.Data["PageIsViewProjects"] = true
@ -318,7 +318,7 @@ func EditProjectPost(ctx *context.Context) {
// ViewProject renders the project with board view for a project // ViewProject renders the project with board view for a project
func ViewProject(ctx *context.Context) { func ViewProject(ctx *context.Context) {
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return return
@ -447,18 +447,18 @@ func DeleteProjectColumn(ctx *context.Context) {
return return
} }
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return return
} }
pb, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID")) pb, err := project_model.GetColumn(ctx, ctx.PathParamInt64("columnID"))
if err != nil { if err != nil {
ctx.ServerError("GetProjectColumn", err) ctx.ServerError("GetProjectColumn", err)
return return
} }
if pb.ProjectID != ctx.PathParamInt64(":id") { if pb.ProjectID != ctx.PathParamInt64("id") {
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{ ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
"message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", pb.ID, project.ID), "message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", pb.ID, project.ID),
}) })
@ -472,7 +472,7 @@ func DeleteProjectColumn(ctx *context.Context) {
return return
} }
if err := project_model.DeleteColumnByID(ctx, ctx.PathParamInt64(":columnID")); err != nil { if err := project_model.DeleteColumnByID(ctx, ctx.PathParamInt64("columnID")); err != nil {
ctx.ServerError("DeleteProjectColumnByID", err) ctx.ServerError("DeleteProjectColumnByID", err)
return return
} }
@ -484,7 +484,7 @@ func DeleteProjectColumn(ctx *context.Context) {
func AddColumnToProjectPost(ctx *context.Context) { func AddColumnToProjectPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.EditProjectColumnForm) form := web.GetForm(ctx).(*forms.EditProjectColumnForm)
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return return
@ -512,18 +512,18 @@ func CheckProjectColumnChangePermissions(ctx *context.Context) (*project_model.P
return nil, nil return nil, nil
} }
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return nil, nil return nil, nil
} }
column, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID")) column, err := project_model.GetColumn(ctx, ctx.PathParamInt64("columnID"))
if err != nil { if err != nil {
ctx.ServerError("GetProjectColumn", err) ctx.ServerError("GetProjectColumn", err)
return nil, nil return nil, nil
} }
if column.ProjectID != ctx.PathParamInt64(":id") { if column.ProjectID != ctx.PathParamInt64("id") {
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{ ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
"message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", column.ID, project.ID), "message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", column.ID, project.ID),
}) })
@ -587,7 +587,7 @@ func MoveIssues(ctx *context.Context) {
return return
} }
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return return
@ -597,7 +597,7 @@ func MoveIssues(ctx *context.Context) {
return return
} }
column, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID")) column, err := project_model.GetColumn(ctx, ctx.PathParamInt64("columnID"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectColumn", project_model.IsErrProjectColumnNotExist, err) ctx.NotFoundOrServerError("GetProjectColumn", project_model.IsErrProjectColumnNotExist, err)
return return

View File

@ -18,8 +18,8 @@ func TestCheckProjectColumnChangePermissions(t *testing.T) {
ctx, _ := contexttest.MockContext(t, "user2/-/projects/4/4") ctx, _ := contexttest.MockContext(t, "user2/-/projects/4/4")
contexttest.LoadUser(t, ctx, 2) contexttest.LoadUser(t, ctx, 2)
ctx.ContextUser = ctx.Doer // user2 ctx.ContextUser = ctx.Doer // user2
ctx.SetPathParam(":id", "4") ctx.SetPathParam("id", "4")
ctx.SetPathParam(":columnID", "4") ctx.SetPathParam("columnID", "4")
project, column := org.CheckProjectColumnChangePermissions(ctx) project, column := org.CheckProjectColumnChangePermissions(ctx)
assert.NotNil(t, project) assert.NotNil(t, project)

View File

@ -71,7 +71,7 @@ func Teams(ctx *context.Context) {
func TeamsAction(ctx *context.Context) { func TeamsAction(ctx *context.Context) {
page := ctx.FormString("page") page := ctx.FormString("page")
var err error var err error
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "join": case "join":
if !ctx.Org.IsOwner { if !ctx.Org.IsOwner {
ctx.Error(http.StatusNotFound) ctx.Error(http.StatusNotFound)
@ -84,7 +84,7 @@ func TeamsAction(ctx *context.Context) {
if org_model.IsErrLastOrgOwner(err) { if org_model.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
} else { } else {
log.Error("Action(%s): %v", ctx.PathParam(":action"), err) log.Error("Action(%s): %v", ctx.PathParam("action"), err)
ctx.JSON(http.StatusOK, map[string]any{ ctx.JSON(http.StatusOK, map[string]any{
"ok": false, "ok": false,
"err": err.Error(), "err": err.Error(),
@ -111,7 +111,7 @@ func TeamsAction(ctx *context.Context) {
if org_model.IsErrLastOrgOwner(err) { if org_model.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
} else { } else {
log.Error("Action(%s): %v", ctx.PathParam(":action"), err) log.Error("Action(%s): %v", ctx.PathParam("action"), err)
ctx.JSON(http.StatusOK, map[string]any{ ctx.JSON(http.StatusOK, map[string]any{
"ok": false, "ok": false,
"err": err.Error(), "err": err.Error(),
@ -178,7 +178,7 @@ func TeamsAction(ctx *context.Context) {
} }
if err := org_model.RemoveInviteByID(ctx, iid, ctx.Org.Team.ID); err != nil { if err := org_model.RemoveInviteByID(ctx, iid, ctx.Org.Team.ID); err != nil {
log.Error("Action(%s): %v", ctx.PathParam(":action"), err) log.Error("Action(%s): %v", ctx.PathParam("action"), err)
ctx.ServerError("RemoveInviteByID", err) ctx.ServerError("RemoveInviteByID", err)
return return
} }
@ -192,7 +192,7 @@ func TeamsAction(ctx *context.Context) {
} else if errors.Is(err, user_model.ErrBlockedUser) { } else if errors.Is(err, user_model.ErrBlockedUser) {
ctx.Flash.Error(ctx.Tr("org.teams.members.blocked_user")) ctx.Flash.Error(ctx.Tr("org.teams.members.blocked_user"))
} else { } else {
log.Error("Action(%s): %v", ctx.PathParam(":action"), err) log.Error("Action(%s): %v", ctx.PathParam("action"), err)
ctx.JSON(http.StatusOK, map[string]any{ ctx.JSON(http.StatusOK, map[string]any{
"ok": false, "ok": false,
"err": err.Error(), "err": err.Error(),
@ -233,7 +233,7 @@ func TeamsRepoAction(ctx *context.Context) {
} }
var err error var err error
action := ctx.PathParam(":action") action := ctx.PathParam("action")
switch action { switch action {
case "add": case "add":
repoName := path.Base(ctx.FormString("repo_name")) repoName := path.Base(ctx.FormString("repo_name"))
@ -258,7 +258,7 @@ func TeamsRepoAction(ctx *context.Context) {
} }
if err != nil { if err != nil {
log.Error("Action(%s): '%s' %v", ctx.PathParam(":action"), ctx.Org.Team.Name, err) log.Error("Action(%s): '%s' %v", ctx.PathParam("action"), ctx.Org.Team.Name, err)
ctx.ServerError("TeamsRepoAction", err) ctx.ServerError("TeamsRepoAction", err)
return return
} }

View File

@ -154,5 +154,5 @@ func ServeAttachment(ctx *context.Context, uuid string) {
// GetAttachment serve attachments // GetAttachment serve attachments
func GetAttachment(ctx *context.Context) { func GetAttachment(ctx *context.Context) {
ServeAttachment(ctx, ctx.PathParam(":uuid")) ServeAttachment(ctx, ctx.PathParam("uuid"))
} }

View File

@ -24,8 +24,8 @@ var tplCherryPick templates.TplName = "repo/editor/cherry_pick"
// CherryPick handles cherrypick GETs // CherryPick handles cherrypick GETs
func CherryPick(ctx *context.Context) { func CherryPick(ctx *context.Context) {
ctx.Data["SHA"] = ctx.PathParam(":sha") ctx.Data["SHA"] = ctx.PathParam("sha")
cherryPickCommit, err := ctx.Repo.GitRepo.GetCommit(ctx.PathParam(":sha")) cherryPickCommit, err := ctx.Repo.GitRepo.GetCommit(ctx.PathParam("sha"))
if err != nil { if err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.NotFound("Missing Commit", err) ctx.NotFound("Missing Commit", err)
@ -37,7 +37,7 @@ func CherryPick(ctx *context.Context) {
if ctx.FormString("cherry-pick-type") == "revert" { if ctx.FormString("cherry-pick-type") == "revert" {
ctx.Data["CherryPickType"] = "revert" ctx.Data["CherryPickType"] = "revert"
ctx.Data["commit_summary"] = "revert " + ctx.PathParam(":sha") ctx.Data["commit_summary"] = "revert " + ctx.PathParam("sha")
ctx.Data["commit_message"] = "revert " + cherryPickCommit.Message() ctx.Data["commit_message"] = "revert " + cherryPickCommit.Message()
} else { } else {
ctx.Data["CherryPickType"] = "cherry-pick" ctx.Data["CherryPickType"] = "cherry-pick"
@ -66,7 +66,7 @@ func CherryPick(ctx *context.Context) {
func CherryPickPost(ctx *context.Context) { func CherryPickPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CherryPickForm) form := web.GetForm(ctx).(*forms.CherryPickForm)
sha := ctx.PathParam(":sha") sha := ctx.PathParam("sha")
ctx.Data["SHA"] = sha ctx.Data["SHA"] = sha
if form.Revert { if form.Revert {
ctx.Data["CherryPickType"] = "revert" ctx.Data["CherryPickType"] = "revert"
@ -140,7 +140,7 @@ func CherryPickPost(ctx *context.Context) {
if form.Revert { if form.Revert {
if err := git.GetReverseRawDiff(ctx, ctx.Repo.Repository.RepoPath(), sha, buf); err != nil { if err := git.GetReverseRawDiff(ctx, ctx.Repo.Repository.RepoPath(), sha, buf); err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam(":sha")+" does not exist.")) ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam("sha")+" does not exist."))
return return
} }
ctx.ServerError("GetRawDiff", err) ctx.ServerError("GetRawDiff", err)
@ -149,7 +149,7 @@ func CherryPickPost(ctx *context.Context) {
} else { } else {
if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, git.RawDiffType("patch"), buf); err != nil { if err := git.GetRawDiff(ctx.Repo.GitRepo, sha, git.RawDiffType("patch"), buf); err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam(":sha")+" does not exist.")) ctx.NotFound("GetRawDiff", errors.New("commit "+ctx.PathParam("sha")+" does not exist."))
return return
} }
ctx.ServerError("GetRawDiff", err) ctx.ServerError("GetRawDiff", err)

View File

@ -282,7 +282,7 @@ func Diff(ctx *context.Context) {
userName := ctx.Repo.Owner.Name userName := ctx.Repo.Owner.Name
repoName := ctx.Repo.Repository.Name repoName := ctx.Repo.Repository.Name
commitID := ctx.PathParam(":sha") commitID := ctx.PathParam("sha")
var ( var (
gitRepo *git.Repository gitRepo *git.Repository
err error err error
@ -427,13 +427,13 @@ func RawDiff(ctx *context.Context) {
} }
if err := git.GetRawDiff( if err := git.GetRawDiff(
gitRepo, gitRepo,
ctx.PathParam(":sha"), ctx.PathParam("sha"),
git.RawDiffType(ctx.PathParam(":ext")), git.RawDiffType(ctx.PathParam("ext")),
ctx.Resp, ctx.Resp,
); err != nil { ); err != nil {
if git.IsErrNotExist(err) { if git.IsErrNotExist(err) {
ctx.NotFound("GetRawDiff", ctx.NotFound("GetRawDiff",
errors.New("commit "+ctx.PathParam(":sha")+" does not exist.")) errors.New("commit "+ctx.PathParam("sha")+" does not exist."))
return return
} }
ctx.ServerError("GetRawDiff", err) ctx.ServerError("GetRawDiff", err)

View File

@ -43,7 +43,7 @@ func TestCleanUploadName(t *testing.T) {
func TestGetUniquePatchBranchName(t *testing.T) { func TestGetUniquePatchBranchName(t *testing.T) {
unittest.PrepareTestEnv(t) unittest.PrepareTestEnv(t)
ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx, _ := contexttest.MockContext(t, "user2/repo1")
ctx.SetPathParam(":id", "1") ctx.SetPathParam("id", "1")
contexttest.LoadRepo(t, ctx, 1) contexttest.LoadRepo(t, ctx, 1)
contexttest.LoadRepoCommit(t, ctx) contexttest.LoadRepoCommit(t, ctx)
contexttest.LoadUser(t, ctx, 2) contexttest.LoadUser(t, ctx, 2)
@ -58,7 +58,7 @@ func TestGetUniquePatchBranchName(t *testing.T) {
func TestGetClosestParentWithFiles(t *testing.T) { func TestGetClosestParentWithFiles(t *testing.T) {
unittest.PrepareTestEnv(t) unittest.PrepareTestEnv(t)
ctx, _ := contexttest.MockContext(t, "user2/repo1") ctx, _ := contexttest.MockContext(t, "user2/repo1")
ctx.SetPathParam(":id", "1") ctx.SetPathParam("id", "1")
contexttest.LoadRepo(t, ctx, 1) contexttest.LoadRepo(t, ctx, 1)
contexttest.LoadRepoCommit(t, ctx) contexttest.LoadRepoCommit(t, ctx)
contexttest.LoadUser(t, ctx, 2) contexttest.LoadUser(t, ctx, 2)

View File

@ -57,8 +57,8 @@ func CorsHandler() func(next http.Handler) http.Handler {
// httpBase implementation git smart HTTP protocol // httpBase implementation git smart HTTP protocol
func httpBase(ctx *context.Context) *serviceHandler { func httpBase(ctx *context.Context) *serviceHandler {
username := ctx.PathParam(":username") username := ctx.PathParam("username")
reponame := strings.TrimSuffix(ctx.PathParam(":reponame"), ".git") reponame := strings.TrimSuffix(ctx.PathParam("reponame"), ".git")
if ctx.FormString("go-get") == "1" { if ctx.FormString("go-get") == "1" {
context.EarlyResponseForGoGetMeta(ctx) context.EarlyResponseForGoGetMeta(ctx)

View File

@ -181,7 +181,7 @@ func retrieveProjectsInternal(ctx *context.Context, repo *repo_model.Repository)
// GetActionIssue will return the issue which is used in the context. // GetActionIssue will return the issue which is used in the context.
func GetActionIssue(ctx *context.Context) *issues_model.Issue { func GetActionIssue(ctx *context.Context) *issues_model.Issue {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err) ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err)
return nil return nil
@ -246,7 +246,7 @@ func getActionIssues(ctx *context.Context) issues_model.IssueList {
// GetIssueInfo get an issue of a repository // GetIssueInfo get an issue of a repository
func GetIssueInfo(ctx *context.Context) { func GetIssueInfo(ctx *context.Context) {
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.Error(http.StatusNotFound) ctx.Error(http.StatusNotFound)
@ -379,7 +379,7 @@ func UpdateIssueContent(ctx *context.Context) {
// UpdateIssueDeadline updates an issue deadline // UpdateIssueDeadline updates an issue deadline
func UpdateIssueDeadline(ctx *context.Context) { func UpdateIssueDeadline(ctx *context.Context) {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("GetIssueByIndex", err) ctx.NotFound("GetIssueByIndex", err)
@ -506,7 +506,7 @@ func ChangeIssueReaction(ctx *context.Context) {
return return
} }
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "react": case "react":
reaction, err := issue_service.CreateIssueReaction(ctx, ctx.Doer, issue, form.Content) reaction, err := issue_service.CreateIssueReaction(ctx, ctx.Doer, issue, form.Content)
if err != nil { if err != nil {
@ -540,7 +540,7 @@ func ChangeIssueReaction(ctx *context.Context) {
log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID) log.Trace("Reaction for issue removed: %d/%d", ctx.Repo.Repository.ID, issue.ID)
default: default:
ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.PathParam(":action")), nil) ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.PathParam("action")), nil)
return return
} }

View File

@ -209,7 +209,7 @@ func NewComment(ctx *context.Context) {
// UpdateCommentContent change comment of issue's content // UpdateCommentContent change comment of issue's content
func UpdateCommentContent(ctx *context.Context) { func UpdateCommentContent(ctx *context.Context) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err) ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return return
@ -287,7 +287,7 @@ func UpdateCommentContent(ctx *context.Context) {
// DeleteComment delete comment of issue // DeleteComment delete comment of issue
func DeleteComment(ctx *context.Context) { func DeleteComment(ctx *context.Context) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err) ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return return
@ -322,7 +322,7 @@ func DeleteComment(ctx *context.Context) {
// ChangeCommentReaction create a reaction for comment // ChangeCommentReaction create a reaction for comment
func ChangeCommentReaction(ctx *context.Context) { func ChangeCommentReaction(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.ReactionForm) form := web.GetForm(ctx).(*forms.ReactionForm)
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err) ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return return
@ -366,7 +366,7 @@ func ChangeCommentReaction(ctx *context.Context) {
return return
} }
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "react": case "react":
reaction, err := issue_service.CreateCommentReaction(ctx, ctx.Doer, comment, form.Content) reaction, err := issue_service.CreateCommentReaction(ctx, ctx.Doer, comment, form.Content)
if err != nil { if err != nil {
@ -400,7 +400,7 @@ func ChangeCommentReaction(ctx *context.Context) {
log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID) log.Trace("Reaction for comment removed: %d/%d/%d", ctx.Repo.Repository.ID, comment.Issue.ID, comment.ID)
default: default:
ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.PathParam(":action")), nil) ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.PathParam("action")), nil)
return return
} }
@ -427,7 +427,7 @@ func ChangeCommentReaction(ctx *context.Context) {
// GetCommentAttachments returns attachments for the comment // GetCommentAttachments returns attachments for the comment
func GetCommentAttachments(ctx *context.Context) { func GetCommentAttachments(ctx *context.Context) {
comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64(":id")) comment, err := issues_model.GetCommentByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err) ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return return

View File

@ -748,7 +748,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
// Issues render issues page // Issues render issues page
func Issues(ctx *context.Context) { func Issues(ctx *context.Context) {
isPullList := ctx.PathParam(":type") == "pulls" isPullList := ctx.PathParam("type") == "pulls"
if isPullList { if isPullList {
MustAllowPulls(ctx) MustAllowPulls(ctx)
if ctx.Written() { if ctx.Written() {

View File

@ -39,7 +39,7 @@ func IssuePinOrUnpin(ctx *context.Context) {
// IssueUnpin unpins a Issue // IssueUnpin unpins a Issue
func IssueUnpin(ctx *context.Context) { func IssueUnpin(ctx *context.Context) {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
ctx.Status(http.StatusInternalServerError) ctx.Status(http.StatusInternalServerError)
log.Error(err.Error()) log.Error(err.Error())

View File

@ -60,7 +60,7 @@ func DeleteTime(c *context.Context) {
return return
} }
t, err := issues_model.GetTrackedTimeByID(c, c.PathParamInt64(":timeid")) t, err := issues_model.GetTrackedTimeByID(c, c.PathParamInt64("timeid"))
if err != nil { if err != nil {
if db.IsErrNotExist(err) { if db.IsErrNotExist(err) {
c.NotFound("time not found", err) c.NotFound("time not found", err)

View File

@ -265,13 +265,13 @@ func combineLabelComments(issue *issues_model.Issue) {
// ViewIssue render issue view page // ViewIssue render issue view page
func ViewIssue(ctx *context.Context) { func ViewIssue(ctx *context.Context) {
if ctx.PathParam(":type") == "issues" { if ctx.PathParam("type") == "issues" {
// If issue was requested we check if repo has external tracker and redirect // If issue was requested we check if repo has external tracker and redirect
extIssueUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit.TypeExternalTracker) extIssueUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit.TypeExternalTracker)
if err == nil && extIssueUnit != nil { if err == nil && extIssueUnit != nil {
if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" { if extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == markup.IssueNameStyleNumeric || extIssueUnit.ExternalTrackerConfig().ExternalTrackerStyle == "" {
metas := ctx.Repo.Repository.ComposeMetas(ctx) metas := ctx.Repo.Repository.ComposeMetas(ctx)
metas["index"] = ctx.PathParam(":index") metas["index"] = ctx.PathParam("index")
res, err := vars.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas) res, err := vars.Expand(extIssueUnit.ExternalTrackerConfig().ExternalTrackerFormat, metas)
if err != nil { if err != nil {
log.Error("unable to expand template vars for issue url. issue: %s, err: %v", metas["index"], err) log.Error("unable to expand template vars for issue url. issue: %s, err: %v", metas["index"], err)
@ -287,7 +287,7 @@ func ViewIssue(ctx *context.Context) {
} }
} }
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("GetIssueByIndex", err) ctx.NotFound("GetIssueByIndex", err)
@ -301,10 +301,10 @@ func ViewIssue(ctx *context.Context) {
} }
// Make sure type and URL matches. // Make sure type and URL matches.
if ctx.PathParam(":type") == "issues" && issue.IsPull { if ctx.PathParam("type") == "issues" && issue.IsPull {
ctx.Redirect(issue.Link()) ctx.Redirect(issue.Link())
return return
} else if ctx.PathParam(":type") == "pulls" && !issue.IsPull { } else if ctx.PathParam("type") == "pulls" && !issue.IsPull {
ctx.Redirect(issue.Link()) ctx.Redirect(issue.Link())
return return
} }

View File

@ -147,7 +147,7 @@ func EditMilestone(ctx *context.Context) {
ctx.Data["PageIsMilestones"] = true ctx.Data["PageIsMilestones"] = true
ctx.Data["PageIsEditMilestone"] = true ctx.Data["PageIsEditMilestone"] = true
m, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id")) m, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrMilestoneNotExist(err) { if issues_model.IsErrMilestoneNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -183,7 +183,7 @@ func EditMilestonePost(ctx *context.Context) {
return return
} }
m, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id")) m, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if issues_model.IsErrMilestoneNotExist(err) { if issues_model.IsErrMilestoneNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -207,7 +207,7 @@ func EditMilestonePost(ctx *context.Context) {
// ChangeMilestoneStatus response for change a milestone's status // ChangeMilestoneStatus response for change a milestone's status
func ChangeMilestoneStatus(ctx *context.Context) { func ChangeMilestoneStatus(ctx *context.Context) {
var toClose bool var toClose bool
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "open": case "open":
toClose = false toClose = false
case "close": case "close":
@ -216,7 +216,7 @@ func ChangeMilestoneStatus(ctx *context.Context) {
ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones") ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones")
return return
} }
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
if err := issues_model.ChangeMilestoneStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil { if err := issues_model.ChangeMilestoneStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
if issues_model.IsErrMilestoneNotExist(err) { if issues_model.IsErrMilestoneNotExist(err) {
@ -226,7 +226,7 @@ func ChangeMilestoneStatus(ctx *context.Context) {
} }
return return
} }
ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones?state=" + url.QueryEscape(ctx.PathParam(":action"))) ctx.JSONRedirect(ctx.Repo.RepoLink + "/milestones?state=" + url.QueryEscape(ctx.PathParam("action")))
} }
// DeleteMilestone delete a milestone // DeleteMilestone delete a milestone
@ -242,7 +242,7 @@ func DeleteMilestone(ctx *context.Context) {
// MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone // MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
func MilestoneIssuesAndPulls(ctx *context.Context) { func MilestoneIssuesAndPulls(ctx *context.Context) {
milestoneID := ctx.PathParamInt64(":id") milestoneID := ctx.PathParamInt64("id")
projectID := ctx.FormInt64("project") projectID := ctx.FormInt64("project")
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, milestoneID) milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, milestoneID)
if err != nil { if err != nil {

View File

@ -166,7 +166,7 @@ func NewProjectPost(ctx *context.Context) {
// ChangeProjectStatus updates the status of a project between "open" and "close" // ChangeProjectStatus updates the status of a project between "open" and "close"
func ChangeProjectStatus(ctx *context.Context) { func ChangeProjectStatus(ctx *context.Context) {
var toClose bool var toClose bool
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "open": case "open":
toClose = false toClose = false
case "close": case "close":
@ -175,7 +175,7 @@ func ChangeProjectStatus(ctx *context.Context) {
ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects") ctx.JSONRedirect(ctx.Repo.RepoLink + "/projects")
return return
} }
id := ctx.PathParamInt64(":id") id := ctx.PathParamInt64("id")
if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil { if err := project_model.ChangeProjectStatusByRepoIDAndID(ctx, ctx.Repo.Repository.ID, id, toClose); err != nil {
ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("ChangeProjectStatusByRepoIDAndID", project_model.IsErrProjectNotExist, err)
@ -186,7 +186,7 @@ func ChangeProjectStatus(ctx *context.Context) {
// DeleteProject delete a project // DeleteProject delete a project
func DeleteProject(ctx *context.Context) { func DeleteProject(ctx *context.Context) {
p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -216,7 +216,7 @@ func RenderEditProject(ctx *context.Context) {
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects) ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(unit.TypeProjects)
ctx.Data["CardTypes"] = project_model.GetCardConfig() ctx.Data["CardTypes"] = project_model.GetCardConfig()
p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) p, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -243,7 +243,7 @@ func RenderEditProject(ctx *context.Context) {
// EditProjectPost response for editing a project // EditProjectPost response for editing a project
func EditProjectPost(ctx *context.Context) { func EditProjectPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CreateProjectForm) form := web.GetForm(ctx).(*forms.CreateProjectForm)
projectID := ctx.PathParamInt64(":id") projectID := ctx.PathParamInt64("id")
ctx.Data["Title"] = ctx.Tr("repo.projects.edit") ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
ctx.Data["PageIsEditProjects"] = true ctx.Data["PageIsEditProjects"] = true
@ -288,7 +288,7 @@ func EditProjectPost(ctx *context.Context) {
// ViewProject renders the project with board view // ViewProject renders the project with board view
func ViewProject(ctx *context.Context) { func ViewProject(ctx *context.Context) {
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -468,7 +468,7 @@ func DeleteProjectColumn(ctx *context.Context) {
return return
} }
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -478,12 +478,12 @@ func DeleteProjectColumn(ctx *context.Context) {
return return
} }
pb, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID")) pb, err := project_model.GetColumn(ctx, ctx.PathParamInt64("columnID"))
if err != nil { if err != nil {
ctx.ServerError("GetProjectColumn", err) ctx.ServerError("GetProjectColumn", err)
return return
} }
if pb.ProjectID != ctx.PathParamInt64(":id") { if pb.ProjectID != ctx.PathParamInt64("id") {
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{ ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
"message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", pb.ID, project.ID), "message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", pb.ID, project.ID),
}) })
@ -497,7 +497,7 @@ func DeleteProjectColumn(ctx *context.Context) {
return return
} }
if err := project_model.DeleteColumnByID(ctx, ctx.PathParamInt64(":columnID")); err != nil { if err := project_model.DeleteColumnByID(ctx, ctx.PathParamInt64("columnID")); err != nil {
ctx.ServerError("DeleteProjectColumnByID", err) ctx.ServerError("DeleteProjectColumnByID", err)
return return
} }
@ -515,7 +515,7 @@ func AddColumnToProjectPost(ctx *context.Context) {
return return
} }
project, err := project_model.GetProjectForRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectForRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -553,7 +553,7 @@ func checkProjectColumnChangePermissions(ctx *context.Context) (*project_model.P
return nil, nil return nil, nil
} }
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("", nil) ctx.NotFound("", nil)
@ -563,12 +563,12 @@ func checkProjectColumnChangePermissions(ctx *context.Context) (*project_model.P
return nil, nil return nil, nil
} }
column, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID")) column, err := project_model.GetColumn(ctx, ctx.PathParamInt64("columnID"))
if err != nil { if err != nil {
ctx.ServerError("GetProjectColumn", err) ctx.ServerError("GetProjectColumn", err)
return nil, nil return nil, nil
} }
if column.ProjectID != ctx.PathParamInt64(":id") { if column.ProjectID != ctx.PathParamInt64("id") {
ctx.JSON(http.StatusUnprocessableEntity, map[string]string{ ctx.JSON(http.StatusUnprocessableEntity, map[string]string{
"message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", column.ID, project.ID), "message": fmt.Sprintf("ProjectColumn[%d] is not in Project[%d] as expected", column.ID, project.ID),
}) })
@ -639,7 +639,7 @@ func MoveIssues(ctx *context.Context) {
return return
} }
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.NotFound("ProjectNotExist", nil) ctx.NotFound("ProjectNotExist", nil)
@ -653,7 +653,7 @@ func MoveIssues(ctx *context.Context) {
return return
} }
column, err := project_model.GetColumn(ctx, ctx.PathParamInt64(":columnID")) column, err := project_model.GetColumn(ctx, ctx.PathParamInt64("columnID"))
if err != nil { if err != nil {
if project_model.IsErrProjectColumnNotExist(err) { if project_model.IsErrProjectColumnNotExist(err) {
ctx.NotFound("ProjectColumnNotExist", nil) ctx.NotFound("ProjectColumnNotExist", nil)

View File

@ -17,8 +17,8 @@ func TestCheckProjectColumnChangePermissions(t *testing.T) {
ctx, _ := contexttest.MockContext(t, "user2/repo1/projects/1/2") ctx, _ := contexttest.MockContext(t, "user2/repo1/projects/1/2")
contexttest.LoadUser(t, ctx, 2) contexttest.LoadUser(t, ctx, 2)
contexttest.LoadRepo(t, ctx, 1) contexttest.LoadRepo(t, ctx, 1)
ctx.SetPathParam(":id", "1") ctx.SetPathParam("id", "1")
ctx.SetPathParam(":columnID", "2") ctx.SetPathParam("columnID", "2")
project, column := checkProjectColumnChangePermissions(ctx) project, column := checkProjectColumnChangePermissions(ctx)
assert.NotNil(t, project) assert.NotNil(t, project)

View File

@ -108,7 +108,7 @@ func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository {
} }
func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) { func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrIssueNotExist(err) { if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("GetIssueByIndex", err) ctx.NotFound("GetIssueByIndex", err)
@ -1544,7 +1544,7 @@ func DownloadPullPatch(ctx *context.Context) {
// DownloadPullDiffOrPatch render a pull's raw diff or patch // DownloadPullDiffOrPatch render a pull's raw diff or patch
func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) { func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)
@ -1637,7 +1637,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
func SetAllowEdits(ctx *context.Context) { func SetAllowEdits(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.UpdateAllowEditsForm) form := web.GetForm(ctx).(*forms.UpdateAllowEditsForm)
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":index")) pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil { if err != nil {
if issues_model.IsErrPullRequestNotExist(err) { if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err) ctx.NotFound("GetPullRequestByIndex", err)

View File

@ -311,7 +311,7 @@ const (
// Action response for actions to a repository // Action response for actions to a repository
func Action(ctx *context.Context) { func Action(ctx *context.Context) {
var err error var err error
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "watch": case "watch":
err = repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, true) err = repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
case "unwatch": case "unwatch":
@ -339,12 +339,12 @@ func Action(ctx *context.Context) {
if errors.Is(err, user_model.ErrBlockedUser) { if errors.Is(err, user_model.ErrBlockedUser) {
ctx.Flash.Error(ctx.Tr("repo.action.blocked_user")) ctx.Flash.Error(ctx.Tr("repo.action.blocked_user"))
} else { } else {
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.PathParam(":action")), err) ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.PathParam("action")), err)
return return
} }
} }
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "watch", "unwatch": case "watch", "unwatch":
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
case "star", "unstar": case "star", "unstar":
@ -354,17 +354,17 @@ func Action(ctx *context.Context) {
// see the `hx-trigger="refreshUserCards ..."` comments in tmpl // see the `hx-trigger="refreshUserCards ..."` comments in tmpl
ctx.RespHeader().Add("hx-trigger", "refreshUserCards") ctx.RespHeader().Add("hx-trigger", "refreshUserCards")
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "watch", "unwatch", "star", "unstar": case "watch", "unwatch", "star", "unstar":
// we have to reload the repository because NumStars or NumWatching (used in the templates) has just changed // we have to reload the repository because NumStars or NumWatching (used in the templates) has just changed
ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name) ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name)
if err != nil { if err != nil {
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.PathParam(":action")), err) ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.PathParam("action")), err)
return return
} }
} }
switch ctx.PathParam(":action") { switch ctx.PathParam("action") {
case "watch", "unwatch": case "watch", "unwatch":
ctx.HTML(http.StatusOK, tplWatchUnwatch) ctx.HTML(http.StatusOK, tplWatchUnwatch)
return return

View File

@ -30,7 +30,7 @@ func GitHooksEdit(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks") ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")
ctx.Data["PageIsSettingsGitHooks"] = true ctx.Data["PageIsSettingsGitHooks"] = true
name := ctx.PathParam(":name") name := ctx.PathParam("name")
hook, err := ctx.Repo.GitRepo.GetHook(name) hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil { if err != nil {
if err == git.ErrNotValidHook { if err == git.ErrNotValidHook {
@ -46,7 +46,7 @@ func GitHooksEdit(ctx *context.Context) {
// GitHooksEditPost response for editing a git hook of a repository // GitHooksEditPost response for editing a git hook of a repository
func GitHooksEditPost(ctx *context.Context) { func GitHooksEditPost(ctx *context.Context) {
name := ctx.PathParam(":name") name := ctx.PathParam("name")
hook, err := ctx.Repo.GitRepo.GetHook(name) hook, err := ctx.Repo.GitRepo.GetHook(name)
if err != nil { if err != nil {
if err == git.ErrNotValidHook { if err == git.ErrNotValidHook {

View File

@ -170,7 +170,7 @@ func setTagsContext(ctx *context.Context) error {
func selectProtectedTagByContext(ctx *context.Context) *git_model.ProtectedTag { func selectProtectedTagByContext(ctx *context.Context) *git_model.ProtectedTag {
id := ctx.FormInt64("id") id := ctx.FormInt64("id")
if id == 0 { if id == 0 {
id = ctx.PathParamInt64(":id") id = ctx.PathParamInt64("id")
} }
tag, err := git_model.GetProtectedTagByID(ctx, id) tag, err := git_model.GetProtectedTagByID(ctx, id)

View File

@ -147,7 +147,7 @@ func RunnersEdit(ctx *context.Context) {
} }
actions_shared.RunnerDetails(ctx, page, actions_shared.RunnerDetails(ctx, page,
ctx.PathParamInt64(":runnerid"), rCtx.OwnerID, rCtx.RepoID, ctx.PathParamInt64("runnerid"), rCtx.OwnerID, rCtx.RepoID,
) )
ctx.HTML(http.StatusOK, rCtx.RunnerEditTemplate) ctx.HTML(http.StatusOK, rCtx.RunnerEditTemplate)
} }
@ -158,9 +158,9 @@ func RunnersEditPost(ctx *context.Context) {
ctx.ServerError("getRunnersCtx", err) ctx.ServerError("getRunnersCtx", err)
return return
} }
actions_shared.RunnerDetailsEditPost(ctx, ctx.PathParamInt64(":runnerid"), actions_shared.RunnerDetailsEditPost(ctx, ctx.PathParamInt64("runnerid"),
rCtx.OwnerID, rCtx.RepoID, rCtx.OwnerID, rCtx.RepoID,
rCtx.RedirectLink+url.PathEscape(ctx.PathParam(":runnerid"))) rCtx.RedirectLink+url.PathEscape(ctx.PathParam("runnerid")))
} }
func ResetRunnerRegistrationToken(ctx *context.Context) { func ResetRunnerRegistrationToken(ctx *context.Context) {
@ -179,7 +179,7 @@ func RunnerDeletePost(ctx *context.Context) {
ctx.ServerError("getRunnersCtx", err) ctx.ServerError("getRunnersCtx", err)
return return
} }
actions_shared.RunnerDeletePost(ctx, ctx.PathParamInt64(":runnerid"), rCtx.RedirectLink, rCtx.RedirectLink+url.PathEscape(ctx.PathParam(":runnerid"))) actions_shared.RunnerDeletePost(ctx, ctx.PathParamInt64("runnerid"), rCtx.RedirectLink, rCtx.RedirectLink+url.PathEscape(ctx.PathParam("runnerid")))
} }
func RedirectToDefaultSetting(ctx *context.Context) { func RedirectToDefaultSetting(ctx *context.Context) {

View File

@ -99,9 +99,9 @@ func getOwnerRepoCtx(ctx *context.Context) (*ownerRepoCtx, error) {
if ctx.Data["PageIsAdmin"] == true { if ctx.Data["PageIsAdmin"] == true {
return &ownerRepoCtx{ return &ownerRepoCtx{
IsAdmin: true, IsAdmin: true,
IsSystemWebhook: ctx.PathParam(":configType") == "system-hooks", IsSystemWebhook: ctx.PathParam("configType") == "system-hooks",
Link: path.Join(setting.AppSubURL, "/-/admin/hooks"), Link: path.Join(setting.AppSubURL, "/-/admin/hooks"),
LinkNew: path.Join(setting.AppSubURL, "/-/admin/", ctx.PathParam(":configType")), LinkNew: path.Join(setting.AppSubURL, "/-/admin/", ctx.PathParam("configType")),
NewTemplate: tplAdminHookNew, NewTemplate: tplAdminHookNew,
}, nil }, nil
} }
@ -110,7 +110,7 @@ func getOwnerRepoCtx(ctx *context.Context) (*ownerRepoCtx, error) {
} }
func checkHookType(ctx *context.Context) string { func checkHookType(ctx *context.Context) string {
hookType := strings.ToLower(ctx.PathParam(":type")) hookType := strings.ToLower(ctx.PathParam("type"))
if !util.SliceContainsString(setting.Webhook.Types, hookType, true) { if !util.SliceContainsString(setting.Webhook.Types, hookType, true) {
ctx.NotFound("checkHookType", nil) ctx.NotFound("checkHookType", nil)
return "" return ""
@ -592,11 +592,11 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
var w *webhook.Webhook var w *webhook.Webhook
if orCtx.RepoID > 0 { if orCtx.RepoID > 0 {
w, err = webhook.GetWebhookByRepoID(ctx, orCtx.RepoID, ctx.PathParamInt64(":id")) w, err = webhook.GetWebhookByRepoID(ctx, orCtx.RepoID, ctx.PathParamInt64("id"))
} else if orCtx.OwnerID > 0 { } else if orCtx.OwnerID > 0 {
w, err = webhook.GetWebhookByOwnerID(ctx, orCtx.OwnerID, ctx.PathParamInt64(":id")) w, err = webhook.GetWebhookByOwnerID(ctx, orCtx.OwnerID, ctx.PathParamInt64("id"))
} else if orCtx.IsAdmin { } else if orCtx.IsAdmin {
w, err = webhook.GetSystemOrDefaultWebhook(ctx, ctx.PathParamInt64(":id")) w, err = webhook.GetSystemOrDefaultWebhook(ctx, ctx.PathParamInt64("id"))
} }
if err != nil || w == nil { if err != nil || w == nil {
if webhook.IsErrWebhookNotExist(err) { if webhook.IsErrWebhookNotExist(err) {
@ -645,7 +645,7 @@ func WebHooksEdit(ctx *context.Context) {
// TestWebhook test if web hook is work fine // TestWebhook test if web hook is work fine
func TestWebhook(ctx *context.Context) { func TestWebhook(ctx *context.Context) {
hookID := ctx.PathParamInt64(":id") hookID := ctx.PathParamInt64("id")
w, err := webhook.GetWebhookByRepoID(ctx, ctx.Repo.Repository.ID, hookID) w, err := webhook.GetWebhookByRepoID(ctx, ctx.Repo.Repository.ID, hookID)
if err != nil { if err != nil {
ctx.Flash.Error("GetWebhookByRepoID: " + err.Error()) ctx.Flash.Error("GetWebhookByRepoID: " + err.Error())
@ -706,7 +706,7 @@ func TestWebhook(ctx *context.Context) {
// ReplayWebhook replays a webhook // ReplayWebhook replays a webhook
func ReplayWebhook(ctx *context.Context) { func ReplayWebhook(ctx *context.Context) {
hookTaskUUID := ctx.PathParam(":uuid") hookTaskUUID := ctx.PathParam("uuid")
orCtx, w := checkWebhook(ctx) orCtx, w := checkWebhook(ctx)
if ctx.Written() { if ctx.Written() {

View File

@ -276,7 +276,7 @@ func prepareToRenderDirOrFile(entry *git.TreeEntry) func(ctx *context.Context) {
func handleRepoHomeFeed(ctx *context.Context) bool { func handleRepoHomeFeed(ctx *context.Context) bool {
if setting.Other.EnableFeed { if setting.Other.EnableFeed {
isFeed, _, showFeedType := feed.GetFeedType(ctx.PathParam(":reponame"), ctx.Req) isFeed, _, showFeedType := feed.GetFeedType(ctx.PathParam("reponame"), ctx.Req)
if isFeed { if isFeed {
switch { switch {
case ctx.Link == fmt.Sprintf("%s.%s", ctx.Repo.RepoLink, showFeedType): case ctx.Link == fmt.Sprintf("%s.%s", ctx.Repo.RepoLink, showFeedType):

View File

@ -40,7 +40,7 @@ func CreateVariable(ctx *context.Context, ownerID, repoID int64, redirectURL str
} }
func UpdateVariable(ctx *context.Context, redirectURL string) { func UpdateVariable(ctx *context.Context, redirectURL string) {
id := ctx.PathParamInt64(":variable_id") id := ctx.PathParamInt64("variable_id")
form := web.GetForm(ctx).(*forms.EditVariableForm) form := web.GetForm(ctx).(*forms.EditVariableForm)
if ok, err := actions_service.UpdateVariable(ctx, id, form.Name, form.Data); err != nil || !ok { if ok, err := actions_service.UpdateVariable(ctx, id, form.Name, form.Data); err != nil || !ok {
@ -53,7 +53,7 @@ func UpdateVariable(ctx *context.Context, redirectURL string) {
} }
func DeleteVariable(ctx *context.Context, redirectURL string) { func DeleteVariable(ctx *context.Context, redirectURL string) {
id := ctx.PathParamInt64(":variable_id") id := ctx.PathParamInt64("variable_id")
if err := actions_service.DeleteVariableByID(ctx, id); err != nil { if err := actions_service.DeleteVariableByID(ctx, id); err != nil {
log.Error("Delete variable [%d] failed: %v", id, err) log.Error("Delete variable [%d] failed: %v", id, err)

View File

@ -11,7 +11,7 @@ import (
// MoveColumns moves or keeps columns in a project and sorts them inside that project // MoveColumns moves or keeps columns in a project and sorts them inside that project
func MoveColumns(ctx *context.Context) { func MoveColumns(ctx *context.Context) {
project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64(":id")) project, err := project_model.GetProjectByID(ctx, ctx.PathParamInt64("id"))
if err != nil { if err != nil {
ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err) ctx.NotFoundOrServerError("GetProjectByID", project_model.IsErrProjectNotExist, err)
return return

View File

@ -23,8 +23,8 @@ func cacheableRedirect(ctx *context.Context, location string) {
// AvatarByUserName redirect browser to user avatar of requested size // AvatarByUserName redirect browser to user avatar of requested size
func AvatarByUserName(ctx *context.Context) { func AvatarByUserName(ctx *context.Context) {
userName := ctx.PathParam(":username") userName := ctx.PathParam("username")
size := int(ctx.PathParamInt64(":size")) size := int(ctx.PathParamInt64("size"))
var user *user_model.User var user *user_model.User
if strings.ToLower(userName) != user_model.GhostUserLowerName { if strings.ToLower(userName) != user_model.GhostUserLowerName {
@ -46,7 +46,7 @@ func AvatarByUserName(ctx *context.Context) {
// AvatarByEmailHash redirects the browser to the email avatar link // AvatarByEmailHash redirects the browser to the email avatar link
func AvatarByEmailHash(ctx *context.Context) { func AvatarByEmailHash(ctx *context.Context) {
hash := ctx.PathParam(":hash") hash := ctx.PathParam("hash")
email, err := avatars.GetEmailForHash(ctx, hash) email, err := avatars.GetEmailForHash(ctx, hash)
if err != nil { if err != nil {
ctx.ServerError("invalid avatar hash: "+hash, err) ctx.ServerError("invalid avatar hash: "+hash, err)

View File

@ -56,7 +56,7 @@ const (
// getDashboardContextUser finds out which context user dashboard is being viewed as . // getDashboardContextUser finds out which context user dashboard is being viewed as .
func getDashboardContextUser(ctx *context.Context) *user_model.User { func getDashboardContextUser(ctx *context.Context) *user_model.User {
ctxUser := ctx.Doer ctxUser := ctx.Doer
orgName := ctx.PathParam(":org") orgName := ctx.PathParam("org")
if len(orgName) > 0 { if len(orgName) > 0 {
ctxUser = ctx.Org.Organization.AsUser() ctxUser = ctx.Org.Organization.AsUser()
ctx.Data["Teams"] = ctx.Org.Teams ctx.Data["Teams"] = ctx.Org.Teams

View File

@ -502,7 +502,7 @@ func PackageSettingsPost(ctx *context.Context) {
// DownloadPackageFile serves the content of a package file // DownloadPackageFile serves the content of a package file
func DownloadPackageFile(ctx *context.Context) { func DownloadPackageFile(ctx *context.Context) {
pf, err := packages_model.GetFileForVersionByID(ctx, ctx.Package.Descriptor.Version.ID, ctx.PathParamInt64(":fileid")) pf, err := packages_model.GetFileForVersionByID(ctx, ctx.Package.Descriptor.Version.ID, ctx.PathParamInt64("fileid"))
if err != nil { if err != nil {
if err == packages_model.ErrPackageFileNotExist { if err == packages_model.ErrPackageFileNotExist {
ctx.NotFound("", err) ctx.NotFound("", err)

View File

@ -9,20 +9,15 @@ import (
"html/template" "html/template"
"io" "io"
"net/http" "net/http"
"net/url"
"strconv"
"strings" "strings"
"code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/reqctx" "code.gitea.io/gitea/modules/reqctx"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/modules/web/middleware"
"github.com/go-chi/chi/v5"
) )
type BaseContextKeyType struct{} type BaseContextKeyType struct{}
@ -107,93 +102,6 @@ func (b *Base) RemoteAddr() string {
return b.Req.RemoteAddr return b.Req.RemoteAddr
} }
// PathParam returns the param in request path, eg: "/{var}" => "/a%2fb", then `var == "a/b"`
func (b *Base) PathParam(name string) string {
s, err := url.PathUnescape(b.PathParamRaw(name))
if err != nil && !setting.IsProd {
panic("Failed to unescape path param: " + err.Error() + ", there seems to be a double-unescaping bug")
}
return s
}
// PathParamRaw returns the raw param in request path, eg: "/{var}" => "/a%2fb", then `var == "a%2fb"`
func (b *Base) PathParamRaw(name string) string {
return chi.URLParam(b.Req, strings.TrimPrefix(name, ":"))
}
// PathParamInt64 returns the param in request path as int64
func (b *Base) PathParamInt64(p string) int64 {
v, _ := strconv.ParseInt(b.PathParam(p), 10, 64)
return v
}
// SetPathParam set request path params into routes
func (b *Base) SetPathParam(k, v string) {
chiCtx := chi.RouteContext(b)
chiCtx.URLParams.Add(strings.TrimPrefix(k, ":"), url.PathEscape(v))
}
// FormString returns the first value matching the provided key in the form as a string
func (b *Base) FormString(key string) string {
return b.Req.FormValue(key)
}
// FormStrings returns a string slice for the provided key from the form
func (b *Base) FormStrings(key string) []string {
if b.Req.Form == nil {
if err := b.Req.ParseMultipartForm(32 << 20); err != nil {
return nil
}
}
if v, ok := b.Req.Form[key]; ok {
return v
}
return nil
}
// FormTrim returns the first value for the provided key in the form as a space trimmed string
func (b *Base) FormTrim(key string) string {
return strings.TrimSpace(b.Req.FormValue(key))
}
// FormInt returns the first value for the provided key in the form as an int
func (b *Base) FormInt(key string) int {
v, _ := strconv.Atoi(b.Req.FormValue(key))
return v
}
// FormInt64 returns the first value for the provided key in the form as an int64
func (b *Base) FormInt64(key string) int64 {
v, _ := strconv.ParseInt(b.Req.FormValue(key), 10, 64)
return v
}
// FormBool returns true if the value for the provided key in the form is "1", "true" or "on"
func (b *Base) FormBool(key string) bool {
s := b.Req.FormValue(key)
v, _ := strconv.ParseBool(s)
v = v || strings.EqualFold(s, "on")
return v
}
// FormOptionalBool returns an optional.Some(true) or optional.Some(false) if the value
// for the provided key exists in the form else it returns optional.None[bool]()
func (b *Base) FormOptionalBool(key string) optional.Option[bool] {
value := b.Req.FormValue(key)
if len(value) == 0 {
return optional.None[bool]()
}
s := b.Req.FormValue(key)
v, _ := strconv.ParseBool(s)
v = v || strings.EqualFold(s, "on")
return optional.Some(v)
}
func (b *Base) SetFormString(key, value string) {
_ = b.Req.FormValue(key) // force parse form
b.Req.Form.Set(key, value)
}
// PlainTextBytes renders bytes as plain text // PlainTextBytes renders bytes as plain text
func (b *Base) plainTextInternal(skip, status int, bs []byte) { func (b *Base) plainTextInternal(skip, status int, bs []byte) {
statusPrefix := status / 100 statusPrefix := status / 100

View File

@ -0,0 +1,72 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package context
import (
"strconv"
"strings"
"code.gitea.io/gitea/modules/optional"
)
// FormString returns the first value matching the provided key in the form as a string
func (b *Base) FormString(key string) string {
return b.Req.FormValue(key)
}
// FormStrings returns a string slice for the provided key from the form
func (b *Base) FormStrings(key string) []string {
if b.Req.Form == nil {
if err := b.Req.ParseMultipartForm(32 << 20); err != nil {
return nil
}
}
if v, ok := b.Req.Form[key]; ok {
return v
}
return nil
}
// FormTrim returns the first value for the provided key in the form as a space trimmed string
func (b *Base) FormTrim(key string) string {
return strings.TrimSpace(b.Req.FormValue(key))
}
// FormInt returns the first value for the provided key in the form as an int
func (b *Base) FormInt(key string) int {
v, _ := strconv.Atoi(b.Req.FormValue(key))
return v
}
// FormInt64 returns the first value for the provided key in the form as an int64
func (b *Base) FormInt64(key string) int64 {
v, _ := strconv.ParseInt(b.Req.FormValue(key), 10, 64)
return v
}
// FormBool returns true if the value for the provided key in the form is "1", "true" or "on"
func (b *Base) FormBool(key string) bool {
s := b.Req.FormValue(key)
v, _ := strconv.ParseBool(s)
v = v || strings.EqualFold(s, "on")
return v
}
// FormOptionalBool returns an optional.Some(true) or optional.Some(false) if the value
// for the provided key exists in the form else it returns optional.None[bool]()
func (b *Base) FormOptionalBool(key string) optional.Option[bool] {
value := b.Req.FormValue(key)
if len(value) == 0 {
return optional.None[bool]()
}
s := b.Req.FormValue(key)
v, _ := strconv.ParseBool(s)
v = v || strings.EqualFold(s, "on")
return optional.Some(v)
}
func (b *Base) SetFormString(key, value string) {
_ = b.Req.FormValue(key) // force parse form
b.Req.Form.Set(key, value)
}

View File

@ -0,0 +1,47 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package context
import (
"net/url"
"strconv"
"strings"
"code.gitea.io/gitea/modules/setting"
"github.com/go-chi/chi/v5"
)
// PathParam returns the param in request path, eg: "/{var}" => "/a%2fb", then `var == "a/b"`
func (b *Base) PathParam(name string) string {
s, err := url.PathUnescape(b.PathParamRaw(name))
if err != nil && !setting.IsProd {
panic("Failed to unescape path param: " + err.Error() + ", there seems to be a double-unescaping bug")
}
return s
}
// PathParamRaw returns the raw param in request path, eg: "/{var}" => "/a%2fb", then `var == "a%2fb"`
func (b *Base) PathParamRaw(name string) string {
if strings.HasPrefix(name, ":") {
setting.PanicInDevOrTesting("path param should not start with ':'")
name = name[1:]
}
return chi.URLParam(b.Req, name)
}
// PathParamInt64 returns the param in request path as int64
func (b *Base) PathParamInt64(p string) int64 {
v, _ := strconv.ParseInt(b.PathParam(p), 10, 64)
return v
}
// SetPathParam set request path params into routes
func (b *Base) SetPathParam(name, value string) {
if strings.HasPrefix(name, ":") {
setting.PanicInDevOrTesting("path param should not start with ':'")
name = name[1:]
}
chi.RouteContext(b).URLParams.Add(name, url.PathEscape(value))
}

View File

@ -40,7 +40,7 @@ func (org *Organization) CanReadUnit(ctx *Context, unitType unit.Type) bool {
} }
func GetOrganizationByParams(ctx *Context) { func GetOrganizationByParams(ctx *Context) {
orgName := ctx.PathParam(":org") orgName := ctx.PathParam("org")
var err error var err error
@ -220,7 +220,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
ctx.Data["NumTeams"] = len(ctx.Org.Teams) ctx.Data["NumTeams"] = len(ctx.Org.Teams)
} }
teamName := ctx.PathParam(":team") teamName := ctx.PathParam("team")
if len(teamName) > 0 { if len(teamName) > 0 {
teamExists := false teamExists := false
for _, team := range ctx.Org.Teams { for _, team := range ctx.Org.Teams {

View File

@ -316,8 +316,8 @@ func ComposeGoGetImport(ctx context.Context, owner, repo string) string {
// This is particular a workaround for "go get" command which does not respect // This is particular a workaround for "go get" command which does not respect
// .netrc file. // .netrc file.
func EarlyResponseForGoGetMeta(ctx *Context) { func EarlyResponseForGoGetMeta(ctx *Context) {
username := ctx.PathParam(":username") username := ctx.PathParam("username")
reponame := strings.TrimSuffix(ctx.PathParam(":reponame"), ".git") reponame := strings.TrimSuffix(ctx.PathParam("reponame"), ".git")
if username == "" || reponame == "" { if username == "" || reponame == "" {
ctx.PlainText(http.StatusBadRequest, "invalid repository path") ctx.PlainText(http.StatusBadRequest, "invalid repository path")
return return
@ -336,8 +336,8 @@ func EarlyResponseForGoGetMeta(ctx *Context) {
// RedirectToRepo redirect to a differently-named repository // RedirectToRepo redirect to a differently-named repository
func RedirectToRepo(ctx *Base, redirectRepoID int64) { func RedirectToRepo(ctx *Base, redirectRepoID int64) {
ownerName := ctx.PathParam(":username") ownerName := ctx.PathParam("username")
previousRepoName := ctx.PathParam(":reponame") previousRepoName := ctx.PathParam("reponame")
repo, err := repo_model.GetRepositoryByID(ctx, redirectRepoID) repo, err := repo_model.GetRepositoryByID(ctx, redirectRepoID)
if err != nil { if err != nil {
@ -412,8 +412,8 @@ func RepoAssignment(ctx *Context) {
err error err error
) )
userName := ctx.PathParam(":username") userName := ctx.PathParam("username")
repoName := ctx.PathParam(":reponame") repoName := ctx.PathParam("reponame")
repoName = strings.TrimSuffix(repoName, ".git") repoName = strings.TrimSuffix(repoName, ".git")
if setting.Other.EnableFeed { if setting.Other.EnableFeed {
repoName = strings.TrimSuffix(repoName, ".rss") repoName = strings.TrimSuffix(repoName, ".rss")
@ -456,7 +456,7 @@ func RepoAssignment(ctx *Context) {
if strings.HasSuffix(repoName, ".wiki") { if strings.HasSuffix(repoName, ".wiki") {
// ctx.Req.URL.Path does not have the preceding appSubURL - any redirect must have this added // ctx.Req.URL.Path does not have the preceding appSubURL - any redirect must have this added
// Now we happen to know that all of our paths are: /:username/:reponame/whatever_else // Now we happen to know that all of our paths are: /:username/:reponame/whatever_else
originalRepoName := ctx.PathParam(":reponame") originalRepoName := ctx.PathParam("reponame")
redirectRepoName := strings.TrimSuffix(repoName, ".wiki") redirectRepoName := strings.TrimSuffix(repoName, ".wiki")
redirectRepoName += originalRepoName[len(redirectRepoName)+5:] redirectRepoName += originalRepoName[len(redirectRepoName)+5:]
redirectPath := strings.Replace( redirectPath := strings.Replace(

View File

@ -97,8 +97,8 @@ func AddUploadContext(ctx *context.Context, uploadType string) {
} else if uploadType == "comment" { } else if uploadType == "comment" {
ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/issues/attachments" ctx.Data["UploadUrl"] = ctx.Repo.RepoLink + "/issues/attachments"
ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/issues/attachments/remove" ctx.Data["UploadRemoveUrl"] = ctx.Repo.RepoLink + "/issues/attachments/remove"
if len(ctx.PathParam(":index")) > 0 { if len(ctx.PathParam("index")) > 0 {
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/" + url.PathEscape(ctx.PathParam(":index")) + "/attachments" ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/" + url.PathEscape(ctx.PathParam("index")) + "/attachments"
} else { } else {
ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/attachments" ctx.Data["UploadLinkUrl"] = ctx.Repo.RepoLink + "/issues/attachments"
} }

View File

@ -33,7 +33,7 @@ func UserAssignmentWeb() func(ctx *Context) {
// UserIDAssignmentAPI returns a middleware to handle context-user assignment for api routes // UserIDAssignmentAPI returns a middleware to handle context-user assignment for api routes
func UserIDAssignmentAPI() func(ctx *APIContext) { func UserIDAssignmentAPI() func(ctx *APIContext) {
return func(ctx *APIContext) { return func(ctx *APIContext) {
userID := ctx.PathParamInt64(":user-id") userID := ctx.PathParamInt64("user-id")
if ctx.IsSigned && ctx.Doer.ID == userID { if ctx.IsSigned && ctx.Doer.ID == userID {
ctx.ContextUser = ctx.Doer ctx.ContextUser = ctx.Doer
@ -59,7 +59,7 @@ func UserAssignmentAPI() func(ctx *APIContext) {
} }
func userAssignment(ctx *Base, doer *user_model.User, errCb func(int, string, any)) (contextUser *user_model.User) { func userAssignment(ctx *Base, doer *user_model.User, errCb func(int, string, any)) (contextUser *user_model.User) {
username := ctx.PathParam(":username") username := ctx.PathParam("username")
if doer != nil && doer.LowerName == strings.ToLower(username) { if doer != nil && doer.LowerName == strings.ToLower(username) {
contextUser = doer contextUser = doer

View File

@ -41,9 +41,19 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io
} }
defer closer.Close() defer closer.Close()
if err := gitRepo.GetDiffOrPatch(pr.MergeBase, pr.GetGitRefName(), w, patch, binary); err != nil { compareArg := pr.MergeBase + "..." + pr.GetGitRefName()
log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) switch {
return fmt.Errorf("Unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) case patch:
err = gitRepo.GetPatch(compareArg, w)
case binary:
err = gitRepo.GetDiffBinary(compareArg, w)
default:
err = gitRepo.GetDiff(compareArg, w)
}
if err != nil {
log.Error("unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
return fmt.Errorf("unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
} }
return nil return nil
} }
@ -354,7 +364,7 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
_ = util.Remove(tmpPatchFile.Name()) _ = util.Remove(tmpPatchFile.Name())
}() }()
if err := gitRepo.GetDiffBinary(pr.MergeBase, "tracking", tmpPatchFile); err != nil { if err := gitRepo.GetDiffBinary(pr.MergeBase+"...tracking", tmpPatchFile); err != nil {
tmpPatchFile.Close() tmpPatchFile.Close()
log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) log.Error("Unable to get patch file from %s to %s in %s Error: %v", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)
return false, fmt.Errorf("unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err) return false, fmt.Errorf("unable to get patch file from %s to %s in %s Error: %w", pr.MergeBase, pr.HeadBranch, pr.BaseRepo.FullName(), err)

Some files were not shown because too many files have changed in this diff Show More