forked from Gitlink/gitea-1120-rc1
fix:first wikies
This commit is contained in:
parent
b228c9f602
commit
3072fc7e4e
|
@ -278,7 +278,28 @@ func (ctx *APIContext) FileNameError(objs ...interface{}){
|
||||||
"errors": errors,
|
"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{}){
|
func (ctx *APIContext) FileExistError(objs ...interface{}){
|
||||||
var message = "file does not exist"
|
var message = "file does not exist"
|
||||||
|
|
|
@ -206,6 +206,20 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
|
||||||
return commits.Front().Value.(*Commit), nil
|
return commits.Front().Value.(*Commit), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) GetFirstAndLastCommitByPath(revision, relpath string) (*Commit,*Commit, error) {
|
||||||
|
stdout, err := NewCommand("log", revision, prettyLogFormat, "--", relpath).RunInDirBytes(repo.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil,nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
commits, err := repo.parsePrettyFormatLogToList(stdout)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil,err
|
||||||
|
}
|
||||||
|
return commits.Front().Value.(*Commit),commits.Back().Value.(*Commit), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// CommitsRangeSize the default commits range size
|
// CommitsRangeSize the default commits range size
|
||||||
var CommitsRangeSize = 50
|
var CommitsRangeSize = 50
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ type WikiCommit struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Author WikiUser `json:"author"`
|
Author WikiUser `json:"author"`
|
||||||
Commiter WikiUser `json:"-"`
|
Commiter WikiUser `json:"commiter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WikiUser struct {
|
type WikiUser struct {
|
||||||
|
|
|
@ -59,7 +59,8 @@ func WikiList(ctx *context.APIContext) {
|
||||||
if !entry.IsRegular() {
|
if !entry.IsRegular() {
|
||||||
continue
|
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 err != nil {
|
||||||
if wikiRepo != nil {
|
if wikiRepo != nil {
|
||||||
wikiRepo.Close()
|
wikiRepo.Close()
|
||||||
|
@ -89,17 +90,17 @@ func WikiList(ctx *context.APIContext) {
|
||||||
Name: wikiName,
|
Name: wikiName,
|
||||||
Commit: api.WikiCommit{
|
Commit: api.WikiCommit{
|
||||||
Author: api.WikiUser{
|
Author: api.WikiUser{
|
||||||
Name: c.Author.Name,
|
Name: firstCommit.Author.Name,
|
||||||
Email: c.Author.Email,
|
Email: firstCommit.Author.Email,
|
||||||
When: c.Author.When.Unix(),
|
When: firstCommit.Author.When.Unix(),
|
||||||
},
|
},
|
||||||
Commiter: api.WikiUser{
|
Commiter: api.WikiUser{
|
||||||
Name: c.Committer.Name,
|
Name: lastCommit.Committer.Name,
|
||||||
Email: c.Committer.Email,
|
Email: lastCommit.Committer.Email,
|
||||||
When: c.Author.When.Unix(),
|
When: lastCommit.Author.When.Unix(),
|
||||||
},
|
},
|
||||||
ID: c.ID.String(),
|
ID: lastCommit.ID.String(),
|
||||||
Message: c.Message(),
|
Message: lastCommit.Message(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -107,7 +108,7 @@ func WikiList(ctx *context.APIContext) {
|
||||||
|
|
||||||
//根据创建时间,按最新的时间排序
|
//根据创建时间,按最新的时间排序
|
||||||
sort.Slice(wikiesList, func(i, j int) bool {
|
sort.Slice(wikiesList, func(i, j int) bool {
|
||||||
return wikiesList[i].Commit.Commiter.When < wikiesList[j].Commit.Commiter.When
|
return wikiesList[i].Commit.Author.When > wikiesList[j].Commit.Author.When
|
||||||
})
|
})
|
||||||
ctx.JSON(http.StatusOK, wikiesList)
|
ctx.JSON(http.StatusOK, wikiesList)
|
||||||
}
|
}
|
||||||
|
@ -309,23 +310,32 @@ func EditWiki(ctx *context.APIContext, form api.WikiOption) {
|
||||||
ctx.FileNameError()
|
ctx.FileNameError()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||||
|
|
||||||
|
//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)
|
wikies.EditWikiPost(ctx, form)
|
||||||
|
|
||||||
OwnerName := ctx.Repo.Repository.OwnerName
|
OwnerName := ctx.Repo.Repository.OwnerName
|
||||||
RepoName := ctx.Repo.Repository.Name
|
RepoName := ctx.Repo.Repository.Name
|
||||||
|
data, entry, pageFilename, _ := wikies.WikiContentsByName(ctx, commit, form.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)
|
|
||||||
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
c, err := wikiRepo.GetCommitByPath(entry.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrWikiInvalidFileName(err) {
|
if models.IsErrWikiInvalidFileName(err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||||
|
PageContent := markdown.RenderWiki(data, ctx.Repo.RepoLink, metas)
|
||||||
|
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
||||||
|
|
||||||
wiki := api.WikiResponse{
|
wiki := api.WikiResponse{
|
||||||
OwnerName: OwnerName,
|
OwnerName: OwnerName,
|
||||||
RepoName: RepoName,
|
RepoName: RepoName,
|
||||||
|
|
|
@ -76,6 +76,7 @@ func CheckFile(filename string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// InitWiki initializes a wiki for repository,
|
// InitWiki initializes a wiki for repository,
|
||||||
// it does nothing when repository already has wiki.
|
// it does nothing when repository already has wiki.
|
||||||
func InitWiki(repo *models.Repository) error {
|
func InitWiki(repo *models.Repository) error {
|
||||||
|
|
Loading…
Reference in New Issue