mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
Move macaron to chi (#14293)
Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
@ -16,6 +16,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
@ -175,7 +176,7 @@ func DeleteBranch(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateBranch creates a branch for a user's repository
|
||||
func CreateBranch(ctx *context.APIContext, opt api.CreateBranchRepoOption) {
|
||||
func CreateBranch(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/branches repository repoCreateBranch
|
||||
// ---
|
||||
// summary: Create a branch
|
||||
@ -206,6 +207,7 @@ func CreateBranch(ctx *context.APIContext, opt api.CreateBranchRepoOption) {
|
||||
// "409":
|
||||
// description: The branch with the same name already exists.
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateBranchRepoOption)
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.Error(http.StatusNotFound, "", "Git Repository is empty.")
|
||||
return
|
||||
@ -395,7 +397,7 @@ func ListBranchProtections(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateBranchProtection creates a branch protection for a repo
|
||||
func CreateBranchProtection(ctx *context.APIContext, form api.CreateBranchProtectionOption) {
|
||||
func CreateBranchProtection(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/branch_protections repository repoCreateBranchProtection
|
||||
// ---
|
||||
// summary: Create a branch protections for a repository
|
||||
@ -428,6 +430,7 @@ func CreateBranchProtection(ctx *context.APIContext, form api.CreateBranchProtec
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateBranchProtectionOption)
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
// Currently protection must match an actual branch
|
||||
@ -561,7 +564,7 @@ func CreateBranchProtection(ctx *context.APIContext, form api.CreateBranchProtec
|
||||
}
|
||||
|
||||
// EditBranchProtection edits a branch protection for a repo
|
||||
func EditBranchProtection(ctx *context.APIContext, form api.EditBranchProtectionOption) {
|
||||
func EditBranchProtection(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/branch_protections/{name} repository repoEditBranchProtection
|
||||
// ---
|
||||
// summary: Edit a branch protections for a repository. Only fields that are set will be changed
|
||||
@ -596,7 +599,7 @@ func EditBranchProtection(ctx *context.APIContext, form api.EditBranchProtection
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditBranchProtectionOption)
|
||||
repo := ctx.Repo.Repository
|
||||
bpName := ctx.Params(":name")
|
||||
protectBranch, err := models.GetProtectedBranchBy(repo.ID, bpName)
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@ -111,7 +112,7 @@ func IsCollaborator(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// AddCollaborator add a collaborator to a repository
|
||||
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
|
||||
func AddCollaborator(ctx *context.APIContext) {
|
||||
// swagger:operation PUT /repos/{owner}/{repo}/collaborators/{collaborator} repository repoAddCollaborator
|
||||
// ---
|
||||
// summary: Add a collaborator to a repository
|
||||
@ -143,6 +144,8 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.AddCollaboratorOption)
|
||||
|
||||
collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
|
@ -69,7 +69,11 @@ func getCommit(ctx *context.APIContext, identifier string) {
|
||||
defer gitRepo.Close()
|
||||
commit, err := gitRepo.GetCommit(identifier)
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err)
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound(identifier)
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "gitRepo.GetCommit", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/repofiles"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/repo"
|
||||
)
|
||||
|
||||
@ -167,7 +168,7 @@ func canReadFiles(r *context.Repository) bool {
|
||||
}
|
||||
|
||||
// CreateFile handles API call for creating a file
|
||||
func CreateFile(ctx *context.APIContext, apiOpts api.CreateFileOptions) {
|
||||
func CreateFile(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/contents/{filepath} repository repoCreateFile
|
||||
// ---
|
||||
// summary: Create a file in a repository
|
||||
@ -206,6 +207,7 @@ func CreateFile(ctx *context.APIContext, apiOpts api.CreateFileOptions) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
apiOpts := web.GetForm(ctx).(*api.CreateFileOptions)
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
|
||||
}
|
||||
@ -253,7 +255,7 @@ func CreateFile(ctx *context.APIContext, apiOpts api.CreateFileOptions) {
|
||||
}
|
||||
|
||||
// UpdateFile handles API call for updating a file
|
||||
func UpdateFile(ctx *context.APIContext, apiOpts api.UpdateFileOptions) {
|
||||
func UpdateFile(ctx *context.APIContext) {
|
||||
// swagger:operation PUT /repos/{owner}/{repo}/contents/{filepath} repository repoUpdateFile
|
||||
// ---
|
||||
// summary: Update a file in a repository
|
||||
@ -291,7 +293,7 @@ func UpdateFile(ctx *context.APIContext, apiOpts api.UpdateFileOptions) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
apiOpts := web.GetForm(ctx).(*api.UpdateFileOptions)
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", fmt.Errorf("repo is empty"))
|
||||
}
|
||||
@ -377,7 +379,7 @@ func createOrUpdateFile(ctx *context.APIContext, opts *repofiles.UpdateRepoFileO
|
||||
}
|
||||
|
||||
// DeleteFile Delete a fle in a repository
|
||||
func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
|
||||
func DeleteFile(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /repos/{owner}/{repo}/contents/{filepath} repository repoDeleteFile
|
||||
// ---
|
||||
// summary: Delete a file in a repository
|
||||
@ -416,6 +418,7 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
|
||||
if !canWriteFiles(ctx.Repo) {
|
||||
ctx.Error(http.StatusForbidden, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{
|
||||
UserID: ctx.User.ID,
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
@ -65,7 +66,7 @@ func ListForks(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateFork create a fork of a repo
|
||||
func CreateFork(ctx *context.APIContext, form api.CreateForkOption) {
|
||||
func CreateFork(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/forks repository createFork
|
||||
// ---
|
||||
// summary: Fork a repository
|
||||
@ -94,6 +95,7 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateForkOption)
|
||||
repo := ctx.Repo.Repository
|
||||
var forker *models.User // user/org that will own the fork
|
||||
if form.Organization == nil {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
)
|
||||
|
||||
// ListGitHooks list all Git hooks of a repository
|
||||
@ -91,7 +92,7 @@ func GetGitHook(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// EditGitHook modify a Git hook of a repository
|
||||
func EditGitHook(ctx *context.APIContext, form api.EditGitHookOption) {
|
||||
func EditGitHook(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/hooks/git/{id} repository repoEditGitHook
|
||||
// ---
|
||||
// summary: Edit a Git hook in a repository
|
||||
@ -123,6 +124,7 @@ func EditGitHook(ctx *context.APIContext, form api.EditGitHookOption) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditGitHookOption)
|
||||
hookID := ctx.Params(":id")
|
||||
hook, err := ctx.Repo.GitRepo.GetHook(hookID)
|
||||
if err != nil {
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"code.gitea.io/gitea/services/webhook"
|
||||
)
|
||||
@ -158,7 +159,7 @@ func TestHook(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateHook create a hook for a repository
|
||||
func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||
func CreateHook(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/hooks repository repoCreateHook
|
||||
// ---
|
||||
// summary: Create a hook
|
||||
@ -184,14 +185,16 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||
// responses:
|
||||
// "201":
|
||||
// "$ref": "#/responses/Hook"
|
||||
if !utils.CheckCreateHookOption(ctx, &form) {
|
||||
form := web.GetForm(ctx).(*api.CreateHookOption)
|
||||
|
||||
if !utils.CheckCreateHookOption(ctx, form) {
|
||||
return
|
||||
}
|
||||
utils.AddRepoHook(ctx, &form)
|
||||
utils.AddRepoHook(ctx, form)
|
||||
}
|
||||
|
||||
// EditHook modify a hook of a repository
|
||||
func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
||||
func EditHook(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/hooks/{id} repository repoEditHook
|
||||
// ---
|
||||
// summary: Edit a hook in a repository
|
||||
@ -221,8 +224,9 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Hook"
|
||||
form := web.GetForm(ctx).(*api.EditHookOption)
|
||||
hookID := ctx.ParamsInt64(":id")
|
||||
utils.EditRepoHook(ctx, &form, hookID)
|
||||
utils.EditRepoHook(ctx, form, hookID)
|
||||
}
|
||||
|
||||
// DeleteHook delete a hook of a repository
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
)
|
||||
@ -448,7 +449,7 @@ func GetIssue(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateIssue create an issue of a repository
|
||||
func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
func CreateIssue(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/issues issue issueCreateIssue
|
||||
// ---
|
||||
// summary: Create an issue. If using deadline only the date will be taken into account, and time of day ignored.
|
||||
@ -480,7 +481,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
// "$ref": "#/responses/error"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateIssueOption)
|
||||
var deadlineUnix timeutil.TimeStamp
|
||||
if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) {
|
||||
deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
|
||||
@ -564,7 +565,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
}
|
||||
|
||||
// EditIssue modify an issue of a repository
|
||||
func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||
func EditIssue(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/issues/{index} issue issueEditIssue
|
||||
// ---
|
||||
// summary: Edit an issue. If using deadline only the date will be taken into account, and time of day ignored.
|
||||
@ -603,6 +604,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||
// "412":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditIssueOption)
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
@ -723,7 +725,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||
}
|
||||
|
||||
// UpdateIssueDeadline updates an issue deadline
|
||||
func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) {
|
||||
func UpdateIssueDeadline(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/issues/{index}/deadline issue issueEditIssueDeadline
|
||||
// ---
|
||||
// summary: Set an issue deadline. If set to null, the deadline is deleted. If using deadline only the date will be taken into account, and time of day ignored.
|
||||
@ -759,7 +761,7 @@ func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) {
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditDeadlineOption)
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
comment_service "code.gitea.io/gitea/services/comments"
|
||||
)
|
||||
@ -174,7 +175,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateIssueComment create a comment for an issue
|
||||
func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOption) {
|
||||
func CreateIssueComment(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/issues/{index}/comments issue issueCreateComment
|
||||
// ---
|
||||
// summary: Add a comment to an issue
|
||||
@ -208,7 +209,7 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti
|
||||
// "$ref": "#/responses/Comment"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||
@ -298,7 +299,7 @@ func GetIssueComment(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// EditIssueComment modify a comment of an issue
|
||||
func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
|
||||
func EditIssueComment(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/issues/comments/{id} issue issueEditComment
|
||||
// ---
|
||||
// summary: Edit a comment
|
||||
@ -337,11 +338,12 @@ func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
editIssueComment(ctx, form)
|
||||
form := web.GetForm(ctx).(*api.EditIssueCommentOption)
|
||||
editIssueComment(ctx, *form)
|
||||
}
|
||||
|
||||
// EditIssueCommentDeprecated modify a comment of an issue
|
||||
func EditIssueCommentDeprecated(ctx *context.APIContext, form api.EditIssueCommentOption) {
|
||||
func EditIssueCommentDeprecated(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/issues/{index}/comments/{id} issue issueEditCommentDeprecated
|
||||
// ---
|
||||
// summary: Edit a comment
|
||||
@ -386,7 +388,8 @@ func EditIssueCommentDeprecated(ctx *context.APIContext, form api.EditIssueComme
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
editIssueComment(ctx, form)
|
||||
form := web.GetForm(ctx).(*api.EditIssueCommentOption)
|
||||
editIssueComment(ctx, *form)
|
||||
}
|
||||
|
||||
func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
)
|
||||
|
||||
@ -64,7 +65,7 @@ func ListIssueLabels(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// AddIssueLabels add labels for an issue
|
||||
func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
func AddIssueLabels(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/issues/{index}/labels issue issueAddLabel
|
||||
// ---
|
||||
// summary: Add a label to an issue
|
||||
@ -99,7 +100,8 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
issue, labels, err := prepareForReplaceOrAdd(ctx, form)
|
||||
form := web.GetForm(ctx).(*api.IssueLabelsOption)
|
||||
issue, labels, err := prepareForReplaceOrAdd(ctx, *form)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -190,7 +192,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// ReplaceIssueLabels replace labels for an issue
|
||||
func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
func ReplaceIssueLabels(ctx *context.APIContext) {
|
||||
// swagger:operation PUT /repos/{owner}/{repo}/issues/{index}/labels issue issueReplaceLabels
|
||||
// ---
|
||||
// summary: Replace an issue's labels
|
||||
@ -224,8 +226,8 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
// "$ref": "#/responses/LabelList"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
issue, labels, err := prepareForReplaceOrAdd(ctx, form)
|
||||
form := web.GetForm(ctx).(*api.IssueLabelsOption)
|
||||
issue, labels, err := prepareForReplaceOrAdd(ctx, *form)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@ -90,7 +91,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// PostIssueCommentReaction add a reaction to a comment of an issue
|
||||
func PostIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption) {
|
||||
func PostIssueCommentReaction(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/issues/comments/{id}/reactions issue issuePostCommentReaction
|
||||
// ---
|
||||
// summary: Add a reaction to a comment of an issue
|
||||
@ -127,11 +128,13 @@ func PostIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOpti
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
changeIssueCommentReaction(ctx, form, true)
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
|
||||
changeIssueCommentReaction(ctx, *form, true)
|
||||
}
|
||||
|
||||
// DeleteIssueCommentReaction remove a reaction from a comment of an issue
|
||||
func DeleteIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption) {
|
||||
func DeleteIssueCommentReaction(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /repos/{owner}/{repo}/issues/comments/{id}/reactions issue issueDeleteCommentReaction
|
||||
// ---
|
||||
// summary: Remove a reaction from a comment of an issue
|
||||
@ -166,7 +169,9 @@ func DeleteIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
changeIssueCommentReaction(ctx, form, false)
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
|
||||
changeIssueCommentReaction(ctx, *form, false)
|
||||
}
|
||||
|
||||
func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) {
|
||||
@ -304,7 +309,7 @@ func GetIssueReactions(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// PostIssueReaction add a reaction to an issue
|
||||
func PostIssueReaction(ctx *context.APIContext, form api.EditReactionOption) {
|
||||
func PostIssueReaction(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/issues/{index}/reactions issue issuePostIssueReaction
|
||||
// ---
|
||||
// summary: Add a reaction to an issue
|
||||
@ -340,12 +345,12 @@ func PostIssueReaction(ctx *context.APIContext, form api.EditReactionOption) {
|
||||
// "$ref": "#/responses/Reaction"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
changeIssueReaction(ctx, form, true)
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
changeIssueReaction(ctx, *form, true)
|
||||
}
|
||||
|
||||
// DeleteIssueReaction remove a reaction from an issue
|
||||
func DeleteIssueReaction(ctx *context.APIContext, form api.EditReactionOption) {
|
||||
func DeleteIssueReaction(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /repos/{owner}/{repo}/issues/{index}/reactions issue issueDeleteIssueReaction
|
||||
// ---
|
||||
// summary: Remove a reaction from an issue
|
||||
@ -379,8 +384,8 @@ func DeleteIssueReaction(ctx *context.APIContext, form api.EditReactionOption) {
|
||||
// "$ref": "#/responses/empty"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
changeIssueReaction(ctx, form, false)
|
||||
form := web.GetForm(ctx).(*api.EditReactionOption)
|
||||
changeIssueReaction(ctx, *form, false)
|
||||
}
|
||||
|
||||
func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) {
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@ -132,7 +133,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// AddTime add time manual to the given issue
|
||||
func AddTime(ctx *context.APIContext, form api.AddTimeOption) {
|
||||
func AddTime(ctx *context.APIContext) {
|
||||
// swagger:operation Post /repos/{owner}/{repo}/issues/{index}/times issue issueAddTime
|
||||
// ---
|
||||
// summary: Add tracked time to a issue
|
||||
@ -168,7 +169,7 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) {
|
||||
// "$ref": "#/responses/error"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
form := web.GetForm(ctx).(*api.AddTimeOption)
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@ -185,7 +186,7 @@ func HandleAddKeyError(ctx *context.APIContext, err error) {
|
||||
}
|
||||
|
||||
// CreateDeployKey create deploy key for a repository
|
||||
func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
func CreateDeployKey(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/keys repository repoCreateKey
|
||||
// ---
|
||||
// summary: Add a key to a repository
|
||||
@ -214,6 +215,7 @@ func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateKeyOption)
|
||||
content, err := models.CheckPublicKeyString(form.Key)
|
||||
if err != nil {
|
||||
HandleCheckKeyStringError(ctx, err)
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@ -108,7 +109,7 @@ func GetLabel(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateLabel create a label for a repository
|
||||
func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||
func CreateLabel(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/labels issue issueCreateLabel
|
||||
// ---
|
||||
// summary: Create a label
|
||||
@ -137,6 +138,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateLabelOption)
|
||||
form.Color = strings.Trim(form.Color, " ")
|
||||
if len(form.Color) == 6 {
|
||||
form.Color = "#" + form.Color
|
||||
@ -160,7 +162,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||
}
|
||||
|
||||
// EditLabel modify a label for a repository
|
||||
func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
||||
func EditLabel(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/labels/{id} issue issueEditLabel
|
||||
// ---
|
||||
// summary: Update a label
|
||||
@ -195,6 +197,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditLabelOption)
|
||||
label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
if models.IsErrRepoLabelNotExist(err) {
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/migrations"
|
||||
@ -24,10 +24,11 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
)
|
||||
|
||||
// Migrate migrate remote git repository to gitea
|
||||
func Migrate(ctx *context.APIContext, form api.MigrateRepoOptions) {
|
||||
func Migrate(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/migrate repository repoMigrate
|
||||
// ---
|
||||
// summary: Migrate a remote git repository
|
||||
@ -48,6 +49,8 @@ func Migrate(ctx *context.APIContext, form api.MigrateRepoOptions) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.MigrateRepoOptions)
|
||||
|
||||
//get repoOwner
|
||||
var (
|
||||
repoOwner *models.User
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@ -110,7 +111,7 @@ func GetMilestone(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateMilestone create a milestone for a repository
|
||||
func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
||||
func CreateMilestone(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/milestones issue issueCreateMilestone
|
||||
// ---
|
||||
// summary: Create a milestone
|
||||
@ -136,6 +137,7 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
||||
// responses:
|
||||
// "201":
|
||||
// "$ref": "#/responses/Milestone"
|
||||
form := web.GetForm(ctx).(*api.CreateMilestoneOption)
|
||||
|
||||
if form.Deadline == nil {
|
||||
defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
|
||||
@ -162,7 +164,7 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
||||
}
|
||||
|
||||
// EditMilestone modify a milestone for a repository by ID and if not available by name
|
||||
func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
|
||||
func EditMilestone(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/milestones/{id} issue issueEditMilestone
|
||||
// ---
|
||||
// summary: Update a milestone
|
||||
@ -193,7 +195,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Milestone"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditMilestoneOption)
|
||||
milestone := getMilestoneByIDOrName(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
@ -11,21 +11,22 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
auth "code.gitea.io/gitea/modules/forms"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
)
|
||||
|
||||
// ListPullRequests returns a list of all PRs
|
||||
func ListPullRequests(ctx *context.APIContext, form api.ListPullRequestsOptions) {
|
||||
func ListPullRequests(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/pulls repository repoListPullRequests
|
||||
// ---
|
||||
// summary: List a repo's pull requests
|
||||
@ -253,7 +254,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext, patch bool) {
|
||||
}
|
||||
|
||||
// CreatePullRequest does what it says
|
||||
func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption) {
|
||||
func CreatePullRequest(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/pulls repository repoCreatePullRequest
|
||||
// ---
|
||||
// summary: Create a pull request
|
||||
@ -284,6 +285,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := *web.GetForm(ctx).(*api.CreatePullRequestOption)
|
||||
if form.Head == form.Base {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "BaseHeadSame",
|
||||
"Invalid PullRequest: There are no changes between the head and the base")
|
||||
@ -437,7 +439,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
|
||||
}
|
||||
|
||||
// EditPullRequest does what it says
|
||||
func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
||||
func EditPullRequest(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/pulls/{index} repository repoEditPullRequest
|
||||
// ---
|
||||
// summary: Update a pull request. If using deadline only the date will be taken into account, and time of day ignored.
|
||||
@ -478,6 +480,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditPullRequestOption)
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
@ -685,7 +688,7 @@ func IsPullRequestMerged(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// MergePullRequest merges a PR given an index
|
||||
func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
|
||||
func MergePullRequest(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/merge repository repoMergePullRequest
|
||||
// ---
|
||||
// summary: Merge a pull request
|
||||
@ -720,6 +723,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
|
||||
// "409":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
form := web.GetForm(ctx).(*auth.MergePullRequestForm)
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
@ -258,7 +259,7 @@ func DeletePullReview(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreatePullReview create a review to an pull request
|
||||
func CreatePullReview(ctx *context.APIContext, opts api.CreatePullReviewOptions) {
|
||||
func CreatePullReview(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/reviews repository repoCreatePullReview
|
||||
// ---
|
||||
// summary: Create a review to an pull request
|
||||
@ -294,6 +295,7 @@ func CreatePullReview(ctx *context.APIContext, opts api.CreatePullReviewOptions)
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.CreatePullReviewOptions)
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrPullRequestNotExist(err) {
|
||||
@ -373,7 +375,7 @@ func CreatePullReview(ctx *context.APIContext, opts api.CreatePullReviewOptions)
|
||||
}
|
||||
|
||||
// SubmitPullReview submit a pending review to an pull request
|
||||
func SubmitPullReview(ctx *context.APIContext, opts api.SubmitPullReviewOptions) {
|
||||
func SubmitPullReview(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/reviews/{id} repository repoSubmitPullReview
|
||||
// ---
|
||||
// summary: Submit a pending review to an pull request
|
||||
@ -415,6 +417,7 @@ func SubmitPullReview(ctx *context.APIContext, opts api.SubmitPullReviewOptions)
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.SubmitPullReviewOptions)
|
||||
review, pr, isWrong := prepareSingleReview(ctx)
|
||||
if isWrong {
|
||||
return
|
||||
@ -542,7 +545,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
|
||||
}
|
||||
|
||||
// CreateReviewRequests create review requests to an pull request
|
||||
func CreateReviewRequests(ctx *context.APIContext, opts api.PullReviewRequestOptions) {
|
||||
func CreateReviewRequests(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/pulls/{index}/requested_reviewers repository repoCreatePullReviewRequests
|
||||
// ---
|
||||
// summary: create review requests for a pull request
|
||||
@ -577,11 +580,13 @@ func CreateReviewRequests(ctx *context.APIContext, opts api.PullReviewRequestOpt
|
||||
// "$ref": "#/responses/validationError"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
apiReviewRequest(ctx, opts, true)
|
||||
|
||||
opts := web.GetForm(ctx).(*api.PullReviewRequestOptions)
|
||||
apiReviewRequest(ctx, *opts, true)
|
||||
}
|
||||
|
||||
// DeleteReviewRequests delete review requests to an pull request
|
||||
func DeleteReviewRequests(ctx *context.APIContext, opts api.PullReviewRequestOptions) {
|
||||
func DeleteReviewRequests(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /repos/{owner}/{repo}/pulls/{index}/requested_reviewers repository repoDeletePullReviewRequests
|
||||
// ---
|
||||
// summary: cancel review requests for a pull request
|
||||
@ -616,7 +621,8 @@ func DeleteReviewRequests(ctx *context.APIContext, opts api.PullReviewRequestOpt
|
||||
// "$ref": "#/responses/validationError"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
apiReviewRequest(ctx, opts, false)
|
||||
opts := web.GetForm(ctx).(*api.PullReviewRequestOptions)
|
||||
apiReviewRequest(ctx, *opts, false)
|
||||
}
|
||||
|
||||
func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions, isAdd bool) {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
releaseservice "code.gitea.io/gitea/services/release"
|
||||
)
|
||||
@ -124,7 +125,7 @@ func ListReleases(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// CreateRelease create a release
|
||||
func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
|
||||
func CreateRelease(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/releases repository repoCreateRelease
|
||||
// ---
|
||||
// summary: Create a release
|
||||
@ -154,7 +155,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "409":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateReleaseOption)
|
||||
rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName)
|
||||
if err != nil {
|
||||
if !models.IsErrReleaseNotExist(err) {
|
||||
@ -210,7 +211,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
|
||||
}
|
||||
|
||||
// EditRelease edit a release
|
||||
func EditRelease(ctx *context.APIContext, form api.EditReleaseOption) {
|
||||
func EditRelease(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/releases/{id} repository repoEditRelease
|
||||
// ---
|
||||
// summary: Update a release
|
||||
@ -245,6 +246,7 @@ func EditRelease(ctx *context.APIContext, form api.EditReleaseOption) {
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditReleaseOption)
|
||||
id := ctx.ParamsInt64(":id")
|
||||
rel, err := models.GetReleaseByID(id)
|
||||
if err != nil && !models.IsErrReleaseNotExist(err) {
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/upload"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
)
|
||||
|
||||
// GetReleaseAttachment gets a single attachment of the release
|
||||
@ -168,7 +169,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// Get uploaded file from request
|
||||
file, header, err := ctx.GetFile("attachment")
|
||||
file, header, err := ctx.Req.FormFile("attachment")
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetFile", err)
|
||||
return
|
||||
@ -208,7 +209,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// EditReleaseAttachment updates the given attachment
|
||||
func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptions) {
|
||||
func EditReleaseAttachment(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/releases/{id}/assets/{attachment_id} repository repoEditReleaseAttachment
|
||||
// ---
|
||||
// summary: Edit a release attachment
|
||||
@ -247,6 +248,8 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio
|
||||
// "201":
|
||||
// "$ref": "#/responses/Attachment"
|
||||
|
||||
form := web.GetForm(ctx).(*api.EditAttachmentOptions)
|
||||
|
||||
// Check if release exists an load release
|
||||
releaseID := ctx.ParamsInt64(":id")
|
||||
attachID := ctx.ParamsInt64(":asset")
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
@ -277,7 +278,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
|
||||
}
|
||||
|
||||
// Create one repository of mine
|
||||
func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
func Create(ctx *context.APIContext) {
|
||||
// swagger:operation POST /user/repos repository user createCurrentUserRepo
|
||||
// ---
|
||||
// summary: Create a repository
|
||||
@ -297,17 +298,17 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
// description: The repository with the same name already exists.
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||
if ctx.User.IsOrganization() {
|
||||
// Shouldn't reach this condition, but just in case.
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", "not allowed creating repository for organization")
|
||||
return
|
||||
}
|
||||
CreateUserRepo(ctx, ctx.User, opt)
|
||||
CreateUserRepo(ctx, ctx.User, *opt)
|
||||
}
|
||||
|
||||
// CreateOrgRepoDeprecated create one repository of the organization
|
||||
func CreateOrgRepoDeprecated(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
func CreateOrgRepoDeprecated(ctx *context.APIContext) {
|
||||
// swagger:operation POST /org/{org}/repos organization createOrgRepoDeprecated
|
||||
// ---
|
||||
// summary: Create a repository in an organization
|
||||
@ -334,11 +335,11 @@ func CreateOrgRepoDeprecated(ctx *context.APIContext, opt api.CreateRepoOption)
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
CreateOrgRepo(ctx, opt)
|
||||
CreateOrgRepo(ctx)
|
||||
}
|
||||
|
||||
// CreateOrgRepo create one repository of the organization
|
||||
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
func CreateOrgRepo(ctx *context.APIContext) {
|
||||
// swagger:operation POST /orgs/{org}/repos organization createOrgRepo
|
||||
// ---
|
||||
// summary: Create a repository in an organization
|
||||
@ -363,7 +364,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
opt := web.GetForm(ctx).(*api.CreateRepoOption)
|
||||
org, err := models.GetOrgByName(ctx.Params(":org"))
|
||||
if err != nil {
|
||||
if models.IsErrOrgNotExist(err) {
|
||||
@ -389,7 +390,7 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
return
|
||||
}
|
||||
}
|
||||
CreateUserRepo(ctx, org, opt)
|
||||
CreateUserRepo(ctx, org, *opt)
|
||||
}
|
||||
|
||||
// Get one repository
|
||||
@ -457,7 +458,7 @@ func GetByID(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// Edit edit repository properties
|
||||
func Edit(ctx *context.APIContext, opts api.EditRepoOption) {
|
||||
func Edit(ctx *context.APIContext) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo} repository repoEdit
|
||||
// ---
|
||||
// summary: Edit a repository's properties. Only fields that are set will be changed.
|
||||
@ -488,6 +489,8 @@ func Edit(ctx *context.APIContext, opts api.EditRepoOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := *web.GetForm(ctx).(*api.EditRepoOption)
|
||||
|
||||
if err := updateBasicProperties(ctx, opts); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -53,7 +54,9 @@ func TestRepoEdit(t *testing.T) {
|
||||
Archived: &archived,
|
||||
}
|
||||
|
||||
Edit(&context.APIContext{Context: ctx, Org: nil}, opts)
|
||||
var apiCtx = &context.APIContext{Context: ctx, Org: nil}
|
||||
web.SetForm(apiCtx, &opts)
|
||||
Edit(apiCtx)
|
||||
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
models.AssertExistsAndLoadBean(t, &models.Repository{
|
||||
@ -73,7 +76,9 @@ func TestRepoEditNameChange(t *testing.T) {
|
||||
Name: &name,
|
||||
}
|
||||
|
||||
Edit(&context.APIContext{Context: ctx, Org: nil}, opts)
|
||||
var apiCtx = &context.APIContext{Context: ctx, Org: nil}
|
||||
web.SetForm(apiCtx, &opts)
|
||||
Edit(apiCtx)
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
|
||||
models.AssertExistsAndLoadBean(t, &models.Repository{
|
||||
|
@ -13,11 +13,12 @@ import (
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/repofiles"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
// NewCommitStatus creates a new CommitStatus
|
||||
func NewCommitStatus(ctx *context.APIContext, form api.CreateStatusOption) {
|
||||
func NewCommitStatus(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/statuses/{sha} repository repoCreateStatus
|
||||
// ---
|
||||
// summary: Create a commit status
|
||||
@ -49,6 +50,7 @@ func NewCommitStatus(ctx *context.APIContext, form api.CreateStatusOption) {
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
|
||||
form := web.GetForm(ctx).(*api.CreateStatusOption)
|
||||
sha := ctx.Params("sha")
|
||||
if len(sha) == 0 {
|
||||
ctx.Error(http.StatusBadRequest, "sha not given", nil)
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
)
|
||||
|
||||
@ -66,7 +67,7 @@ func ListTopics(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
// UpdateTopics updates repo with a new set of topics
|
||||
func UpdateTopics(ctx *context.APIContext, form api.RepoTopicOptions) {
|
||||
func UpdateTopics(ctx *context.APIContext) {
|
||||
// swagger:operation PUT /repos/{owner}/{repo}/topics repository repoUpdateTopics
|
||||
// ---
|
||||
// summary: Replace list of topics for a repository
|
||||
@ -93,6 +94,7 @@ func UpdateTopics(ctx *context.APIContext, form api.RepoTopicOptions) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/invalidTopicsError"
|
||||
|
||||
form := web.GetForm(ctx).(*api.RepoTopicOptions)
|
||||
topicNames := form.Topics
|
||||
validTopics, invalidTopics := models.SanitizeAndValidateTopics(topicNames)
|
||||
|
||||
|
@ -14,11 +14,12 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
|
||||
// Transfer transfers the ownership of a repository
|
||||
func Transfer(ctx *context.APIContext, opts api.TransferRepoOption) {
|
||||
func Transfer(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/transfer repository repoTransfer
|
||||
// ---
|
||||
// summary: Transfer a repo ownership
|
||||
@ -51,6 +52,8 @@ func Transfer(ctx *context.APIContext, opts api.TransferRepoOption) {
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
opts := web.GetForm(ctx).(*api.TransferRepoOption)
|
||||
|
||||
newOwner, err := models.GetUserByName(opts.NewOwner)
|
||||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
|
Reference in New Issue
Block a user