mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Release API endpoints
This commit is contained in:
committed by
Kim "BKC" Carlbäcker
parent
b7e1bccc50
commit
0c301f7b5c
@@ -15,12 +15,16 @@ import (
|
||||
"code.gitea.io/git"
|
||||
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
// Release represents a release of repository.
|
||||
type Release struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64
|
||||
Repo *Repository `xorm:"-"`
|
||||
PublisherID int64
|
||||
Publisher *User `xorm:"-"`
|
||||
TagName string
|
||||
@@ -53,6 +57,62 @@ func (r *Release) AfterSet(colName string, _ xorm.Cell) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Release) loadAttributes(e Engine) error {
|
||||
var err error
|
||||
if r.Repo == nil {
|
||||
r.Repo, err = GetRepositoryByID(r.RepoID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if r.Publisher == nil {
|
||||
r.Publisher, err = GetUserByID(r.PublisherID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadAttributes load repo and publisher attributes for a realease
|
||||
func (r *Release) LoadAttributes() error {
|
||||
return r.loadAttributes(x)
|
||||
}
|
||||
|
||||
// APIURL the api url for a release. release must have attributes loaded
|
||||
func (r *Release) APIURL() string {
|
||||
return fmt.Sprintf("%sapi/v1/%s/releases/%d",
|
||||
setting.AppURL, r.Repo.FullName(), r.ID)
|
||||
}
|
||||
|
||||
// ZipURL the zip url for a release. release must have attributes loaded
|
||||
func (r *Release) ZipURL() string {
|
||||
return fmt.Sprintf("%s/archive/%s.zip", r.Repo.HTMLURL(), r.TagName)
|
||||
}
|
||||
|
||||
// TarURL the tar.gz url for a release. release must have attributes loaded
|
||||
func (r *Release) TarURL() string {
|
||||
return fmt.Sprintf("%s/archive/%s.tar.gz", r.Repo.HTMLURL(), r.TagName)
|
||||
}
|
||||
|
||||
// APIFormat convert a Release to api.Release
|
||||
func (r *Release) APIFormat() *api.Release {
|
||||
return &api.Release{
|
||||
ID: r.ID,
|
||||
TagName: r.TagName,
|
||||
Target: r.Target,
|
||||
Note: r.Note,
|
||||
URL: r.APIURL(),
|
||||
TarURL: r.TarURL(),
|
||||
ZipURL: r.ZipURL(),
|
||||
IsDraft: r.IsDraft,
|
||||
IsPrerelease: r.IsPrerelease,
|
||||
CreatedAt: r.Created,
|
||||
PublishedAt: r.Created,
|
||||
Publisher: r.Publisher.APIFormat(),
|
||||
}
|
||||
}
|
||||
|
||||
// IsReleaseExist returns true if release with given tag name already exists.
|
||||
func IsReleaseExist(repoID int64, tagName string) (bool, error) {
|
||||
if len(tagName) == 0 {
|
||||
|
Reference in New Issue
Block a user