summaryrefslogtreecommitdiffstats
path: root/models/release.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-15 23:52:46 -0500
committerUnknwon <u@gogs.io>2015-11-15 23:52:46 -0500
commit18de67380c5049d6a4d10cc3f6f8fd80a9ac7a89 (patch)
treec5f142fdee161a61867756631ae63b439e7d902f /models/release.go
parent1a901433e2a27e5bcd29216fdb57082be620b745 (diff)
downloadgitea-18de67380c5049d6a4d10cc3f6f8fd80a9ac7a89.tar.gz
gitea-18de67380c5049d6a4d10cc3f6f8fd80a9ac7a89.zip
fix #1958
Diffstat (limited to 'models/release.go')
-rw-r--r--models/release.go34
1 files changed, 14 insertions, 20 deletions
diff --git a/models/release.go b/models/release.go
index 38f3e4f48f..1c9c7d60bd 100644
--- a/models/release.go
+++ b/models/release.go
@@ -5,7 +5,6 @@
package models
import (
- "errors"
"sort"
"strings"
"time"
@@ -15,16 +14,11 @@ import (
"github.com/gogits/gogs/modules/git"
)
-var (
- ErrReleaseAlreadyExist = errors.New("Release already exist")
- ErrReleaseNotExist = errors.New("Release does not exist")
-)
-
// Release represents a release of repository.
type Release struct {
- Id int64
- RepoId int64
- PublisherId int64
+ ID int64 `xorm:"pk autoincr"`
+ RepoID int64
+ PublisherID int64
Publisher *User `xorm:"-"`
TagName string
LowerTagName string
@@ -47,12 +41,12 @@ func (r *Release) AfterSet(colName string, _ xorm.Cell) {
}
// IsReleaseExist returns true if release with given tag name already exists.
-func IsReleaseExist(repoId int64, tagName string) (bool, error) {
+func IsReleaseExist(repoID int64, tagName string) (bool, error) {
if len(tagName) == 0 {
return false, nil
}
- return x.Get(&Release{RepoId: repoId, LowerTagName: strings.ToLower(tagName)})
+ return x.Get(&Release{RepoID: repoID, LowerTagName: strings.ToLower(tagName)})
}
func createTag(gitRepo *git.Repository, rel *Release) error {
@@ -84,11 +78,11 @@ func createTag(gitRepo *git.Repository, rel *Release) error {
// CreateRelease creates a new release of repository.
func CreateRelease(gitRepo *git.Repository, rel *Release) error {
- isExist, err := IsReleaseExist(rel.RepoId, rel.TagName)
+ isExist, err := IsReleaseExist(rel.RepoID, rel.TagName)
if err != nil {
return err
} else if isExist {
- return ErrReleaseAlreadyExist
+ return ErrReleaseAlreadyExist{rel.TagName}
}
if err = createTag(gitRepo, rel); err != nil {
@@ -100,22 +94,22 @@ func CreateRelease(gitRepo *git.Repository, rel *Release) error {
}
// GetRelease returns release by given ID.
-func GetRelease(repoId int64, tagName string) (*Release, error) {
- isExist, err := IsReleaseExist(repoId, tagName)
+func GetRelease(repoID int64, tagName string) (*Release, error) {
+ isExist, err := IsReleaseExist(repoID, tagName)
if err != nil {
return nil, err
} else if !isExist {
- return nil, ErrReleaseNotExist
+ return nil, ErrReleaseNotExist{tagName}
}
- rel := &Release{RepoId: repoId, LowerTagName: strings.ToLower(tagName)}
+ rel := &Release{RepoID: repoID, LowerTagName: strings.ToLower(tagName)}
_, err = x.Get(rel)
return rel, err
}
// GetReleasesByRepoId returns a list of releases of repository.
-func GetReleasesByRepoId(repoId int64) (rels []*Release, err error) {
- err = x.Desc("created").Find(&rels, Release{RepoId: repoId})
+func GetReleasesByRepoId(repoID int64) (rels []*Release, err error) {
+ err = x.Desc("created").Find(&rels, Release{RepoID: repoID})
return rels, err
}
@@ -150,6 +144,6 @@ func UpdateRelease(gitRepo *git.Repository, rel *Release) (err error) {
if err = createTag(gitRepo, rel); err != nil {
return err
}
- _, err = x.Id(rel.Id).AllCols().Update(rel)
+ _, err = x.Id(rel.ID).AllCols().Update(rel)
return err
}