aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2020-04-18 09:47:15 -0500
committerGitHub <noreply@github.com>2020-04-18 11:47:15 -0300
commit4f597b1866954ff94999a52af1a41fed06f0143e (patch)
tree0f260a237d33e55b259bb5cf5671c67135799d79 /models
parent1b86f174ce99b579df35c32e800551b1fd1df807 (diff)
downloadgitea-4f597b1866954ff94999a52af1a41fed06f0143e.tar.gz
gitea-4f597b1866954ff94999a52af1a41fed06f0143e.zip
Add single release page and latest redirect (#11102)
* Add single release and latest release routes Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update API and move latest search to models Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix swagger Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'models')
-rw-r--r--models/release.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/models/release.go b/models/release.go
index 0f670f374f..0c76d17f4b 100644
--- a/models/release.go
+++ b/models/release.go
@@ -80,6 +80,11 @@ func (r *Release) TarURL() string {
return fmt.Sprintf("%s/archive/%s.tar.gz", r.Repo.HTMLURL(), r.TagName)
}
+// HTMLURL the url for a release on the web UI. release must have attributes loaded
+func (r *Release) HTMLURL() string {
+ return fmt.Sprintf("%s/releases/tag/%s", r.Repo.HTMLURL(), r.TagName)
+}
+
// APIFormat convert a Release to api.Release
func (r *Release) APIFormat() *api.Release {
assets := make([]*api.Attachment, 0)
@@ -93,6 +98,7 @@ func (r *Release) APIFormat() *api.Release {
Title: r.Title,
Note: r.Note,
URL: r.APIURL(),
+ HTMLURL: r.HTMLURL(),
TarURL: r.TarURL(),
ZipURL: r.ZipURL(),
IsDraft: r.IsDraft,
@@ -217,6 +223,28 @@ func GetReleasesByRepoID(repoID int64, opts FindReleasesOptions) ([]*Release, er
return rels, sess.Find(&rels)
}
+// GetLatestReleaseByRepoID returns the latest release for a repository
+func GetLatestReleaseByRepoID(repoID int64) (*Release, error) {
+ cond := builder.NewCond().
+ And(builder.Eq{"repo_id": repoID}).
+ And(builder.Eq{"is_draft": false}).
+ And(builder.Eq{"is_prerelease": false}).
+ And(builder.Eq{"is_tag": false})
+
+ rel := new(Release)
+ has, err := x.
+ Desc("created_unix", "id").
+ Where(cond).
+ Get(rel)
+ if err != nil {
+ return nil, err
+ } else if !has {
+ return nil, ErrReleaseNotExist{0, "latest"}
+ }
+
+ return rel, nil
+}
+
// GetReleasesByRepoIDAndNames returns a list of releases of repository according repoID and tagNames.
func GetReleasesByRepoIDAndNames(ctx DBContext, repoID int64, tagNames []string) (rels []*Release, err error) {
err = ctx.e.