对tags接口修改 #25

Merged
jasder merged 1 commits from wonderful/gitea-1120-rc1:develop_w into develop 2021-09-23 15:56:45 +08:00
7 changed files with 51 additions and 143 deletions

View File

@ -158,26 +158,29 @@ func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection {
}
// ToTag convert a git.Tag to an api.Tag
func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
return &api.Tag{
Name: t.Name,
ID: t.ID.String(),
Commit: ToCommitMeta(repo, t),
ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
}
}
// func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
// return &api.Tag{
// Name: t.Name,
// ID: t.ID.String(),
// Commit: ToCommitMeta(repo, t),
// ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
// TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
// }
// }
func ToTagReleases(repo *models.Repository, t *git.Tag, release *models.Release) *api.TagReleases {
func ToTag(repo *models.Repository, t *git.Tag, release *models.Release) *api.Tag {
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(),
commit, _ := t.Commit()
return &api.Tag{
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(),
CommitMessage: commit.CommitMessage,
}
}

View File

@ -6,24 +6,17 @@ package structs
// Tag represents a repository tag
type Tag struct {
Name string `json:"name"`
ID string `json:"id"`
Commit *CommitMeta `json:"commit"`
ZipballURL string `json:"zipball_url"`
TarballURL string `json:"tarball_url"`
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"`
CommitMessage string `json:"commit_message"`
// User *CommitUser `json:"user"`
}
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
type SortTagReleases []*Tag
func (s SortTagReleases) Len() int { return len(s) }
func (s SortTagReleases) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

View File

@ -808,7 +808,6 @@ func RegisterRoutes(m *macaron.Macaron) {
}, reqToken(), reqAdmin())
m.Group("/tags", func() {
m.Get("", repo.ListTags)
m.Get("/releases", repo.ListTagsFolk)
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys).

View File

@ -330,7 +330,7 @@ func ListBranches(ctx *context.APIContext) {
// ListBranches list all the branches of a repository
func ListBranchesSlice(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/branches/branches_slice repository repoListBranches
// swagger:operation GET /repos/{owner}/{repo}/branches/branches_slice repository repoListBranchesSlice
// ---
// summary: List a repository's branches, Group sort.
// produces:

View File

@ -224,7 +224,7 @@ func GetAllCommits(ctx *context.APIContext) {
// GetAllCommits get all commits via
func GetAllCommitsSliceByTime(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/commits_slice repository repoGetAllCommits
// swagger:operation GET /repos/{owner}/{repo}/commits_slice repository repoGetAllCommitsSlice
// ---
// summary: Get a list of all commits from a repository
// produces:
@ -358,9 +358,9 @@ func GetAllCommitsSliceByTime(ctx *context.APIContext) {
}
func CommitSplitSlice(CommitsList []api.Commit) []api.CommitsSlice {
// sort by time
// sort by time
sort.Sort(api.SortCommit(CommitsList))
Commits := make([]api.CommitsSlice,0)
Commits := make([]api.CommitsSlice, 0)
i := 0
var j int
for {
@ -372,18 +372,17 @@ func CommitSplitSlice(CommitsList []api.Commit) []api.CommitsSlice {
}
// if equal, put commitdata in an array
commitDate := CommitsList[i].CommitDate
commitDatalist := CommitsList[i:j]
i = j // variable value
commitDatalist := CommitsList[i:j]
i = j // variable value
// get all the values,,,Commits
Commits = append(Commits, api.CommitsSlice{
CommitDate: commitDate,
Commits: commitDatalist,
Commits: commitDatalist,
})
}
return Commits
}
func toCommit(ctx *context.APIContext, repo *models.Repository, commit *git.Commit, userCache map[string]*models.User) (*api.Commit, error) {
var apiAuthor, apiCommitter *api.User
@ -483,7 +482,7 @@ func toCommit(ctx *context.APIContext, repo *models.Repository, commit *git.Comm
// add by qiubing
// 获取 Graph
func GetGraph(ctx *context.APIContext) {
if ctx.Repo.Repository.IsEmpty { // 项目是否为空
ctx.JSON(http.StatusConflict, api.APIError{
Message: "Git Repository is empty.",

View File

@ -54,51 +54,6 @@ func ListTags(ctx *context.APIContext) {
}
apiTags := make([]*api.Tag, len(tags))
for i := range tags {
apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i])
}
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()
@ -106,7 +61,8 @@ func ListTagsFolk(ctx *context.APIContext) {
if err != nil {
ctx.Error(http.StatusBadRequest, "GetRelease", err)
}
apiTags[i] = convert.ToTagReleases(ctx.Repo.Repository, tags[i], release)
apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i], release)
}
sort.Sort(api.SortTagReleases(apiTags))
ctx.JSON(http.StatusOK, apiTags)

View File

@ -2452,7 +2452,7 @@
"repository"
],
"summary": "List a repository's branches, Group sort.",
"operationId": "repoListBranches",
"operationId": "repoListBranchesSlice",
"parameters": [
{
"type": "string",
@ -2852,7 +2852,7 @@
"repository"
],
"summary": "Get a list of all commits from a repository",
"operationId": "repoGetAllCommits",
"operationId": "repoGetAllCommitsSlice",
"parameters": [
{
"type": "string",
@ -8706,51 +8706,6 @@
}
}
},
"/repos/{owner}/{repo}/tags/releases": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "List a repository's tags",
"operationId": "repoListTagsReleases",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "page number of results to return (1-based)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "page size of results, default maximum page size is 50",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"$ref": "#/responses/TagList"
}
}
}
},
"/repos/{owner}/{repo}/times": {
"get": {
"produces": [
@ -15370,14 +15325,17 @@
"commit": {
"$ref": "#/definitions/CommitMeta"
},
"commit_message": {
"type": "string",
"x-go-name": "CommitMessage"
},
"commit_time": {
"type": "string",
"x-go-name": "CommitTime"
},
"commiter": {
"$ref": "#/definitions/CommitUser"
},
"create_unix": {
"type": "string",
"format": "date-time",
"x-go-name": "CreatedUnix"
},
"id": {
"type": "string",
"x-go-name": "ID"