Merge pull request '[API] Add 添加对仓库的二级页面README.md内容获取' (#10) from wonderful/gitea-1156:develop into develop
This commit is contained in:
commit
73aed61d0b
|
@ -792,6 +792,10 @@ func Routes() *web.Route {
|
|||
Delete(repo.DeleteWiki)
|
||||
})
|
||||
})
|
||||
m.Group("/readme", func() {
|
||||
m.Get("", repo.GetReadmeContents)
|
||||
m.Get("/*", repo.GetReadmeContentsByPath)
|
||||
})
|
||||
m.Get("/commits_slice", repo.GetAllCommitsSliceByTime)
|
||||
m.Group("/tags", func() {
|
||||
m.Get("", repo.ListTags)
|
||||
|
@ -968,7 +972,6 @@ func Routes() *web.Route {
|
|||
m.Group("/contents", func() {
|
||||
m.Get("", repo.GetContentsList)
|
||||
m.Get("/*", repo.GetContents)
|
||||
m.Get("/readme", repo.GetReadmeContents)
|
||||
m.Group("/*", func() {
|
||||
m.Post("", bind(api.CreateFileOptions{}), repo.CreateFile)
|
||||
m.Put("", bind(api.UpdateFileOptions{}), repo.UpdateFile)
|
||||
|
|
|
@ -286,7 +286,7 @@ func UpdateFile(ctx *context.APIContext) {
|
|||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// - application/jsoncontent
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
|
@ -599,7 +599,7 @@ func GetContentsList(ctx *context.APIContext) {
|
|||
|
||||
// GetReadmeContents Get the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir
|
||||
func GetReadmeContents(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/contents/readme repository repoGetReadmeContents
|
||||
// swagger:operation GET /repos/{owner}/{repo}/readme repository repoGetReadmeContents
|
||||
// ---
|
||||
// summary: Gets the README.md's contents (if a file) of an entry in a repository ***
|
||||
// produces:
|
||||
|
@ -647,3 +647,58 @@ func GetReadmeContents(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, fileList)
|
||||
}
|
||||
}
|
||||
|
||||
func GetReadmeContentsByPath(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/readme/{dir} repository repoGetReadmeContentsByPath
|
||||
// ---
|
||||
// summary: Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir ***
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: dir
|
||||
// in: path
|
||||
// description: path of the dir, file, symlink or submodule in the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: ref
|
||||
// in: query
|
||||
// description: "The name of the commit/branch/tag. Default the repository’s default branch (usually master)"
|
||||
// type: string
|
||||
// required: false
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/ContentsResponse"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
if !canReadFiles(ctx.Repo) {
|
||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
|
||||
UserID: ctx.User.ID,
|
||||
RepoName: ctx.Repo.Repository.LowerName,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
treePath := ctx.Params("*")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
newTreePath := treePath + "/" + "README.md"
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, newTreePath, ref); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetContentsOrList", err)
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err)
|
||||
} else {
|
||||
ctx.JSON(http.StatusOK, fileList)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3215,48 +3215,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/contents/readme": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Gets the README.md's contents (if a file) of an entry in a repository ***",
|
||||
"operationId": "repoGetReadmeContents",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
|
||||
"name": "ref",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/ContentsResponse"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/contents/{filepath}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -3310,7 +3268,7 @@
|
|||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
"application/jsoncontent"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
|
@ -8272,6 +8230,97 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/readme": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Gets the README.md's contents (if a file) of an entry in a repository ***",
|
||||
"operationId": "repoGetReadmeContents",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
|
||||
"name": "ref",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/ContentsResponse"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/readme/{dir}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Gets the metadata and contents (if a file) of an entry in a repository, or a list of entries if a dir ***",
|
||||
"operationId": "repoGetReadmeContentsByPath",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "path of the dir, file, symlink or submodule in the repo",
|
||||
"name": "dir",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The name of the commit/branch/tag. Default the repository’s default branch (usually master)",
|
||||
"name": "ref",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/ContentsResponse"
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/notFound"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/releases": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
|
Loading…
Reference in New Issue