diff options
author | Unknwon <u@gogs.io> | 2015-11-15 23:52:46 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-15 23:52:46 -0500 |
commit | 18de67380c5049d6a4d10cc3f6f8fd80a9ac7a89 (patch) | |
tree | c5f142fdee161a61867756631ae63b439e7d902f /models | |
parent | 1a901433e2a27e5bcd29216fdb57082be620b745 (diff) | |
download | gitea-18de67380c5049d6a4d10cc3f6f8fd80a9ac7a89.tar.gz gitea-18de67380c5049d6a4d10cc3f6f8fd80a9ac7a89.zip |
fix #1958
Diffstat (limited to 'models')
-rw-r--r-- | models/error.go | 26 | ||||
-rw-r--r-- | models/release.go | 34 | ||||
-rw-r--r-- | models/repo.go | 2 |
3 files changed, 41 insertions, 21 deletions
diff --git a/models/error.go b/models/error.go index 8f508598a1..f8fea6f560 100644 --- a/models/error.go +++ b/models/error.go @@ -288,6 +288,32 @@ func (err ErrUpdateTaskNotExist) Error() string { return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID) } +type ErrReleaseAlreadyExist struct { + TagName string +} + +func IsErrReleaseAlreadyExist(err error) bool { + _, ok := err.(ErrReleaseAlreadyExist) + return ok +} + +func (err ErrReleaseAlreadyExist) Error() string { + return fmt.Sprintf("Release tag already exist [tag_name: %s]", err.TagName) +} + +type ErrReleaseNotExist struct { + TagName string +} + +func IsErrReleaseNotExist(err error) bool { + _, ok := err.(ErrReleaseNotExist) + return ok +} + +func (err ErrReleaseNotExist) Error() string { + return fmt.Sprintf("Release tag does not exist [tag_name: %s]", err.TagName) +} + // __ __ ___. .__ __ // / \ / \ ____\_ |__ | |__ ____ ____ | | __ // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ / 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 } diff --git a/models/repo.go b/models/repo.go index bbd978ff4b..9b2c7bc6c0 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1116,7 +1116,7 @@ func DeleteRepository(uid, repoID int64) error { return err } else if _, err = sess.Delete(&Milestone{RepoID: repoID}); err != nil { return err - } else if _, err = sess.Delete(&Release{RepoId: repoID}); err != nil { + } else if _, err = sess.Delete(&Release{RepoID: repoID}); err != nil { return err } else if _, err = sess.Delete(&Collaboration{RepoID: repoID}); err != nil { return err |