add: add tag message
This commit is contained in:
parent
705694ff88
commit
b82b5bf80b
|
@ -168,19 +168,29 @@ func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection {
|
|||
// }
|
||||
// }
|
||||
|
||||
func ToTag(repo *models.Repository, t *git.Tag, release *models.Release) *api.Tag {
|
||||
release.Publisher, _ = models.GetUserByID(release.PublisherID)
|
||||
|
||||
commit, _ := t.Commit()
|
||||
func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
|
||||
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,
|
||||
Name: t.Name,
|
||||
ID: t.ID.String(),
|
||||
Commit: ToTagCommit(repo, t),
|
||||
Tagger: ToCommitUser(t.Tagger),
|
||||
Message: t.Message,
|
||||
ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
|
||||
TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
|
||||
}
|
||||
}
|
||||
|
||||
func ToTagCommit(repo *models.Repository, t *git.Tag) *api.TagCommit {
|
||||
commit, err := t.Commit()
|
||||
if err != nil {
|
||||
log.Error("Commit", err)
|
||||
return &api.TagCommit{}
|
||||
}
|
||||
return &api.TagCommit{
|
||||
CommitMeta: ToCommitMeta(repo, t),
|
||||
Commiter: ToCommitUser(commit.Committer),
|
||||
Author: ToCommitUser(commit.Author),
|
||||
Message: commit.CommitMessage,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
/*
|
||||
* @Description: Do not edit
|
||||
* @Date: 2021-09-23 17:10:03
|
||||
* @LastEditors: viletyy
|
||||
* @Author: viletyy
|
||||
* @LastEditTime: 2021-09-24 17:45:38
|
||||
* @FilePath: /gitea-1120-rc1/modules/structs/repo_tag.go
|
||||
*/
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
@ -6,21 +14,21 @@ 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"`
|
||||
Commiter *CommitUser `json:"commiter"`
|
||||
CommitTime string `json:"commit_time"`
|
||||
CommitMessage string `json:"commit_message"`
|
||||
// User *CommitUser `json:"user"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
Commit *TagCommit `json:"commit"`
|
||||
Tagger *CommitUser `json:"tagger"`
|
||||
Message string `json:"message"`
|
||||
ZipballURL string `json:"zipball_url"`
|
||||
TarballURL string `json:"tarball_url"`
|
||||
}
|
||||
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] }
|
||||
func (s SortTagReleases) Less(i, j int) bool { return s[i].CommitTime > s[j].CommitTime }
|
||||
type TagCommit struct {
|
||||
*CommitMeta
|
||||
Commiter *CommitUser `json:"commiter"`
|
||||
Author *CommitUser `json:"author"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// AnnotatedTag represents an annotated tag
|
||||
type AnnotatedTag struct {
|
||||
|
|
|
@ -6,9 +6,7 @@ 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"
|
||||
|
@ -55,17 +53,10 @@ func ListTags(ctx *context.APIContext) {
|
|||
|
||||
apiTags := make([]*api.Tag, 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.ToTag(ctx.Repo.Repository, tags[i], release)
|
||||
|
||||
apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i])
|
||||
}
|
||||
sort.Sort(api.SortTagReleases(apiTags))
|
||||
ctx.JSON(http.StatusOK, apiTags)
|
||||
|
||||
ctx.JSON(http.StatusOK, &apiTags)
|
||||
}
|
||||
|
||||
// GetTag get the tag of a repository.
|
||||
|
|
Loading…
Reference in New Issue