chore: enable forcetypeassert linter, fix issues (#38804)

Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert)
linter to prevent unchecked type assertions. ~650 issues fixed, most
fixes were clean, some use `setting.PanicInDevOrTesting`.

The only behaviour changes are where code would previously send a 500 error
or panic, a 4xx error is now emitted.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-08-09 12:25:06 +02:00
committed by GitHub
parent fac8bf2eca
commit 76a81b24f9
248 changed files with 1110 additions and 995 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ func ListCronTasks(ctx *context.APIContext) {
count := len(tasks)
listOpts := utils.GetListOptions(ctx)
tasks = util.PaginateSlice(tasks, listOpts.Page, listOpts.PageSize).(cron.TaskTable)
tasks = util.PaginateSlice(tasks, listOpts.Page, listOpts.PageSize)
res := make([]structs.Cron, len(tasks))
for i, task := range tasks {
+2 -2
View File
@@ -137,7 +137,7 @@ func CreateHook(ctx *context.APIContext) {
// "201":
// "$ref": "#/responses/Hook"
form := web.GetForm(ctx).(*api.CreateHookOption)
form := web.GetForm[*api.CreateHookOption](ctx)
utils.AddSystemHook(ctx, form)
}
@@ -166,7 +166,7 @@ func EditHook(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/Hook"
form := web.GetForm(ctx).(*api.EditHookOption)
form := web.GetForm[*api.EditHookOption](ctx)
// TODO in body params
hookID := ctx.PathParamInt64("id")
+1 -1
View File
@@ -44,7 +44,7 @@ func CreateOrg(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateOrgOption)
form := web.GetForm[*api.CreateOrgOption](ctx)
visibility := api.VisibleTypePublic
if form.Visibility != "" {
+1 -1
View File
@@ -43,7 +43,7 @@ func CreateRepo(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateRepoOption)
form := web.GetForm[*api.CreateRepoOption](ctx)
repo.CreateUserRepo(ctx, ctx.ContextUser, *form)
}
+4 -4
View File
@@ -75,7 +75,7 @@ func CreateUser(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateUserOption)
form := web.GetForm[*api.CreateUserOption](ctx)
u := &user_model.User{
Name: form.Username,
@@ -190,7 +190,7 @@ func EditUser(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditUserOption)
form := web.GetForm[*api.EditUserOption](ctx)
authOpts := &user_service.UpdateAuthOptions{
LoginSource: optional.FromNonDefault(form.SourceID),
@@ -340,7 +340,7 @@ func CreatePublicKey(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateKeyOption)
form := web.GetForm[*api.CreateKeyOption](ctx)
user.CreateUserPublicKey(ctx, *form, ctx.ContextUser.ID)
}
@@ -551,7 +551,7 @@ func RenameUser(ctx *context.APIContext) {
return
}
newName := web.GetForm(ctx).(*api.RenameUserOption).NewName
newName := web.GetForm[*api.RenameUserOption](ctx).NewName
// Check if username has been changed
if err := user_service.RenameUser(ctx, ctx.ContextUser, newName, ctx.Doer); err != nil {
+2 -2
View File
@@ -66,7 +66,7 @@ func AddUserBadges(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
form := web.GetForm(ctx).(*api.UserBadgeOption)
form := web.GetForm[*api.UserBadgeOption](ctx)
badges := prepareBadgesForReplaceOrAdd(*form)
if err := user_model.AddUserBadges(ctx, ctx.ContextUser, badges); err != nil {
@@ -102,7 +102,7 @@ func DeleteUserBadges(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.UserBadgeOption)
form := web.GetForm[*api.UserBadgeOption](ctx)
badges := prepareBadgesForReplaceOrAdd(*form)
if err := user_model.RemoveUserBadges(ctx, ctx.ContextUser, badges); err != nil {
+1 -1
View File
@@ -396,7 +396,7 @@ func reqUsersExploreEnabled() func(ctx *context.APIContext) {
func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
if ctx.IsSigned && setting.Service.EnableReverseProxyAuthAPI && ctx.Data["AuthedMethod"].(string) == auth.ReverseProxyMethodName {
if ctx.IsSigned && setting.Service.EnableReverseProxyAuthAPI && ctx.Data["AuthedMethod"] == auth.ReverseProxyMethodName {
return
}
if !ctx.IsBasicAuth {
+2 -2
View File
@@ -33,7 +33,7 @@ func Markup(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.MarkupOption)
form := web.GetForm[*api.MarkupOption](ctx)
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, form.FilePath)
}
@@ -58,7 +58,7 @@ func Markdown(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.MarkdownOption)
form := web.GetForm[*api.MarkdownOption](ctx)
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, "")
}
+3 -3
View File
@@ -106,7 +106,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
opt := web.GetForm[*api.CreateOrUpdateSecretOption](ctx)
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Org.Organization.ID, 0, ctx.PathParam("secretname"), opt.Data, opt.Description)
if err != nil {
@@ -373,7 +373,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// "500":
// "$ref": "#/responses/error"
opt := web.GetForm(ctx).(*api.CreateVariableOption)
opt := web.GetForm[*api.CreateVariableOption](ctx)
ownerID := ctx.Org.Organization.ID
variableName := ctx.PathParam("variablename")
@@ -437,7 +437,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
opt := web.GetForm(ctx).(*api.UpdateVariableOption)
opt := web.GetForm[*api.UpdateVariableOption](ctx)
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
OwnerID: ctx.Org.Organization.ID,
+1 -1
View File
@@ -35,7 +35,7 @@ func UpdateAvatar(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.UpdateUserAvatarOption)
form := web.GetForm[*api.UpdateUserAvatarOption](ctx)
content, err := base64.StdEncoding.DecodeString(form.Image)
if err != nil {
+2 -2
View File
@@ -113,7 +113,7 @@ func CreateHook(ctx *context.APIContext) {
utils.AddOwnerHook(
ctx,
ctx.ContextUser,
web.GetForm(ctx).(*api.CreateHookOption),
web.GetForm[*api.CreateHookOption](ctx),
)
}
@@ -151,7 +151,7 @@ func EditHook(ctx *context.APIContext) {
utils.EditOwnerHook(
ctx,
ctx.ContextUser,
web.GetForm(ctx).(*api.EditHookOption),
web.GetForm[*api.EditHookOption](ctx),
ctx.PathParamInt64("id"),
)
}
+2 -2
View File
@@ -86,7 +86,7 @@ func CreateLabel(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateLabelOption)
form := web.GetForm[*api.CreateLabelOption](ctx)
form.Color = strings.Trim(form.Color, " ")
color, err := label.NormalizeColor(form.Color)
if err != nil {
@@ -189,7 +189,7 @@ func EditLabel(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditLabelOption)
form := web.GetForm[*api.EditLabelOption](ctx)
l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, ctx.PathParamInt64("id"))
if err != nil {
if issues_model.IsErrOrgLabelNotExist(err) {
+3 -3
View File
@@ -261,7 +261,7 @@ func Create(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateOrgOption)
form := web.GetForm[*api.CreateOrgOption](ctx)
if !ctx.Doer.CanCreateOrganization() {
ctx.APIError(http.StatusForbidden, "not allowed to create org")
return
@@ -358,7 +358,7 @@ func Rename(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.RenameOrgOption)
form := web.GetForm[*api.RenameOrgOption](ctx)
orgUser := ctx.Org.Organization.AsUser()
if err := user_service.RenameUser(ctx, orgUser, form.NewName, ctx.Doer); err != nil {
if user_model.IsErrUserAlreadyExist(err) || db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) || db.IsErrNameCharsNotAllowed(err) {
@@ -397,7 +397,7 @@ func Edit(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditOrgOption)
form := web.GetForm[*api.EditOrgOption](ctx)
if err := org.UpdateOrgEmailAddress(ctx, ctx.Org.Organization, form.Email); err != nil {
if errors.Is(err, util.ErrInvalidArgument) {
+2 -2
View File
@@ -214,7 +214,7 @@ func CreateTeam(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateTeamOption)
form := web.GetForm[*api.CreateTeamOption](ctx)
teamPermission := perm.ParseAccessMode(string(form.Permission), perm.AccessModeNone, perm.AccessModeAdmin)
team := &organization.Team{
OrgID: ctx.Org.Organization.ID,
@@ -282,7 +282,7 @@ func EditTeam(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditTeamOption)
form := web.GetForm[*api.EditTeamOption](ctx)
team := ctx.Org.Team
if err := team.LoadUnits(ctx); err != nil {
ctx.APIErrorInternal(err)
+4 -4
View File
@@ -135,7 +135,7 @@ func (Action) CreateOrUpdateSecret(ctx *context.APIContext) {
repo := ctx.Repo.Repository
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
opt := web.GetForm[*api.CreateOrUpdateSecretOption](ctx)
_, created, err := secret_service.CreateOrUpdateSecret(ctx, 0, repo.ID, ctx.PathParam("secretname"), opt.Data, opt.Description)
if err != nil {
@@ -346,7 +346,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// "500":
// "$ref": "#/responses/error"
opt := web.GetForm(ctx).(*api.CreateVariableOption)
opt := web.GetForm[*api.CreateVariableOption](ctx)
repoID := ctx.Repo.Repository.ID
variableName := ctx.PathParam("variablename")
@@ -413,7 +413,7 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
opt := web.GetForm(ctx).(*api.UpdateVariableOption)
opt := web.GetForm[*api.UpdateVariableOption](ctx)
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
RepoID: ctx.Repo.Repository.ID,
@@ -1170,7 +1170,7 @@ func ActionsDispatchWorkflow(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
workflowID := ctx.PathParam("workflow_id")
opt := web.GetForm(ctx).(*api.CreateActionWorkflowDispatch)
opt := web.GetForm[*api.CreateActionWorkflowDispatch](ctx)
if opt.Ref == "" {
ctx.APIError(http.StatusUnprocessableEntity, "ref is required parameter")
return
+1 -1
View File
@@ -40,7 +40,7 @@ func UpdateAvatar(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.UpdateRepoAvatarOption)
form := web.GetForm[*api.UpdateRepoAvatarOption](ctx)
content, err := base64.StdEncoding.DecodeString(form.Image)
if err != nil {
+10 -10
View File
@@ -212,7 +212,7 @@ func CreateBranch(ctx *context.APIContext) {
return
}
opt := web.GetForm(ctx).(*api.CreateBranchRepoOption)
opt := web.GetForm[*api.CreateBranchRepoOption](ctx)
var oldCommit *git.Commit
var err error
@@ -426,7 +426,7 @@ func UpdateBranch(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opt := web.GetForm(ctx).(*api.UpdateBranchRepoOption)
opt := web.GetForm[*api.UpdateBranchRepoOption](ctx)
branchName := ctx.PathParam("*")
repo := ctx.Repo.Repository
@@ -443,14 +443,14 @@ func UpdateBranch(ctx *context.APIContext) {
// permission check has been done in api.go
if err := repo_service.UpdateBranch(ctx, repo, ctx.Repo.GitRepo, ctx.Doer, branchName, opt.NewCommitID, opt.OldCommitID, opt.Force); err != nil {
var errPushRejected *git.ErrPushRejected
switch {
case git_model.IsErrBranchNotExist(err):
ctx.APIErrorNotFound()
case errors.Is(err, util.ErrInvalidArgument):
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
case git.IsErrPushRejected(err):
rej := err.(*git.ErrPushRejected)
ctx.APIError(http.StatusForbidden, rej.Message)
case errors.As(err, &errPushRejected):
ctx.APIError(http.StatusForbidden, errPushRejected.Message)
default:
ctx.APIErrorInternal(err)
}
@@ -499,7 +499,7 @@ func RenameBranch(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opt := web.GetForm(ctx).(*api.RenameBranchRepoOption)
opt := web.GetForm[*api.RenameBranchRepoOption](ctx)
oldName := ctx.PathParam("*")
repo := ctx.Repo.Repository
@@ -654,7 +654,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateBranchProtectionOption)
form := web.GetForm[*api.CreateBranchProtectionOption](ctx)
repo := ctx.Repo.Repository
ruleName := form.RuleName
@@ -875,7 +875,7 @@ func EditBranchProtection(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
form := web.GetForm[*api.EditBranchProtectionOption](ctx)
repo := ctx.Repo.Repository
bpName := ctx.PathParam("*")
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, bpName)
@@ -1292,7 +1292,7 @@ func UpdateBranchProtectionPriories(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.UpdateBranchProtectionPriories)
form := web.GetForm[*api.UpdateBranchProtectionPriories](ctx)
repo := ctx.Repo.Repository
if err := git_model.UpdateProtectBranchPriorities(ctx, repo, form.IDs); err != nil {
@@ -1331,7 +1331,7 @@ func MergeUpstream(ctx *context.APIContext) {
// "$ref": "#/responses/error"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.MergeUpstreamRequest)
form := web.GetForm[*api.MergeUpstreamRequest](ctx)
mergeStyle, err := repo_service.MergeUpstream(ctx, ctx.Doer, ctx.Repo.Repository, form.Branch, form.FfOnly)
if err != nil {
if errors.Is(err, util.ErrInvalidArgument) {
+1 -1
View File
@@ -162,7 +162,7 @@ func AddOrUpdateCollaborator(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.AddCollaboratorOption)
form := web.GetForm[*api.AddCollaboratorOption](ctx)
collaborator, err := user_model.GetUserByName(ctx, ctx.PathParam("collaborator"))
if err != nil {
+23 -26
View File
@@ -323,14 +323,19 @@ func base64Reader(s string) (io.ReadSeeker, error) {
}
func ReqChangeRepoFileOptionsAndCheck(ctx *context.APIContext) {
commonOpts := web.GetForm(ctx).(api.FileOptionsInterface).GetFileOptions()
commonOpts := web.GetForm[api.FileOptionsInterface](ctx).GetFileOptions()
commonOpts.BranchName = util.IfZero(commonOpts.BranchName, ctx.Repo.Repository.DefaultBranch)
commonOpts.NewBranchName = util.IfZero(commonOpts.NewBranchName, commonOpts.BranchName)
if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, commonOpts.NewBranchName) && !ctx.IsUserSiteAdmin() {
ctx.APIError(http.StatusForbidden, "user should have a permission to write to the target branch")
return
}
changeFileOpts := &files_service.ChangeRepoFilesOptions{
}
// getAPIChangeRepoFileOptions requires ReqChangeRepoFileOptionsAndCheck to have run, it fills in the branch defaults
func getAPIChangeRepoFileOptions[T api.FileOptionsInterface](ctx *context.APIContext) (apiOpts T, opts *files_service.ChangeRepoFilesOptions) {
apiOpts = web.GetForm[T](ctx)
commonOpts := apiOpts.GetFileOptions()
opts = &files_service.ChangeRepoFilesOptions{
Message: commonOpts.Message,
OldBranch: commonOpts.BranchName,
NewBranch: commonOpts.NewBranchName,
@@ -349,17 +354,13 @@ func ReqChangeRepoFileOptionsAndCheck(ctx *context.APIContext) {
},
Signoff: commonOpts.Signoff,
}
if changeFileOpts.Dates.Author.IsZero() {
changeFileOpts.Dates.Author = time.Now()
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if changeFileOpts.Dates.Committer.IsZero() {
changeFileOpts.Dates.Committer = time.Now()
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}
ctx.Data["__APIChangeRepoFilesOptions"] = changeFileOpts
}
func getAPIChangeRepoFileOptions[T api.FileOptionsInterface](ctx *context.APIContext) (apiOpts T, opts *files_service.ChangeRepoFilesOptions) {
return web.GetForm(ctx).(T), ctx.Data["__APIChangeRepoFilesOptions"].(*files_service.ChangeRepoFilesOptions)
return apiOpts, opts
}
// ChangeFiles handles API call for modifying multiple files
@@ -574,9 +575,8 @@ func UpdateFile(ctx *context.APIContext) {
}
func handleChangeRepoFilesError(ctx *context.APIContext, err error) {
if git.IsErrPushRejected(err) {
err := err.(*git.ErrPushRejected)
ctx.APIError(http.StatusForbidden, err.Message)
if errPushRejected, ok := err.(*git.ErrPushRejected); ok {
ctx.APIError(http.StatusForbidden, errPushRejected.Message)
return
}
if files_service.IsErrUserCannotCommit(err) || pull_service.IsErrFilePathProtected(err) {
@@ -896,7 +896,12 @@ func GetFileContentsGet(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
// The POST method requires "write" permission, so we also support this "GET" method
handleGetFileContents(ctx)
opts := &api.GetFilesOptions{}
if err := json.Unmarshal(util.UnsafeStringToBytes(ctx.FormString("body")), opts); err != nil {
ctx.APIError(http.StatusBadRequest, "invalid body parameter")
return
}
handleGetFileContents(ctx, opts)
}
func GetFileContentsPost(ctx *context.APIContext) {
@@ -940,18 +945,10 @@ func GetFileContentsPost(ctx *context.APIContext) {
// This is actually a "read" request, but we need to accept a "files" list, then POST method seems easy to use.
// But the permission system requires that the caller must have "write" permission to use POST method.
// At the moment, there is no other way to get around the permission check, so there is a "GET" workaround method above.
handleGetFileContents(ctx)
handleGetFileContents(ctx, web.GetForm[*api.GetFilesOptions](ctx))
}
func handleGetFileContents(ctx *context.APIContext) {
opts, ok := web.GetForm(ctx).(*api.GetFilesOptions)
if !ok {
err := json.Unmarshal(util.UnsafeStringToBytes(ctx.FormString("body")), &opts)
if err != nil {
ctx.APIError(http.StatusBadRequest, "invalid body parameter")
return
}
}
func handleGetFileContents(ctx *context.APIContext, opts *api.GetFilesOptions) {
refCommit := resolveRefCommit(ctx, ctx.FormTrim("ref"))
if ctx.Written() {
return
+1 -1
View File
@@ -148,7 +148,7 @@ func CreateFork(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateForkOption)
form := web.GetForm[*api.CreateForkOption](ctx)
forkOwner := ctx.Doer // user/org that will own the fork
if form.Organization != nil {
org := prepareDoerCreateRepoInOrg(ctx, *form.Organization)
+1 -1
View File
@@ -126,7 +126,7 @@ func EditGitHook(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditGitHookOption)
form := web.GetForm[*api.EditGitHookOption](ctx)
hookID := ctx.PathParam("id")
hook, err := git.GetHook(ctx.Repo.GitRepo, hookID)
if err != nil {
+2 -2
View File
@@ -226,7 +226,7 @@ func CreateHook(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
utils.AddRepoHook(ctx, web.GetForm(ctx).(*api.CreateHookOption))
utils.AddRepoHook(ctx, web.GetForm[*api.CreateHookOption](ctx))
}
// EditHook modify a hook of a repository
@@ -262,7 +262,7 @@ func EditHook(ctx *context.APIContext) {
// "$ref": "#/responses/Hook"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditHookOption)
form := web.GetForm[*api.EditHookOption](ctx)
hookID := ctx.PathParamInt64("id")
utils.EditRepoHook(ctx, form, hookID)
}
+3 -3
View File
@@ -631,7 +631,7 @@ func CreateIssue(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateIssueOption)
form := web.GetForm[*api.CreateIssueOption](ctx)
var deadlineUnix timeutil.TimeStamp
if form.Deadline != nil && ctx.Repo.Permission.CanWrite(unit.TypeIssues) {
deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
@@ -759,7 +759,7 @@ func EditIssue(ctx *context.APIContext) {
// "412":
// "$ref": "#/responses/error"
form := web.GetForm(ctx).(*api.EditIssueOption)
form := web.GetForm[*api.EditIssueOption](ctx)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
if issues_model.IsErrIssueNotExist(err) {
@@ -1012,7 +1012,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditDeadlineOption)
form := web.GetForm[*api.EditDeadlineOption](ctx)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
if issues_model.IsErrIssueNotExist(err) {
+2 -2
View File
@@ -60,7 +60,7 @@ func AddIssueAssignees(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.IssueAssigneesOption)
opts := web.GetForm[*api.IssueAssigneesOption](ctx)
updateIssueAssignees(ctx, *opts, true)
}
@@ -105,7 +105,7 @@ func DeleteIssueAssignees(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.IssueAssigneesOption)
opts := web.GetForm[*api.IssueAssigneesOption](ctx)
updateIssueAssignees(ctx, *opts, false)
}
+1 -1
View File
@@ -265,7 +265,7 @@ func EditIssueAttachment(ctx *context.APIContext) {
}
// do changes to attachment. only meaningful change is name.
form := web.GetForm(ctx).(*api.EditAttachmentOptions)
form := web.GetForm[*api.EditAttachmentOptions](ctx)
if form.Name != "" {
attachment.Name = form.Name
}
+3 -3
View File
@@ -379,7 +379,7 @@ func CreateIssueComment(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
form := web.GetForm[*api.CreateIssueCommentOption](ctx)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
ctx.APIErrorInternal(err)
@@ -511,7 +511,7 @@ func EditIssueComment(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.EditIssueCommentOption)
form := web.GetForm[*api.EditIssueCommentOption](ctx)
editIssueComment(ctx, *form)
}
@@ -561,7 +561,7 @@ func EditIssueCommentDeprecated(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditIssueCommentOption)
form := web.GetForm[*api.EditIssueCommentOption](ctx)
editIssueComment(ctx, *form)
}
@@ -278,7 +278,7 @@ func EditIssueCommentAttachment(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.EditAttachmentOptions)
form := web.GetForm[*api.EditAttachmentOptions](ctx)
if form.Name != "" {
attach.Name = form.Name
}
+4 -4
View File
@@ -183,7 +183,7 @@ func CreateIssueDependency(ctx *context.APIContext) {
}
// and <Form> represents the dependency
form := web.GetForm(ctx).(*api.IssueMeta)
form := web.GetForm[*api.IssueMeta](ctx)
dependency := getFormIssue(ctx, form)
if ctx.Written() {
return
@@ -244,7 +244,7 @@ func RemoveIssueDependency(ctx *context.APIContext) {
}
// and <Form> represents the dependency
form := web.GetForm(ctx).(*api.IssueMeta)
form := web.GetForm[*api.IssueMeta](ctx)
dependency := getFormIssue(ctx, form)
if ctx.Written() {
return
@@ -404,7 +404,7 @@ func CreateIssueBlocking(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.IssueMeta)
form := web.GetForm[*api.IssueMeta](ctx)
target := getFormIssue(ctx, form)
if ctx.Written() {
return
@@ -461,7 +461,7 @@ func RemoveIssueBlocking(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.IssueMeta)
form := web.GetForm[*api.IssueMeta](ctx)
target := getFormIssue(ctx, form)
if ctx.Written() {
return
+2 -2
View File
@@ -103,7 +103,7 @@ func AddIssueLabels(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.IssueLabelsOption)
form := web.GetForm[*api.IssueLabelsOption](ctx)
issue, labels, err := prepareForReplaceOrAdd(ctx, *form)
if err != nil {
return
@@ -232,7 +232,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.IssueLabelsOption)
form := web.GetForm[*api.IssueLabelsOption](ctx)
issue, labels, err := prepareForReplaceOrAdd(ctx, *form)
if err != nil {
return
+1 -1
View File
@@ -50,7 +50,7 @@ func LockIssue(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
reason := web.GetForm(ctx).(*api.LockIssueOption).Reason
reason := web.GetForm[*api.LockIssueOption](ctx).Reason
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
ctx.APIErrorAuto(err)
+4 -4
View File
@@ -135,7 +135,7 @@ func PostIssueCommentReaction(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditReactionOption)
form := web.GetForm[*api.EditReactionOption](ctx)
changeIssueCommentReaction(ctx, *form, true)
}
@@ -178,7 +178,7 @@ func DeleteIssueCommentReaction(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditReactionOption)
form := web.GetForm[*api.EditReactionOption](ctx)
changeIssueCommentReaction(ctx, *form, false)
}
@@ -364,7 +364,7 @@ func PostIssueReaction(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditReactionOption)
form := web.GetForm[*api.EditReactionOption](ctx)
changeIssueReaction(ctx, *form, true)
}
@@ -405,7 +405,7 @@ func DeleteIssueReaction(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditReactionOption)
form := web.GetForm[*api.EditReactionOption](ctx)
changeIssueReaction(ctx, *form, false)
}
+1 -1
View File
@@ -199,7 +199,7 @@ func AddTime(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.AddTimeOption)
form := web.GetForm[*api.AddTimeOption](ctx)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
ctx.APIErrorAuto(err)
+1 -1
View File
@@ -231,7 +231,7 @@ func CreateDeployKey(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateKeyOption)
form := web.GetForm[*api.CreateKeyOption](ctx)
content, err := asymkey_model.CheckPublicKeyString(form.Key)
if err != nil {
HandleCheckKeyStringError(ctx, err)
+2 -2
View File
@@ -145,7 +145,7 @@ func CreateLabel(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateLabelOption)
form := web.GetForm[*api.CreateLabelOption](ctx)
color, err := label.NormalizeColor(form.Color)
if err != nil {
@@ -207,7 +207,7 @@ func EditLabel(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditLabelOption)
form := web.GetForm[*api.EditLabelOption](ctx)
l, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
if err != nil {
ctx.APIErrorAuto(err)
+13 -9
View File
@@ -56,7 +56,7 @@ func Migrate(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.MigrateRepoOptions)
form := web.GetForm[*api.MigrateRepoOptions](ctx)
// get repoOwner
var (
@@ -217,6 +217,11 @@ func Migrate(ctx *context.APIContext) {
}
func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err error) {
var (
errNameReserved db.ErrNameReserved
errNameCharsNotAllowed db.ErrNameCharsNotAllowed
errNamePatternNotAllowed db.ErrNamePatternNotAllowed
)
switch {
case repo_model.IsErrRepoAlreadyExist(err):
ctx.APIError(http.StatusConflict, "The repository with the same name already exists.")
@@ -228,12 +233,12 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err
ctx.APIError(http.StatusUnprocessableEntity, "Remote visit required two factors authentication.")
case repo_model.IsErrReachLimitOfRepo(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit()))
case db.IsErrNameReserved(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name))
case db.IsErrNameCharsNotAllowed(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' contains invalid characters.", err.(db.ErrNameCharsNotAllowed).Name))
case db.IsErrNamePatternNotAllowed(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(db.ErrNamePatternNotAllowed).Pattern))
case errors.As(err, &errNameReserved):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' is reserved.", errNameReserved.Name))
case errors.As(err, &errNameCharsNotAllowed):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' contains invalid characters.", errNameCharsNotAllowed.Name))
case errors.As(err, &errNamePatternNotAllowed):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The pattern '%s' is not allowed in a username.", errNamePatternNotAllowed.Pattern))
case git.IsErrInvalidCloneAddr(err):
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
case base.IsErrNotSupported(err):
@@ -253,8 +258,7 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err
}
func handleRemoteAddrError(ctx *context.APIContext, err error) {
if git.IsErrInvalidCloneAddr(err) {
addrErr := err.(*git.ErrInvalidCloneAddr)
if addrErr, ok := err.(*git.ErrInvalidCloneAddr); ok {
switch {
case addrErr.IsURLError:
ctx.APIError(http.StatusUnprocessableEntity, "The provided URL is invalid.")
+2 -2
View File
@@ -147,7 +147,7 @@ func CreateMilestone(ctx *context.APIContext) {
// "$ref": "#/responses/Milestone"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.CreateMilestoneOption)
form := web.GetForm[*api.CreateMilestoneOption](ctx)
var deadlineUnix int64
if form.Deadline != nil {
@@ -207,7 +207,7 @@ func EditMilestone(ctx *context.APIContext) {
// "$ref": "#/responses/Milestone"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditMilestoneOption)
form := web.GetForm[*api.EditMilestoneOption](ctx)
milestone := getMilestoneByIDOrName(ctx)
if ctx.Written() {
return
+2 -3
View File
@@ -291,7 +291,7 @@ func AddPushMirror(ctx *context.APIContext) {
return
}
pushMirror := web.GetForm(ctx).(*api.CreatePushMirrorOption)
pushMirror := web.GetForm[*api.CreatePushMirrorOption](ctx)
CreatePushMirror(ctx, pushMirror)
}
@@ -403,8 +403,7 @@ func CreatePushMirror(ctx *context.APIContext, mirrorOption *api.CreatePushMirro
}
func HandleRemoteAddressError(ctx *context.APIContext, err error) {
if git.IsErrInvalidCloneAddr(err) {
addrErr := err.(*git.ErrInvalidCloneAddr)
if addrErr, ok := err.(*git.ErrInvalidCloneAddr); ok {
switch {
case addrErr.IsProtocolInvalid:
ctx.APIError(http.StatusBadRequest, "Invalid mirror protocol")
+7 -11
View File
@@ -404,7 +404,7 @@ func CreatePullRequest(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := *web.GetForm(ctx).(*api.CreatePullRequestOption)
form := *web.GetForm[*api.CreatePullRequestOption](ctx)
if form.Head == form.Base {
ctx.APIError(http.StatusUnprocessableEntity, "Invalid PullRequest: There are no changes between the head and the base")
return
@@ -628,7 +628,7 @@ func EditPullRequest(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditPullRequestOption)
form := web.GetForm[*api.EditPullRequestOption](ctx)
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
if issues_model.IsErrPullRequestNotExist(err) {
@@ -922,7 +922,7 @@ func MergePullRequest(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*forms.MergePullRequestForm)
form := web.GetForm[*forms.MergePullRequestForm](ctx)
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
@@ -1044,21 +1044,17 @@ func MergePullRequest(ctx *context.APIContext) {
if err := pull_service.Merge(ctx, pr, ctx.Doer, repo_model.MergeStyle(form.Do), form.HeadCommitID, message, false); err != nil {
if pull_service.IsErrInvalidMergeStyle(err) {
ctx.APIError(http.StatusMethodNotAllowed, fmt.Sprintf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
} else if pull_service.IsErrMergeConflicts(err) {
conflictError := err.(pull_service.ErrMergeConflicts)
} else if conflictError, ok := err.(pull_service.ErrMergeConflicts); ok {
ctx.JSON(http.StatusConflict, conflictError)
} else if pull_service.IsErrRebaseConflicts(err) {
conflictError := err.(pull_service.ErrRebaseConflicts)
} else if conflictError, ok := err.(pull_service.ErrRebaseConflicts); ok {
ctx.JSON(http.StatusConflict, conflictError)
} else if pull_service.IsErrMergeUnrelatedHistories(err) {
conflictError := err.(pull_service.ErrMergeUnrelatedHistories)
} else if conflictError, ok := err.(pull_service.ErrMergeUnrelatedHistories); ok {
ctx.JSON(http.StatusConflict, conflictError)
} else if git.IsErrPushOutOfDate(err) {
ctx.APIError(http.StatusConflict, "merge push out of date")
} else if pull_service.IsErrSHADoesNotMatch(err) {
ctx.APIError(http.StatusConflict, "head out of date")
} else if git.IsErrPushRejected(err) {
errPushRej := err.(*git.ErrPushRejected)
} else if errPushRej, ok := err.(*git.ErrPushRejected); ok {
if len(errPushRej.Message) == 0 {
ctx.APIError(http.StatusConflict, "PushRejected without remote error message")
} else {
+6 -6
View File
@@ -252,7 +252,7 @@ func CreatePullReviewCommentReply(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.CreatePullReviewCommentReplyOptions)
opts := web.GetForm[*api.CreatePullReviewCommentReplyOptions](ctx)
parent := getPullReviewCommentToResolve(ctx)
if parent == nil {
@@ -499,7 +499,7 @@ func CreatePullReview(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.CreatePullReviewOptions)
opts := web.GetForm[*api.CreatePullReviewOptions](ctx)
pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
if err != nil {
ctx.APIErrorAuto(err)
@@ -622,7 +622,7 @@ func SubmitPullReview(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.SubmitPullReviewOptions)
opts := web.GetForm[*api.SubmitPullReviewOptions](ctx)
review, pr, isWrong := prepareSingleReview(ctx)
if isWrong {
return
@@ -792,7 +792,7 @@ func CreateReviewRequests(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
opts := web.GetForm(ctx).(*api.PullReviewRequestOptions)
opts := web.GetForm[*api.PullReviewRequestOptions](ctx)
apiReviewRequest(ctx, *opts, true)
}
@@ -834,7 +834,7 @@ func DeleteReviewRequests(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
opts := web.GetForm(ctx).(*api.PullReviewRequestOptions)
opts := web.GetForm[*api.PullReviewRequestOptions](ctx)
apiReviewRequest(ctx, *opts, false)
}
@@ -1014,7 +1014,7 @@ func DismissPullReview(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
// "422":
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.DismissPullReviewOptions)
opts := web.GetForm[*api.DismissPullReviewOptions](ctx)
dismissReview(ctx, opts.Message, true, opts.Priors)
}
+3 -3
View File
@@ -28,7 +28,7 @@ func canAccessReleaseDraft(ctx *context.APIContext) bool {
return true
}
// the request is from an access token with scope
scope := ctx.Data["ApiTokenScope"].(auth_model.AccessTokenScope)
scope := ctx.Data["ApiTokenScope"].(auth_model.AccessTokenScope) //nolint:forcetypeassert // must exist
requiredScopes := auth_model.GetRequiredScopes(auth_model.Write, auth_model.AccessTokenScopeCategoryRepository)
allow, _ := scope.HasScope(requiredScopes...) // err (invalid token) can be safely ignored
return allow
@@ -244,7 +244,7 @@ func CreateRelease(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateReleaseOption)
form := web.GetForm[*api.CreateReleaseOption](ctx)
if ctx.Repo.Repository.IsEmpty {
ctx.APIError(http.StatusUnprocessableEntity, "repo is empty")
return
@@ -346,7 +346,7 @@ func EditRelease(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditReleaseOption)
form := web.GetForm[*api.EditReleaseOption](ctx)
id := ctx.PathParamInt64("id")
rel, err := repo_model.GetReleaseForRepoByID(ctx, ctx.Repo.Repository.ID, id)
if err != nil && !repo_model.IsErrReleaseNotExist(err) {
+1 -1
View File
@@ -310,7 +310,7 @@ func EditReleaseAttachment(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditAttachmentOptions)
form := web.GetForm[*api.EditAttachmentOptions](ctx)
// Check if release exists an load release
releaseID := ctx.PathParamInt64("id")
+4 -4
View File
@@ -298,7 +298,7 @@ func Create(ctx *context.APIContext) {
// description: The repository with the same name already exists.
// "422":
// "$ref": "#/responses/validationError"
opt := web.GetForm(ctx).(*api.CreateRepoOption)
opt := web.GetForm[*api.CreateRepoOption](ctx)
if ctx.Doer.IsOrganization() {
// Shouldn't reach this condition, but just in case.
ctx.APIError(http.StatusUnprocessableEntity, "not allowed creating repository for organization")
@@ -342,7 +342,7 @@ func Generate(ctx *context.APIContext) {
// description: The repository with the same name already exists.
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.GenerateRepoOption)
form := web.GetForm[*api.GenerateRepoOption](ctx)
if !ctx.Repo.Repository.IsTemplate {
ctx.APIError(http.StatusUnprocessableEntity, "this is not a template repo")
@@ -484,7 +484,7 @@ func CreateOrgRepo(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
// "403":
// "$ref": "#/responses/forbidden"
opt := web.GetForm(ctx).(*api.CreateRepoOption)
opt := web.GetForm[*api.CreateRepoOption](ctx)
orgName := ctx.PathParam("org")
org := prepareDoerCreateRepoInOrg(ctx, orgName)
if ctx.Written() {
@@ -603,7 +603,7 @@ func Edit(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opts := *web.GetForm(ctx).(*api.EditRepoOption)
opts := *web.GetForm[*api.EditRepoOption](ctx)
if err := updateBasicProperties(ctx, opts); err != nil {
return
+1 -1
View File
@@ -52,7 +52,7 @@ func NewCommitStatus(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.CreateStatusOption)
form := web.GetForm[*api.CreateStatusOption](ctx)
sha := ctx.PathParam("sha")
if len(sha) == 0 {
ctx.APIError(http.StatusBadRequest, "sha not provided")
+3 -3
View File
@@ -194,7 +194,7 @@ func CreateTag(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateTagOption)
form := web.GetForm[*api.CreateTagOption](ctx)
// If target is not provided use default branch
if len(form.Target) == 0 {
@@ -411,7 +411,7 @@ func CreateTagProtection(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateTagProtectionOption)
form := web.GetForm[*api.CreateTagProtectionOption](ctx)
repo := ctx.Repo.Repository
namePattern := strings.TrimSpace(form.NamePattern)
@@ -522,7 +522,7 @@ func EditTagProtection(ctx *context.APIContext) {
// "$ref": "#/responses/repoArchivedError"
repo := ctx.Repo.Repository
form := web.GetForm(ctx).(*api.EditTagProtectionOption)
form := web.GetForm[*api.EditTagProtectionOption](ctx)
id := ctx.PathParamInt64("id")
pt, err := git_model.GetProtectedTagByID(ctx, id)
+1 -1
View File
@@ -101,7 +101,7 @@ func UpdateTopics(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/invalidTopicsError"
form := web.GetForm(ctx).(*api.RepoTopicOptions)
form := web.GetForm[*api.RepoTopicOptions](ctx)
topicNames := form.Topics
validTopics, invalidTopics := repo_model.SanitizeAndValidateTopics(topicNames)
+1 -1
View File
@@ -56,7 +56,7 @@ func Transfer(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.TransferRepoOption)
opts := web.GetForm[*api.TransferRepoOption](ctx)
newOwner, err := user_model.GetUserByName(ctx, opts.NewOwner)
if err != nil {
+2 -2
View File
@@ -55,7 +55,7 @@ func NewWikiPage(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
form := web.GetForm[*api.CreateWikiPageOptions](ctx)
if util.IsEmptyString(form.Title) {
ctx.APIError(http.StatusBadRequest, "title is required")
@@ -133,7 +133,7 @@ func EditWikiPage(ctx *context.APIContext) {
// "423":
// "$ref": "#/responses/repoArchivedError"
form := web.GetForm(ctx).(*api.CreateWikiPageOptions)
form := web.GetForm[*api.CreateWikiPageOptions](ctx)
oldWikiName := wiki_service.WebPathFromRequest(ctx.PathParamRaw("pageName"))
newWikiName := wiki_service.UserTitleToWebPath("", form.Title)
+6 -6
View File
@@ -478,7 +478,7 @@ func CreateProject(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
scope := projectScopeFromContext(ctx)
form := web.GetForm(ctx).(*api.CreateProjectOption)
form := web.GetForm[*api.CreateProjectOption](ctx)
templateType, err := convert.ProjectTemplateTypeFromString(form.TemplateType)
if err != nil {
@@ -611,7 +611,7 @@ func EditProject(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.EditProjectOption)
form := web.GetForm[*api.EditProjectOption](ctx)
if form.Title != nil && util.IsEmptyString(*form.Title) {
ctx.APIError(http.StatusUnprocessableEntity, "title must not be empty")
return
@@ -951,7 +951,7 @@ func CreateProjectColumn(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.CreateProjectColumnOption)
form := web.GetForm[*api.CreateProjectColumnOption](ctx)
column := &project_model.Column{
Title: form.Title,
Color: form.Color,
@@ -1185,7 +1185,7 @@ func EditProjectColumn(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.EditProjectColumnOption)
form := web.GetForm[*api.EditProjectColumnOption](ctx)
if form.Title != nil {
if util.IsEmptyString(*form.Title) {
ctx.APIError(http.StatusUnprocessableEntity, "title must not be empty")
@@ -1529,7 +1529,7 @@ func MoveProjectColumns(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.MoveProjectColumnsOption)
form := web.GetForm[*api.MoveProjectColumnsOption](ctx)
columns, err := project_model.GetColumns(ctx, project.ID, db.ListOptionsAll)
if err != nil {
ctx.APIErrorInternal(err)
@@ -2097,7 +2097,7 @@ func MoveProjectIssue(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.MoveProjectIssueOption)
form := web.GetForm[*api.MoveProjectIssueOption](ctx)
column, err := project_model.GetColumnByIDAndProjectID(ctx, form.ColumnID, project.ID)
if err != nil {
if project_model.IsErrProjectColumnNotExist(err) {
+1 -1
View File
@@ -131,7 +131,7 @@ func UpdateRunner(ctx *context.APIContext, ownerID, repoID, runnerID int64) {
return
}
form := web.GetForm(ctx).(*api.EditActionRunnerOption)
form := web.GetForm[*api.EditActionRunnerOption](ctx)
if form.Disabled == nil {
ctx.APIError(http.StatusUnprocessableEntity, "[Disabled]: Required")
return
+3 -3
View File
@@ -48,7 +48,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption)
opt := web.GetForm[*api.CreateOrUpdateSecretOption](ctx)
_, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Doer.ID, 0, ctx.PathParam("secretname"), opt.Data, opt.Description)
if err != nil {
@@ -134,7 +134,7 @@ func CreateVariable(ctx *context.APIContext) {
// "409":
// description: variable name already exists.
opt := web.GetForm(ctx).(*api.CreateVariableOption)
opt := web.GetForm[*api.CreateVariableOption](ctx)
ownerID := ctx.Doer.ID
variableName := ctx.PathParam("variablename")
@@ -193,7 +193,7 @@ func UpdateVariable(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
opt := web.GetForm(ctx).(*api.UpdateVariableOption)
opt := web.GetForm[*api.UpdateVariableOption](ctx)
v, err := actions_service.GetVariable(ctx, actions_model.FindVariablesOpts{
OwnerID: ctx.Doer.ID,
+3 -3
View File
@@ -98,7 +98,7 @@ func CreateAccessToken(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
form := web.GetForm(ctx).(*api.CreateAccessTokenOption)
form := web.GetForm[*api.CreateAccessTokenOption](ctx)
t := &auth_model.AccessToken{
UID: ctx.ContextUser.ID,
@@ -242,7 +242,7 @@ func CreateOauth2Application(ctx *context.APIContext) {
// "400":
// "$ref": "#/responses/error"
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
data := web.GetForm[*api.CreateOAuth2ApplicationOptions](ctx)
if invalidURI := forms.DetectInvalidOAuth2ApplicationRedirectURI(data.RedirectURIs); invalidURI != "" {
ctx.APIError(http.StatusBadRequest, "invalid redirect URI: "+invalidURI)
return
@@ -406,7 +406,7 @@ func UpdateOauth2Application(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
appID := ctx.PathParamInt64("id")
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
data := web.GetForm[*api.CreateOAuth2ApplicationOptions](ctx)
if invalidURI := forms.DetectInvalidOAuth2ApplicationRedirectURI(data.RedirectURIs); invalidURI != "" {
ctx.APIError(http.StatusBadRequest, "invalid redirect URI: "+invalidURI)
return
+1 -1
View File
@@ -28,7 +28,7 @@ func UpdateAvatar(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
form := web.GetForm(ctx).(*api.UpdateUserAvatarOption)
form := web.GetForm[*api.UpdateUserAvatarOption](ctx)
content, err := base64.StdEncoding.DecodeString(form.Image)
if err != nil {
+4 -4
View File
@@ -63,15 +63,15 @@ func AddEmail(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.CreateEmailOption)
form := web.GetForm[*api.CreateEmailOption](ctx)
if len(form.Emails) == 0 {
ctx.APIError(http.StatusUnprocessableEntity, "Email list empty")
return
}
if err := user_service.AddEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
if user_model.IsErrEmailAlreadyUsed(err) {
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
if errEmailAlreadyUsed, ok := err.(user_model.ErrEmailAlreadyUsed); ok {
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+errEmailAlreadyUsed.Email)
} else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
email := ""
if typedError, ok := err.(user_model.ErrEmailInvalid); ok {
@@ -125,7 +125,7 @@ func DeleteEmail(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.DeleteEmailOption)
form := web.GetForm[*api.DeleteEmailOption](ctx)
if len(form.Emails) == 0 {
ctx.Status(http.StatusNoContent)
return
+2 -2
View File
@@ -187,7 +187,7 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.VerifyGPGKeyOption)
form := web.GetForm[*api.VerifyGPGKeyOption](ctx)
token := asymkey_model.VerificationToken(ctx.Doer, 1)
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)
@@ -248,7 +248,7 @@ func CreateGPGKey(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateGPGKeyOption)
form := web.GetForm[*api.CreateGPGKeyOption](ctx)
CreateUserGPGKey(ctx, *form, ctx.Doer.ID)
}
+2 -2
View File
@@ -97,7 +97,7 @@ func CreateHook(ctx *context.APIContext) {
utils.AddOwnerHook(
ctx,
ctx.Doer,
web.GetForm(ctx).(*api.CreateHookOption),
web.GetForm[*api.CreateHookOption](ctx),
)
}
@@ -128,7 +128,7 @@ func EditHook(ctx *context.APIContext) {
utils.EditOwnerHook(
ctx,
ctx.Doer,
web.GetForm(ctx).(*api.EditHookOption),
web.GetForm[*api.EditHookOption](ctx),
ctx.PathParamInt64("id"),
)
}
+1 -1
View File
@@ -243,7 +243,7 @@ func CreatePublicKey(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateKeyOption)
form := web.GetForm[*api.CreateKeyOption](ctx)
CreateUserPublicKey(ctx, *form, ctx.Doer.ID)
}
+1 -1
View File
@@ -43,7 +43,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/UserSettings"
form := web.GetForm(ctx).(*api.UserSettingsOptions)
form := web.GetForm[*api.UserSettingsOptions](ctx)
opts := &user_service.UpdateOptions{
FullName: optional.FromPtr(form.FullName),