forked from Gitlink/gitea-1156
add:Content of the README.md of the repo
This commit is contained in:
parent
537056b48a
commit
6aeadbdb7d
|
@ -968,6 +968,7 @@ func Routes() *web.Route {
|
||||||
m.Group("/contents", func() {
|
m.Group("/contents", func() {
|
||||||
m.Get("", repo.GetContentsList)
|
m.Get("", repo.GetContentsList)
|
||||||
m.Get("/*", repo.GetContents)
|
m.Get("/*", repo.GetContents)
|
||||||
|
m.Get("/readme", repo.GetReadmeContents)
|
||||||
m.Group("/*", func() {
|
m.Group("/*", func() {
|
||||||
m.Post("", bind(api.CreateFileOptions{}), repo.CreateFile)
|
m.Post("", bind(api.CreateFileOptions{}), repo.CreateFile)
|
||||||
m.Put("", bind(api.UpdateFileOptions{}), repo.UpdateFile)
|
m.Put("", bind(api.UpdateFileOptions{}), repo.UpdateFile)
|
||||||
|
|
|
@ -596,3 +596,54 @@ func GetContentsList(ctx *context.APIContext) {
|
||||||
// same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface
|
// same as GetContents(), this function is here because swagger fails if path is empty in GetContents() interface
|
||||||
GetContents(ctx)
|
GetContents(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// ---
|
||||||
|
// summary: Gets the README.md's contents (if a file) of an entry in a repository ***
|
||||||
|
// 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: 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")
|
||||||
|
|
||||||
|
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, "README.md", 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,6 +3215,48 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/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}": {
|
"/repos/{owner}/{repo}/contents/{filepath}": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
|
|
Loading…
Reference in New Issue