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 (
|
const (
|
||||||
|
None BranchKind = iota
|
||||||
None BranchKind = iota
|
|
||||||
DefaultBranch
|
DefaultBranch
|
||||||
ProtectedBranch
|
ProtectedBranch
|
||||||
OtherBranch
|
OtherBranch
|
||||||
|
@ -41,7 +41,7 @@ const (
|
||||||
|
|
||||||
// ToBranch convert a git.Commit and git.Branch to an api.Branch
|
// 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) {
|
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
|
var branchKind BranchKind
|
||||||
if bp == nil {
|
if bp == nil {
|
||||||
var hasPerm bool
|
var hasPerm bool
|
||||||
|
@ -52,15 +52,15 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if b.Name == repo.DefaultBranch{
|
if b.Name == repo.DefaultBranch {
|
||||||
branchKind = DefaultBranch
|
branchKind = DefaultBranch
|
||||||
}else{
|
} else {
|
||||||
branchKind = OtherBranch
|
branchKind = OtherBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
return &api.Branch{
|
return &api.Branch{
|
||||||
Name: b.Name,
|
Name: b.Name,
|
||||||
CommitID: c.ID.String(), //add configure
|
CommitID: c.ID.String(), //add configure
|
||||||
Commit: ToCommit(repo, c),
|
Commit: ToCommit(repo, c),
|
||||||
Protected: false,
|
Protected: false,
|
||||||
RequiredApprovals: 0,
|
RequiredApprovals: 0,
|
||||||
|
@ -69,26 +69,26 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.
|
||||||
UserCanPush: hasPerm,
|
UserCanPush: hasPerm,
|
||||||
UserCanMerge: hasPerm,
|
UserCanMerge: hasPerm,
|
||||||
CommitTime: c.Author.When.Format(time.RFC3339),
|
CommitTime: c.Author.When.Format(time.RFC3339),
|
||||||
DefaultBranch: repo.DefaultBranch,
|
DefaultBranch: repo.DefaultBranch,
|
||||||
BranchKind: int(branchKind),
|
BranchKind: int(branchKind),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
if b.Name == repo.DefaultBranch{
|
if b.Name == repo.DefaultBranch {
|
||||||
branchKind = DefaultBranch
|
branchKind = DefaultBranch
|
||||||
}else{
|
} else {
|
||||||
branchKind = ProtectedBranch
|
branchKind = ProtectedBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
branch := &api.Branch{
|
branch := &api.Branch{
|
||||||
Name: b.Name,
|
Name: b.Name,
|
||||||
CommitID: c.ID.String(), // add configure
|
CommitID: c.ID.String(), // add configure
|
||||||
Commit: ToCommit(repo, c),
|
Commit: ToCommit(repo, c),
|
||||||
Protected: true,
|
Protected: true,
|
||||||
RequiredApprovals: bp.RequiredApprovals,
|
RequiredApprovals: bp.RequiredApprovals,
|
||||||
EnableStatusCheck: bp.EnableStatusCheck,
|
EnableStatusCheck: bp.EnableStatusCheck,
|
||||||
StatusCheckContexts: bp.StatusCheckContexts,
|
StatusCheckContexts: bp.StatusCheckContexts,
|
||||||
CommitTime: c.Author.When.Format(time.RFC3339),
|
CommitTime: c.Author.When.Format(time.RFC3339),
|
||||||
DefaultBranch: repo.DefaultBranch,
|
DefaultBranch: repo.DefaultBranch,
|
||||||
BranchKind: int(branchKind),
|
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
|
// ToCommit convert a git.Commit to api.PayloadCommit
|
||||||
func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
|
func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
|
||||||
authorUsername := ""
|
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
|
// ToTopicResponse convert from models.Topic to api.TopicResponse
|
||||||
func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
|
func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
|
||||||
return &api.TopicResponse{
|
return &api.TopicResponse{
|
||||||
|
|
|
@ -13,6 +13,22 @@ type Tag struct {
|
||||||
TarballURL string `json:"tarball_url"`
|
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
|
// AnnotatedTag represents an annotated tag
|
||||||
type AnnotatedTag struct {
|
type AnnotatedTag struct {
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
|
|
|
@ -6,7 +6,9 @@ package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
@ -59,6 +61,57 @@ func ListTags(ctx *context.APIContext) {
|
||||||
ctx.JSON(http.StatusOK, &apiTags)
|
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.
|
// GetTag get the tag of a repository.
|
||||||
func GetTag(ctx *context.APIContext) {
|
func GetTag(ctx *context.APIContext) {
|
||||||
// swagger:operation GET /repos/{owner}/{repo}/git/tags/{sha} repository GetTag
|
// swagger:operation GET /repos/{owner}/{repo}/git/tags/{sha} repository GetTag
|
||||||
|
|
Loading…
Reference in New Issue