add: add tag message

This commit is contained in:
yystopf 2021-09-24 17:49:54 +08:00
parent 705694ff88
commit b82b5bf80b
3 changed files with 46 additions and 37 deletions

View File

@ -168,19 +168,29 @@ func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection {
// } // }
// } // }
func ToTag(repo *models.Repository, t *git.Tag, release *models.Release) *api.Tag { func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
release.Publisher, _ = models.GetUserByID(release.PublisherID)
commit, _ := t.Commit()
return &api.Tag{ return &api.Tag{
Name: t.Name, Name: t.Name,
ID: t.ID.String(), ID: t.ID.String(),
Commit: ToCommitMeta(repo, t), Commit: ToTagCommit(repo, t),
Commiter: ToCommitUserFolk(release.Publisher), Tagger: ToCommitUser(t.Tagger),
Message: t.Message,
ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"), ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"), TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
CommitTime: release.CreatedUnix.AsTime().String(), }
CommitMessage: commit.CommitMessage, }
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,
} }
} }

View File

@ -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. // Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -8,19 +16,19 @@ package structs
type Tag struct { type Tag struct {
Name string `json:"name"` Name string `json:"name"`
ID string `json:"id"` ID string `json:"id"`
Commit *CommitMeta `json:"commit"` Commit *TagCommit `json:"commit"`
Tagger *CommitUser `json:"tagger"`
Message string `json:"message"`
ZipballURL string `json:"zipball_url"` ZipballURL string `json:"zipball_url"`
TarballURL string `json:"tarball_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 SortTagReleases []*Tag
func (s SortTagReleases) Len() int { return len(s) } type TagCommit struct {
func (s SortTagReleases) Swap(i, j int) { s[i], s[j] = s[j], s[i] } *CommitMeta
func (s SortTagReleases) Less(i, j int) bool { return s[i].CommitTime > s[j].CommitTime } Commiter *CommitUser `json:"commiter"`
Author *CommitUser `json:"author"`
Message string `json:"message"`
}
// AnnotatedTag represents an annotated tag // AnnotatedTag represents an annotated tag
type AnnotatedTag struct { type AnnotatedTag struct {

View File

@ -6,9 +6,7 @@ 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"
@ -55,17 +53,10 @@ func ListTags(ctx *context.APIContext) {
apiTags := make([]*api.Tag, len(tags)) apiTags := make([]*api.Tag, len(tags))
for i := range tags { for i := range tags {
// commit, err := tags[i].Commit() apiTags[i] = convert.ToTag(ctx.Repo.Repository, tags[i])
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)
} ctx.JSON(http.StatusOK, &apiTags)
sort.Sort(api.SortTagReleases(apiTags))
ctx.JSON(http.StatusOK, apiTags)
} }
// GetTag get the tag of a repository. // GetTag get the tag of a repository.