forked from Gitlink/gitea-1120-rc1
Merge pull request '添加tags/releases接口' (#24) from wonderful/gitea-1120-rc1:develop_w into develop
This commit is contained in:
commit
04f3e061cb
|
@ -30,10 +30,10 @@ func ToEmail(email *models.EmailAddress) *api.Email {
|
|||
}
|
||||
}
|
||||
|
||||
type BranchKind int
|
||||
type BranchKind int
|
||||
|
||||
const (
|
||||
|
||||
None BranchKind = iota
|
||||
None BranchKind = iota
|
||||
DefaultBranch
|
||||
ProtectedBranch
|
||||
OtherBranch
|
||||
|
@ -41,7 +41,7 @@ const (
|
|||
|
||||
// ToBranch convert a git.Commit and git.Branch to an api.Branch
|
||||
func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *models.User, isRepoAdmin bool) (*api.Branch, error) {
|
||||
|
||||
|
||||
var branchKind BranchKind
|
||||
if bp == nil {
|
||||
var hasPerm bool
|
||||
|
@ -52,15 +52,15 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
if b.Name == repo.DefaultBranch{
|
||||
if b.Name == repo.DefaultBranch {
|
||||
branchKind = DefaultBranch
|
||||
}else{
|
||||
} else {
|
||||
branchKind = OtherBranch
|
||||
}
|
||||
|
||||
return &api.Branch{
|
||||
Name: b.Name,
|
||||
CommitID: c.ID.String(), //add configure
|
||||
CommitID: c.ID.String(), //add configure
|
||||
Commit: ToCommit(repo, c),
|
||||
Protected: false,
|
||||
RequiredApprovals: 0,
|
||||
|
@ -69,26 +69,26 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
|
|||
UserCanPush: hasPerm,
|
||||
UserCanMerge: hasPerm,
|
||||
CommitTime: c.Author.When.Format(time.RFC3339),
|
||||
DefaultBranch: repo.DefaultBranch,
|
||||
DefaultBranch: repo.DefaultBranch,
|
||||
BranchKind: int(branchKind),
|
||||
}, nil
|
||||
}
|
||||
if b.Name == repo.DefaultBranch{
|
||||
if b.Name == repo.DefaultBranch {
|
||||
branchKind = DefaultBranch
|
||||
}else{
|
||||
} else {
|
||||
branchKind = ProtectedBranch
|
||||
}
|
||||
|
||||
branch := &api.Branch{
|
||||
Name: b.Name,
|
||||
CommitID: c.ID.String(), // add configure
|
||||
CommitID: c.ID.String(), // add configure
|
||||
Commit: ToCommit(repo, c),
|
||||
Protected: true,
|
||||
RequiredApprovals: bp.RequiredApprovals,
|
||||
EnableStatusCheck: bp.EnableStatusCheck,
|
||||
StatusCheckContexts: bp.StatusCheckContexts,
|
||||
CommitTime: c.Author.When.Format(time.RFC3339),
|
||||
DefaultBranch: repo.DefaultBranch,
|
||||
DefaultBranch: repo.DefaultBranch,
|
||||
BranchKind: int(branchKind),
|
||||
}
|
||||
|
||||
|
@ -168,6 +168,19 @@ func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
|
|||
}
|
||||
}
|
||||
|
||||
func ToTagReleases(repo *models.Repository, t *git.Tag, release *models.Release) *api.TagReleases {
|
||||
release.Publisher, _ = models.GetUserByID(release.PublisherID)
|
||||
return &api.TagReleases{
|
||||
Name: t.Name,
|
||||
ID: t.ID.String(),
|
||||
Commit: ToCommitMeta(repo, t),
|
||||
Commiter: ToCommitUserFolk(release.Publisher),
|
||||
ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
|
||||
TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
|
||||
CommitTime: release.CreatedUnix.AsTime().String(),
|
||||
}
|
||||
}
|
||||
|
||||
// ToCommit convert a git.Commit to api.PayloadCommit
|
||||
func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
|
||||
authorUsername := ""
|
||||
|
@ -453,6 +466,16 @@ func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
|
|||
}
|
||||
}
|
||||
|
||||
func ToCommitUserFolk(user *models.User) *api.CommitUser {
|
||||
return &api.CommitUser{
|
||||
Identity: api.Identity{
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
},
|
||||
Date: user.CreatedUnix.AsTime().String(),
|
||||
}
|
||||
}
|
||||
|
||||
// ToTopicResponse convert from models.Topic to api.TopicResponse
|
||||
func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
|
||||
return &api.TopicResponse{
|
||||
|
|
|
@ -13,6 +13,22 @@ type Tag struct {
|
|||
TarballURL string `json:"tarball_url"`
|
||||
}
|
||||
|
||||
type TagReleases struct {
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
Commit *CommitMeta `json:"commit"`
|
||||
ZipballURL string `json:"zipball_url"`
|
||||
TarballURL string `json:"tarball_url"`
|
||||
Commiter *CommitUser `json:"commiter"`
|
||||
CommitTime string `json:"commit_time"`
|
||||
}
|
||||
|
||||
type SortTagReleases []*TagReleases
|
||||
|
||||
func (s SortTagReleases) Len() int { return len(s) }
|
||||
func (s SortTagReleases) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s SortTagReleases) Less(i, j int) bool { return s[i].CommitTime > s[j].CommitTime }
|
||||
|
||||
// AnnotatedTag represents an annotated tag
|
||||
type AnnotatedTag struct {
|
||||
Tag string `json:"tag"`
|
||||
|
|
|
@ -6,7 +6,9 @@ package repo
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
@ -59,6 +61,57 @@ func ListTags(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, &apiTags)
|
||||
}
|
||||
|
||||
func ListTagsFolk(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/tags/releases repository repoListTagsReleases
|
||||
// ---
|
||||
// summary: List a repository's tags
|
||||
// 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: page
|
||||
// in: query
|
||||
// description: page number of results to return (1-based)
|
||||
// type: integer
|
||||
// - name: limit
|
||||
// in: query
|
||||
// description: page size of results, default maximum page size is 50
|
||||
// type: integer
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/TagList"
|
||||
|
||||
listOpts := utils.GetListOptions(ctx)
|
||||
|
||||
tags, err := ctx.Repo.GitRepo.GetTagInfos(listOpts.Page, listOpts.PageSize)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetTags", err)
|
||||
return
|
||||
}
|
||||
|
||||
apiTags := make([]*api.TagReleases, len(tags))
|
||||
for i := range tags {
|
||||
// commit, err := tags[i].Commit()
|
||||
|
||||
release, err := models.GetRelease(ctx.Repo.Repository.ID, tags[i].Name)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusBadRequest, "GetRelease", err)
|
||||
}
|
||||
apiTags[i] = convert.ToTagReleases(ctx.Repo.Repository, tags[i], release)
|
||||
}
|
||||
sort.Sort(api.SortTagReleases(apiTags))
|
||||
ctx.JSON(http.StatusOK, apiTags)
|
||||
}
|
||||
|
||||
// GetTag get the tag of a repository.
|
||||
func GetTag(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/git/tags/{sha} repository GetTag
|
||||
|
|
Loading…
Reference in New Issue