forked from Gitlink/gitea_hat
新增:标签分页以及最后一次commit信息
This commit is contained in:
parent
72f4095786
commit
317f9691f6
|
@ -0,0 +1,41 @@
|
||||||
|
package convert
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/repo"
|
||||||
|
gitea_convert "code.gitea.io/gitea/modules/convert"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ToTag(repo *repo.Repository, gitRepo *git.Repository, t *git.Tag) (tag *api.Tag, err error) {
|
||||||
|
tagCommit, err := ToTagCommit(repo, gitRepo, t)
|
||||||
|
if err != nil {
|
||||||
|
return &api.Tag{}, err
|
||||||
|
}
|
||||||
|
return &api.Tag{
|
||||||
|
Name: t.Name,
|
||||||
|
Message: strings.TrimSpace(t.Message),
|
||||||
|
ID: t.ID.String(),
|
||||||
|
Commit: tagCommit,
|
||||||
|
Tagger: gitea_convert.ToCommitUser(t.Tagger),
|
||||||
|
ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
|
||||||
|
TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToTagCommit(repo *repo.Repository, gitRepo *git.Repository, t *git.Tag) (result *api.TagCommit, err error) {
|
||||||
|
commit, err := t.Commit(gitRepo)
|
||||||
|
if err != nil {
|
||||||
|
return &api.TagCommit{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.TagCommit{
|
||||||
|
CommitMeta: gitea_convert.ToCommitMeta(repo, t),
|
||||||
|
Committer: gitea_convert.ToCommitUser(commit.Committer),
|
||||||
|
Author: gitea_convert.ToCommitUser(commit.Author),
|
||||||
|
Message: commit.CommitMessage,
|
||||||
|
}, nil
|
||||||
|
}
|
|
@ -1,5 +1,26 @@
|
||||||
package structs
|
package structs
|
||||||
|
|
||||||
|
import (
|
||||||
|
gitea_api "code.gitea.io/gitea/modules/structs"
|
||||||
|
)
|
||||||
|
|
||||||
type BranchNameSet struct {
|
type BranchNameSet struct {
|
||||||
BranchName []*string `json:"branch_name"`
|
BranchName []*string `json:"branch_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
Commit *TagCommit `json:"commit"`
|
||||||
|
ZipballURL string `json:"zipball_url"`
|
||||||
|
TarballURL string `json:"tarball_url"`
|
||||||
|
Tagger *gitea_api.CommitUser `json:"tagger"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TagCommit struct {
|
||||||
|
*gitea_api.CommitMeta
|
||||||
|
Committer *gitea_api.CommitUser `json:"committer"`
|
||||||
|
Author *gitea_api.CommitUser `json:"author"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
|
@ -61,6 +61,9 @@ func Routers() *web.Route {
|
||||||
m.Group("/branches", func() {
|
m.Group("/branches", func() {
|
||||||
m.Get("/branches_slice", context.ReferencesGitRepo(), repo.ListBranchesSlice)
|
m.Get("/branches_slice", context.ReferencesGitRepo(), repo.ListBranchesSlice)
|
||||||
}, reqRepoReader(unit_model.TypeCode))
|
}, reqRepoReader(unit_model.TypeCode))
|
||||||
|
m.Group("/tags", func() {
|
||||||
|
m.Get("", repo.ListTags)
|
||||||
|
}, reqRepoReader(unit_model.TypeCode), context.ReferencesGitRepo(true))
|
||||||
m.Group("/wikies", func() {
|
m.Group("/wikies", func() {
|
||||||
m.Combo("").Get(repo.ListWikiPages).
|
m.Combo("").Get(repo.ListWikiPages).
|
||||||
Post(bind(hat_api.WikiOption{}), repo.CreateWiki)
|
Post(bind(hat_api.WikiOption{}), repo.CreateWiki)
|
||||||
|
|
|
@ -1,13 +1,49 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
|
"code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/convert"
|
||||||
|
"code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func ListTags(ctx *context.APIContext) {
|
||||||
|
listOpts := utils.GetListOptions(ctx)
|
||||||
|
|
||||||
|
tags, total, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "GetTags", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
apiTags := make([]*structs.Tag, len(tags))
|
||||||
|
for i := range tags {
|
||||||
|
convertTag, err := convert.ToTag(ctx.Repo.Repository, ctx.Repo.GitRepo, tags[i])
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "convert.ToTag", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
apiTags[i] = convertTag
|
||||||
|
}
|
||||||
|
|
||||||
|
pageCount := int(math.Ceil(float64(total) / float64(listOpts.PageSize)))
|
||||||
|
ctx.RespHeader().Set("X-Page", strconv.Itoa(listOpts.Page))
|
||||||
|
ctx.RespHeader().Set("X-PerPage", strconv.Itoa(listOpts.PageSize))
|
||||||
|
ctx.RespHeader().Set("X-Total", strconv.Itoa(total))
|
||||||
|
ctx.RespHeader().Set("X-PageCount", strconv.Itoa(pageCount))
|
||||||
|
ctx.RespHeader().Set("X-HasMore", strconv.FormatBool(listOpts.Page < pageCount))
|
||||||
|
|
||||||
|
ctx.SetLinkHeader(total, listOpts.PageSize)
|
||||||
|
ctx.SetTotalCountHeader(int64(total))
|
||||||
|
ctx.JSON(http.StatusOK, &apiTags)
|
||||||
|
}
|
||||||
|
|
||||||
func BranchNameSet(ctx *context.APIContext) {
|
func BranchNameSet(ctx *context.APIContext) {
|
||||||
|
|
||||||
searchName := ctx.Params("name")
|
searchName := ctx.Params("name")
|
||||||
|
|
Loading…
Reference in New Issue