add:GetWiki
This commit is contained in:
parent
44cfd79573
commit
653eb66ff5
|
@ -785,11 +785,11 @@ func Routes() *web.Route {
|
|||
m.Group("/wikies", func() {
|
||||
m.Combo("").Get(repo.ListWikiPages).
|
||||
Post(bind(api.WikiOption{}), repo.CreateWiki)
|
||||
// m.Group("/:page", func() {
|
||||
// m.Combo("").Get(repo.GetWiki).
|
||||
// Patch(bind(api.WikiOption{}), repo.EditWiki).
|
||||
// Delete(repo.DeleteWiki)
|
||||
// })
|
||||
m.Group("/{page}", func() {
|
||||
m.Combo("").Get(repo.GetWiki).
|
||||
Patch(bind(api.WikiOption{}), repo.EditWiki).
|
||||
Delete(repo.DeleteWiki)
|
||||
})
|
||||
})
|
||||
m.Group("/tags", func() {
|
||||
m.Get("", repo.ListTags)
|
||||
|
|
|
@ -2,6 +2,10 @@ package repo
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
|
@ -9,9 +13,6 @@ import (
|
|||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
webWiki "code.gitea.io/gitea/routers/web/repo"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
wiki_service "code.gitea.io/gitea/services/wiki"
|
||||
)
|
||||
|
@ -226,3 +227,108 @@ func CreateWiki(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, wiki)
|
||||
|
||||
}
|
||||
|
||||
func GetWiki(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/wikies/{pagename} repository repoGetWiki
|
||||
// ---
|
||||
// summary: Get a Wiki
|
||||
// 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: pagename
|
||||
// in: path
|
||||
// description: name of the wikipage
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Wiki"
|
||||
|
||||
wikiRepo, commit, _ := webWiki.FindWikiRepoCommit(ctx.Context)
|
||||
|
||||
wikiCloneWiki := ctx.Repo.Repository.WikiCloneLink()
|
||||
|
||||
// pageName := wiki_service.NormalizeWikiName(ctx.Context.Params(":page"))
|
||||
pageName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
|
||||
if len(pageName) == 0 {
|
||||
pageName = "Home"
|
||||
}
|
||||
data, entry, pageFilename, noEntry := webWiki.WikiContentsByName(ctx.Context, commit, pageName)
|
||||
if noEntry {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
if entry == nil || ctx.Written() {
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
}
|
||||
}
|
||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||
|
||||
var rctx = &markup.RenderContext{
|
||||
URLPrefix: ctx.Repo.RepoLink,
|
||||
Metas: metas,
|
||||
IsWiki: true,
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
if err := markdown.Render(rctx, bytes.NewReader(data), &buf); err != nil {
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
}
|
||||
ctx.ServerError("Render", err)
|
||||
return
|
||||
}
|
||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
if err != nil {
|
||||
if models.IsErrWikiInvalidFileName(err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
||||
wiki := api.WikiResponse{
|
||||
WikiCloneLink: api.CloneLink{
|
||||
HTTPS: wikiCloneWiki.HTTPS,
|
||||
SSH: wikiCloneWiki.SSH,
|
||||
},
|
||||
WikiMeta: api.WikiMeta{
|
||||
Name: pageName,
|
||||
Commit: api.WikiCommit{
|
||||
Author: api.WikiUser{
|
||||
Name: c.Author.Name,
|
||||
Email: c.Author.Email,
|
||||
When: c.Author.When.Unix(),
|
||||
},
|
||||
Commiter: api.WikiUser{
|
||||
Name: c.Committer.Name,
|
||||
Email: c.Committer.Email,
|
||||
When: c.Author.When.Unix(),
|
||||
},
|
||||
ID: c.ID.String(),
|
||||
Message: c.Message(),
|
||||
},
|
||||
},
|
||||
CommitCounts: commitsCount,
|
||||
MdContent: string(data),
|
||||
SimpleContent: buf.String(),
|
||||
}
|
||||
ctx.JSON(http.StatusOK, wiki)
|
||||
}
|
||||
|
||||
func DeleteWiki(ctx *context.APIContext) {
|
||||
|
||||
}
|
||||
|
||||
func EditWiki(ctx *context.APIContext) {
|
||||
|
||||
}
|
||||
|
|
|
@ -50,10 +50,15 @@ type swaggerResponseBranchProtectionList struct {
|
|||
Body []api.BranchProtection `json:"body"`
|
||||
}
|
||||
|
||||
// Wiki
|
||||
// swagger:response Wiki
|
||||
type swaggerResponseWiki struct {
|
||||
// in:body
|
||||
Body api.WikiResponse `json:"body"`
|
||||
}
|
||||
|
||||
// WikiList
|
||||
// swagger:response WikiList
|
||||
type swaggerResponseWikiList struct {
|
||||
// in:body
|
||||
Body api.WikiesResponse `json:"body"`
|
||||
|
|
|
@ -9848,6 +9848,46 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/wikies/{pagename}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "Get a Wiki",
|
||||
"operationId": "repoGetWiki",
|
||||
"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": "name of the wikipage",
|
||||
"name": "pagename",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/Wiki"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{template_owner}/{template_repo}/generate": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
|
@ -12398,6 +12438,20 @@
|
|||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"CloneLink": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"https": {
|
||||
"type": "string",
|
||||
"x-go-name": "HTTPS"
|
||||
},
|
||||
"ssh": {
|
||||
"type": "string",
|
||||
"x-go-name": "SSH"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"CombinedStatus": {
|
||||
"description": "CombinedStatus holds the combined state of several statuses for a single commit",
|
||||
"type": "object",
|
||||
|
@ -17114,6 +17168,23 @@
|
|||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"WikiCommit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"author": {
|
||||
"$ref": "#/definitions/WikiUser"
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
"x-go-name": "ID"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"x-go-name": "Message"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"WikiOption": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -17131,6 +17202,70 @@
|
|||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"WikiResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"commit": {
|
||||
"$ref": "#/definitions/WikiCommit"
|
||||
},
|
||||
"commit_counts": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "CommitCounts"
|
||||
},
|
||||
"md_content": {
|
||||
"type": "string",
|
||||
"x-go-name": "MdContent"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"simple_content": {
|
||||
"type": "string",
|
||||
"x-go-name": "SimpleContent"
|
||||
},
|
||||
"wiki_clone_link": {
|
||||
"$ref": "#/definitions/CloneLink"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"WikiUser": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string",
|
||||
"x-go-name": "Email"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"when": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "When"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"WikiesResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"commit": {
|
||||
"$ref": "#/definitions/WikiCommit"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"wiki_clone_link": {
|
||||
"$ref": "#/definitions/CloneLink"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
|
@ -17806,6 +17941,18 @@
|
|||
"$ref": "#/definitions/WatchInfo"
|
||||
}
|
||||
},
|
||||
"Wiki": {
|
||||
"description": "Wiki",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/WikiResponse"
|
||||
}
|
||||
},
|
||||
"WikiList": {
|
||||
"description": "WikiList",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/WikiesResponse"
|
||||
}
|
||||
},
|
||||
"conflict": {
|
||||
"description": "APIConflict is a conflict empty response"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue