diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2016-12-31 11:51:22 -0500 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-01-02 00:10:52 +0100 |
commit | 0c301f7b5c7a9cc691421724c154b40247aa6959 (patch) | |
tree | e509a85e0cc5a63cc4f8555269a8ae23ca754094 /models/release.go | |
parent | b7e1bccc501c5246e6f8b9bed4853b90e9a447c5 (diff) | |
download | gitea-0c301f7b5c7a9cc691421724c154b40247aa6959.tar.gz gitea-0c301f7b5c7a9cc691421724c154b40247aa6959.zip |
Release API endpoints
Diffstat (limited to 'models/release.go')
-rw-r--r-- | models/release.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/models/release.go b/models/release.go index 41fd145bea..bb5f43407b 100644 --- a/models/release.go +++ b/models/release.go @@ -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 { |