fix:merge from wmh_develop
This commit is contained in:
commit
9d53ff793b
|
@ -278,7 +278,28 @@ func (ctx *APIContext) FileNameError(objs ...interface{}){
|
|||
"errors": errors,
|
||||
})
|
||||
}
|
||||
func (ctx *APIContext) SameFileNameError(objs ...interface{}){
|
||||
var message = "Same name exists"
|
||||
var errors []string
|
||||
|
||||
for _, obj := range objs {
|
||||
// Ignore nil
|
||||
if obj == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err, ok := obj.(error); ok {
|
||||
errors = append(errors, err.Error())
|
||||
} else {
|
||||
message = obj.(string)
|
||||
}
|
||||
}
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"message": message,
|
||||
"documentation_url": setting.API.SwaggerURL,
|
||||
"errors": errors,
|
||||
})
|
||||
}
|
||||
|
||||
func (ctx *APIContext) FileExistError(objs ...interface{}){
|
||||
var message = "file does not exist"
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/*
|
||||
* @Date: 2021-08-06 14:28:55
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-08-06 16:33:20
|
||||
* @LastEditTime: 2021-08-19 18:00:34
|
||||
* @FilePath: /gitea-1120-rc1/modules/structs/wiki.go
|
||||
*/
|
||||
package structs
|
||||
|
||||
type WikiesResponse struct {
|
||||
When int64 `json:"when"`
|
||||
type WikiesResponse struct {
|
||||
WikiMeta
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
}
|
||||
|
||||
type WikiMeta struct {
|
||||
Name string `json:"name"`
|
||||
Commit WikiCommit `json:"commit"`
|
||||
Name string `json:"name"`
|
||||
Commit WikiCommit `json:"commit"`
|
||||
FirstCommit WikiCommit `json:"-"`
|
||||
//WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ type WikiCommit struct {
|
|||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Author WikiUser `json:"author"`
|
||||
Commiter WikiUser `json:"commiter"`
|
||||
Commiter WikiUser `json:"-"`
|
||||
}
|
||||
|
||||
type WikiUser struct {
|
||||
|
@ -32,13 +32,11 @@ type WikiUser struct {
|
|||
}
|
||||
|
||||
type WikiResponse struct {
|
||||
RepoName string `json:"repo_name"`
|
||||
OwnerName string `json:"owner_name"`
|
||||
WikiMeta
|
||||
CommitCounts int64 `json:"commit_counts"`
|
||||
MdContent string `json:"md_content"`
|
||||
SimpleContent string `json:"simple_content"`
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
CommitCounts int64 `json:"commit_counts"`
|
||||
MdContent string `json:"md_content"`
|
||||
SimpleContent string `json:"simple_content"`
|
||||
WikiCloneLink CloneLink `json:"wiki_clone_link"`
|
||||
}
|
||||
|
||||
type WikiOption struct {
|
||||
|
@ -47,6 +45,6 @@ type WikiOption struct {
|
|||
CommitMessage string `json:"commit_message"`
|
||||
}
|
||||
type CloneLink struct {
|
||||
SSH string `json:"ssh"`
|
||||
HTTPS string `json:"https"`
|
||||
SSH string `json:"ssh"`
|
||||
HTTPS string `json:"https"`
|
||||
}
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
/*
|
||||
* @Date: 2021-08-06 09:53:43
|
||||
* @LastEditors: viletyy
|
||||
* @LastEditTime: 2021-08-06 16:55:28
|
||||
* @LastEditTime: 2021-08-19 17:58:21
|
||||
* @FilePath: /gitea-1120-rc1/modules/wikies/wiki.go
|
||||
*/
|
||||
package wikies
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/sync"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"fmt"
|
||||
"github.com/unknwon/com"
|
||||
|
||||
//"github.com/unknwon/com"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
//"code.gitea.io/gitea/modules/wikies"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -25,14 +28,11 @@ import (
|
|||
wiki_service "code.gitea.io/gitea/services/wiki"
|
||||
)
|
||||
|
||||
|
||||
|
||||
var (
|
||||
reservedWikiNames = []string{"_pages", "_new", "_edit", "raw"}
|
||||
wikiWorkingPool = sync.NewExclusivePool()
|
||||
)
|
||||
|
||||
|
||||
func nameAllowed(name string) error {
|
||||
if util.IsStringInSlice(name, reservedWikiNames) {
|
||||
return models.ErrWikiReservedName{
|
||||
|
@ -54,7 +54,6 @@ func InitWiki(repo *models.Repository) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
func FindWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit, error) {
|
||||
wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
|
||||
if err != nil {
|
||||
|
@ -113,14 +112,12 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) []byte {
|
|||
return content
|
||||
}
|
||||
|
||||
|
||||
func CreateWikiPage(doer *models.User, repo *models.Repository, wikiName, content, message string) error {
|
||||
return updateWikiPage(doer, repo, "", wikiName, content, message, true)
|
||||
}
|
||||
|
||||
|
||||
func EditWikiPage(doer *models.User, repo *models.Repository, oldWikiName,newWikiName, content, message string) error {
|
||||
return updateWikiPage(doer, repo, oldWikiName , newWikiName, content, message, false)
|
||||
func EditWikiPage(doer *models.User, repo *models.Repository, oldWikiName, newWikiName, content, message string) error {
|
||||
return updateWikiPage(doer, repo, oldWikiName, newWikiName, content, message, false)
|
||||
}
|
||||
func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) {
|
||||
if err = nameAllowed(newWikiName); err != nil {
|
||||
|
@ -261,7 +258,6 @@ func updateWikiPage(doer *models.User, repo *models.Repository, oldWikiName, new
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
// NewWikiPost response for wiki create request
|
||||
func NewWikiPost(ctx *context.APIContext, form api.WikiOption) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
|
||||
|
@ -280,15 +276,12 @@ func NewWikiPost(ctx *context.APIContext, form api.WikiOption) {
|
|||
|
||||
if models.IsErrWikiReservedName(err) {
|
||||
ctx.Data["Err_Title"] = true
|
||||
fmt.Println("err1 ================== ",err)
|
||||
//ctx.RenderWithErr(ctx.Tr("repo.wiki.reserved_page", wikiName), tplWikiNew, &form)
|
||||
} else if models.IsErrWikiAlreadyExist(err) {
|
||||
ctx.Data["Err_Title"] = true
|
||||
fmt.Println("err2 ====================", err)
|
||||
//ctx.RenderWithErr(ctx.Tr("repo.wiki.page_already_exists"), tplWikiNew, &form)
|
||||
} else {
|
||||
//ctx.ServerError("AddWikiPage", err)
|
||||
fmt.Println("err3 =======",err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -302,7 +295,7 @@ func EditWikiPost(ctx *context.APIContext, form api.WikiOption) {
|
|||
oldWikiName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
|
||||
newWikiName := wiki_service.NormalizeWikiName(form.Name)
|
||||
|
||||
newWikiName, _= url.QueryUnescape(newWikiName)
|
||||
//newWikiName, _= url.QueryUnescape(newWikiName)
|
||||
|
||||
if len(form.CommitMessage) == 0 {
|
||||
form.CommitMessage = ctx.Tr("repo.editor.update", form.Name)
|
||||
|
|
|
@ -2,15 +2,15 @@ package repo
|
|||
|
||||
//
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/wikies"
|
||||
wiki_service "code.gitea.io/gitea/services/wiki"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
)
|
||||
|
||||
func WikiList(ctx *context.APIContext) {
|
||||
|
@ -59,7 +59,8 @@ func WikiList(ctx *context.APIContext) {
|
|||
if !entry.IsRegular() {
|
||||
continue
|
||||
}
|
||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
//c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
lastCommit, firstCommit, err := wikiRepo.GetFirstAndLastCommitByPath("master", entry.Name())
|
||||
if err != nil {
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
|
@ -79,7 +80,6 @@ func WikiList(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
wikiesList = append(wikiesList, api.WikiesResponse{
|
||||
When: c.Author.When.Unix(),
|
||||
WikiCloneLink: api.CloneLink{
|
||||
HTTPS: wikiCloneLink.HTTPS,
|
||||
SSH: wikiCloneLink.SSH,
|
||||
|
@ -88,17 +88,31 @@ func WikiList(ctx *context.APIContext) {
|
|||
Name: wikiName,
|
||||
Commit: api.WikiCommit{
|
||||
Author: api.WikiUser{
|
||||
Name: c.Author.Name,
|
||||
Email: c.Author.Email,
|
||||
When: c.Author.When.Unix(),
|
||||
Name: lastCommit.Author.Name,
|
||||
Email: lastCommit.Author.Email,
|
||||
When: lastCommit.Author.When.Unix(),
|
||||
},
|
||||
Commiter: api.WikiUser{
|
||||
Name: c.Committer.Name,
|
||||
Email: c.Committer.Email,
|
||||
When: c.Committer.When.Unix(),
|
||||
Name: lastCommit.Committer.Name,
|
||||
Email: lastCommit.Committer.Email,
|
||||
When: lastCommit.Author.When.Unix(),
|
||||
},
|
||||
ID: c.ID.String(),
|
||||
Message: c.Message(),
|
||||
ID: lastCommit.ID.String(),
|
||||
Message: lastCommit.Message(),
|
||||
},
|
||||
FirstCommit: api.WikiCommit{
|
||||
Author: api.WikiUser{
|
||||
Name: firstCommit.Author.Name,
|
||||
Email: firstCommit.Author.Email,
|
||||
When: firstCommit.Author.When.Unix(),
|
||||
},
|
||||
Commiter: api.WikiUser{
|
||||
Name: firstCommit.Committer.Name,
|
||||
Email: firstCommit.Committer.Email,
|
||||
When: firstCommit.Author.When.Unix(),
|
||||
},
|
||||
ID: firstCommit.ID.String(),
|
||||
Message: firstCommit.Message(),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -106,7 +120,7 @@ func WikiList(ctx *context.APIContext) {
|
|||
|
||||
//根据创建时间,按最新的时间排序
|
||||
sort.Slice(wikiesList, func(i, j int) bool {
|
||||
return wikiesList[i].Commit.Commiter.When < wikiesList[j].Commit.Commiter.When
|
||||
return wikiesList[i].FirstCommit.Author.When > wikiesList[j].FirstCommit.Author.When
|
||||
})
|
||||
ctx.JSON(http.StatusOK, wikiesList)
|
||||
}
|
||||
|
@ -223,8 +237,6 @@ func CreateWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
ctx.FileNameError()
|
||||
return
|
||||
}
|
||||
OwnerName := ctx.Repo.Repository.OwnerName
|
||||
RepoName := ctx.Repo.Repository.Name
|
||||
repository := ctx.Repo.Repository
|
||||
wikiCloneLink := repository.CloneWikiLink()
|
||||
wikies.NewWikiPost(ctx, form)
|
||||
|
@ -240,8 +252,6 @@ func CreateWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
}
|
||||
}
|
||||
wiki := api.WikiResponse{
|
||||
OwnerName: OwnerName,
|
||||
RepoName: RepoName,
|
||||
WikiCloneLink: api.CloneLink{
|
||||
HTTPS: wikiCloneLink.HTTPS,
|
||||
SSH: wikiCloneLink.SSH,
|
||||
|
@ -306,26 +316,31 @@ func EditWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
ctx.FileNameError()
|
||||
return
|
||||
}
|
||||
|
||||
wikies.EditWikiPost(ctx, form)
|
||||
|
||||
OwnerName := ctx.Repo.Repository.OwnerName
|
||||
RepoName := ctx.Repo.Repository.Name
|
||||
|
||||
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||
data, entry, pageFilename, _ := wikies.WikiContentsByName(ctx, commit, form.Name) //
|
||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||
PageContent := markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
|
||||
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
||||
|
||||
//Does the same name exist
|
||||
//entries, err := commit.ListEntries()
|
||||
//for _, entry := range entries {
|
||||
// wikiname, _ := wiki_service.FilenameToName(entry.Name())
|
||||
//
|
||||
// if wikiname == newWikiName{
|
||||
// ctx.SameFileNameError()
|
||||
// return
|
||||
// }
|
||||
//}
|
||||
wikies.EditWikiPost(ctx, form)
|
||||
data, entry, pageFilename, _ := wikies.WikiContentsByName(ctx, commit, form.Name)
|
||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||
if err != nil {
|
||||
if models.IsErrWikiInvalidFileName(err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||
PageContent := markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
|
||||
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
||||
|
||||
wiki := api.WikiResponse{
|
||||
OwnerName: OwnerName,
|
||||
RepoName: RepoName,
|
||||
WikiMeta: api.WikiMeta{
|
||||
Name: form.Name,
|
||||
Commit: api.WikiCommit{
|
||||
|
|
|
@ -76,6 +76,7 @@ func CheckFile(filename string) error {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// InitWiki initializes a wiki for repository,
|
||||
// it does nothing when repository already has wiki.
|
||||
func InitWiki(repo *models.Repository) error {
|
||||
|
|
|
@ -15506,9 +15506,6 @@
|
|||
"WikiCommit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"_": {
|
||||
"$ref": "#/definitions/WikiUser"
|
||||
},
|
||||
"author": {
|
||||
"$ref": "#/definitions/WikiUser"
|
||||
},
|
||||
|
@ -15560,14 +15557,6 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"owner_name": {
|
||||
"type": "string",
|
||||
"x-go-name": "OwnerName"
|
||||
},
|
||||
"repo_name": {
|
||||
"type": "string",
|
||||
"x-go-name": "RepoName"
|
||||
},
|
||||
"simple_content": {
|
||||
"type": "string",
|
||||
"x-go-name": "SimpleContent"
|
||||
|
@ -15607,11 +15596,6 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
},
|
||||
"when": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "When"
|
||||
},
|
||||
"wiki_clone_link": {
|
||||
"$ref": "#/definitions/CloneLink"
|
||||
}
|
||||
|
@ -16411,4 +16395,4 @@
|
|||
"TOTPHeader": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue