@ -20,45 +20,40 @@ import (
"code.gitea.io/gitea/routers/api/v1/convert"
"code.gitea.io/gitea/routers/api/v1/convert"
)
)
// SearchRepoOption options when searching repositories
// Search repositories via options
// swagger:parameters repoSearch
func Search ( ctx * context . APIContext ) {
type SearchRepoOption struct { // TODO: Move SearchRepoOption to Gitea SDK
// swagger:operation GET /repos/search repository repoSearch
// Keyword to search
// ---
//
// summary: Search for repositories
// produces:
// - application/json
// parameters:
// - name: q
// in: query
// in: query
Keyword string ` json:"q" `
// description: keyword
// Repository owner to search
// type: string
//
// - name: uid
// in: query
// in: query
OwnerID int64 ` json:"uid" `
// description: if provided, will return only repos owned by the user with the given id
// Limit of result
// type: integer
//
// - name: limit
// maximum: setting.ExplorePagingNum
// in: query
// in: query
PageSize int ` json:"limit" `
// description: maximum number of repos to return
// Type of repository to search, related to own er
// type: integ er
//
// - name: mode
// in: query
// in: query
SearchMode string ` json:"mode" `
// description: type of repository to search for. Supported values are
// Search only owners repositories
// "fork", "source", "mirror" and "collaborative"
// Has effect only if owner is provided and mode is not "collaborative"
// type: string
//
// - name: exclusive
// in: query
// in: query
OwnerExclusive bool ` json:"exclusive" `
// description: only search for repositories owned by the authenticated user
}
// type: boolean
// responses:
// Search repositories via options
// "200":
func Search ( ctx * context . APIContext ) {
// "$ref": "#/responses/SearchResults"
// swagger:route GET /repos/search repository repoSearch
// "422":
//
// "$ref": "#/responses/validationError"
// Produces:
// - application/json
//
// Responses:
// 200: SearchResults
// 422: validationError
// 500: SearchError
opts := & models . SearchRepoOptions {
opts := & models . SearchRepoOptions {
Keyword : strings . Trim ( ctx . Query ( "q" ) , " " ) ,
Keyword : strings . Trim ( ctx . Query ( "q" ) , " " ) ,
OwnerID : ctx . QueryInt64 ( "uid" ) ,
OwnerID : ctx . QueryInt64 ( "uid" ) ,
@ -187,22 +182,23 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
// Create one repository of mine
// Create one repository of mine
func Create ( ctx * context . APIContext , opt api . CreateRepoOption ) {
func Create ( ctx * context . APIContext , opt api . CreateRepoOption ) {
// swagger:route POST /user/repos repository user createCurrentUserRepo
// swagger:operation POST /user/repos repository user createCurrentUserRepo
//
// ---
// Consumes:
// summary: Create a repository
// consumes:
// - application/json
// - application/json
//
// produces:
// Produces:
// - application/json
// - application/json
//
// parameters:
// Responses:
// - name: body
// 201: Repositor y
// in: bod y
// 403: forbidden
// schema:
// 422: validationError
// "$ref": "#/definitions/CreateRepoOption"
// 500: error
// responses:
// "201":
// Shouldn't reach this condition, but just in case.
// "$ref": "#/responses/Repository"
if ctx . User . IsOrganization ( ) {
if ctx . User . IsOrganization ( ) {
// Shouldn't reach this condition, but just in case.
ctx . Error ( 422 , "" , "not allowed creating repository for organization" )
ctx . Error ( 422 , "" , "not allowed creating repository for organization" )
return
return
}
}
@ -211,20 +207,30 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
// CreateOrgRepo create one repository of the organization
// CreateOrgRepo create one repository of the organization
func CreateOrgRepo ( ctx * context . APIContext , opt api . CreateRepoOption ) {
func CreateOrgRepo ( ctx * context . APIContext , opt api . CreateRepoOption ) {
// swagger:route POST /org/{org}/repos organization createOrgRepo
// swagger:operation POST /org/{org}/repos organization createOrgRepo
//
// ---
// Consumes:
// summary: Create a repository in an organization
// consumes:
// - application/json
// - application/json
//
// produces:
// Produces:
// - application/json
// - application/json
//
// parameters:
// Responses:
// - name: org
// 201: Repository
// in: path
// 422: validationError
// description: name of organization
// 403: forbidden
// type: string
// 500: error
// required: true
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/CreateRepoOption"
// responses:
// "201":
// "$ref": "#/responses/Repository"
// "422":
// "$ref": "#/responses/validationError"
// "403":
// "$ref": "#/responses/forbidden"
org , err := models . GetOrgByName ( ctx . Params ( ":org" ) )
org , err := models . GetOrgByName ( ctx . Params ( ":org" ) )
if err != nil {
if err != nil {
if models . IsErrOrgNotExist ( err ) {
if models . IsErrOrgNotExist ( err ) {
@ -244,19 +250,21 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
// Migrate migrate remote git repository to gitea
// Migrate migrate remote git repository to gitea
func Migrate ( ctx * context . APIContext , form auth . MigrateRepoForm ) {
func Migrate ( ctx * context . APIContext , form auth . MigrateRepoForm ) {
// swagger:route POST /repos/migrate repository repoMigrate
// swagger:operation POST /repos/migrate repository repoMigrate
//
// ---
// Consumes:
// summary: Migrate a remote git repository
// consumes:
// - application/json
// - application/json
//
// produces:
// Produces:
// - application/json
// - application/json
//
// parameters:
// Responses:
// - name: body
// 201: Repository
// in: body
// 422: validationError
// schema:
// 500: error
// "$ref": "#/definitions/MigrateRepoForm"
// responses:
// "201":
// "$ref": "#/responses/Repository"
ctxUser := ctx . User
ctxUser := ctx . User
// Not equal means context user is an organization,
// Not equal means context user is an organization,
// or is another user/organization if current user is admin.
// or is another user/organization if current user is admin.
@ -329,29 +337,44 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
// Get one repository
// Get one repository
func Get ( ctx * context . APIContext ) {
func Get ( ctx * context . APIContext ) {
// swagger:route GET /repos/{username}/{reponame} repository repoGet
// swagger:operation GET /repos/{owner}/{repo} repository repoGet
//
// ---
// Produces:
// summary: Get a repository
// produces:
// - application/json
// - application/json
//
// parameters:
// Responses:
// - name: owner
// 200: Repository
// in: path
// 500: error
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/Repository"
ctx . JSON ( 200 , ctx . Repo . Repository . APIFormat ( ctx . Repo . AccessMode ) )
ctx . JSON ( 200 , ctx . Repo . Repository . APIFormat ( ctx . Repo . AccessMode ) )
}
}
// GetByID returns a single Repository
// GetByID returns a single Repository
func GetByID ( ctx * context . APIContext ) {
func GetByID ( ctx * context . APIContext ) {
// swagger:route GET /repositories/{id} repository repoGetByID
// swagger:operation GET /repositories/{id} repository repoGetByID
//
// ---
// Produces:
// summary: Get a repository by id
// produces:
// - application/json
// - application/json
//
// parameters:
// Responses:
// - name: id
// 200: Repository
// in: path
// 500: error
// description: id of the repo to get
// type: integer
// required: true
// responses:
// "200":
// "$ref": "#/responses/Repository"
repo , err := models . GetRepositoryByID ( ctx . ParamsInt64 ( ":id" ) )
repo , err := models . GetRepositoryByID ( ctx . ParamsInt64 ( ":id" ) )
if err != nil {
if err != nil {
if models . IsErrRepoNotExist ( err ) {
if models . IsErrRepoNotExist ( err ) {
@ -375,16 +398,27 @@ func GetByID(ctx *context.APIContext) {
// Delete one repository
// Delete one repository
func Delete ( ctx * context . APIContext ) {
func Delete ( ctx * context . APIContext ) {
// swagger:route DELETE /repos/{username}/{reponame} repository repoDelete
// swagger:operation DELETE /repos/{owner}/{repo} repository repoDelete
//
// ---
// Produces:
// summary: Delete a repository
// produces:
// - application/json
// - application/json
//
// parameters:
// Responses:
// - name: owner
// 204: empty
// in: path
// 403: forbidden
// description: owner of the repo to delete
// 500: error
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo to delete
// type: string
// required: true
// responses:
// "204":
// "$ref": "#/responses/empty"
// "403":
// "$ref": "#/responses/forbidden"
if ! ctx . Repo . IsAdmin ( ) {
if ! ctx . Repo . IsAdmin ( ) {
ctx . Error ( 403 , "" , "Must have admin rights" )
ctx . Error ( 403 , "" , "Must have admin rights" )
return
return
@ -408,15 +442,25 @@ func Delete(ctx *context.APIContext) {
// MirrorSync adds a mirrored repository to the sync queue
// MirrorSync adds a mirrored repository to the sync queue
func MirrorSync ( ctx * context . APIContext ) {
func MirrorSync ( ctx * context . APIContext ) {
// swagger:route POST /repos/{username}/{reponame}/mirror-sync repository repoMirrorSync
// swagger:operation POST /repos/{owner}/{repo}/mirror-sync repository repoMirrorSync
//
// ---
// Produces:
// summary: Sync a mirrored repository
// produces:
// - application/json
// - application/json
//
// parameters:
// Responses:
// - name: owner
// 200: empty
// in: path
// 403: forbidden
// description: owner of the repo to sync
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo to sync
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/empty"
repo := ctx . Repo . Repository
repo := ctx . Repo . Repository
if ! ctx . Repo . IsWriter ( ) {
if ! ctx . Repo . IsWriter ( ) {