summaryrefslogtreecommitdiffstats
path: root/models/release.go
diff options
context:
space:
mode:
authorBwko <bouwko@gmail.com>2016-11-25 09:11:12 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2016-11-25 16:11:12 +0800
commitc0ca6644ade5ce21d8c7601439d94ea1fed7443d (patch)
tree1499afb6db12488a8ce1df8708717f46eb6e89b6 /models/release.go
parent081c2a9395706e24bb396bf2aa9ac8a92d0a8f40 (diff)
downloadgitea-c0ca6644ade5ce21d8c7601439d94ea1fed7443d.tar.gz
gitea-c0ca6644ade5ce21d8c7601439d94ea1fed7443d.zip
Lint/issue &mail (#243)
* Lint models/release.go * Lint models/ issue_label, issue_mail & mail.go
Diffstat (limited to 'models/release.go')
-rw-r--r--models/release.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/models/release.go b/models/release.go
index a60376d978..c047b2f557 100644
--- a/models/release.go
+++ b/models/release.go
@@ -38,12 +38,14 @@ type Release struct {
CreatedUnix int64
}
+// BeforeInsert is invoked from XORM before inserting an object of this type.
func (r *Release) BeforeInsert() {
if r.CreatedUnix == 0 {
r.CreatedUnix = time.Now().Unix()
}
}
+// AfterSet is invoked from XORM after setting the value of a field of this object.
func (r *Release) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "created_unix":
@@ -151,15 +153,15 @@ func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err
return rels, err
}
-type ReleaseSorter struct {
+type releaseSorter struct {
rels []*Release
}
-func (rs *ReleaseSorter) Len() int {
+func (rs *releaseSorter) Len() int {
return len(rs.rels)
}
-func (rs *ReleaseSorter) Less(i, j int) bool {
+func (rs *releaseSorter) Less(i, j int) bool {
diffNum := rs.rels[i].NumCommits - rs.rels[j].NumCommits
if diffNum != 0 {
return diffNum > 0
@@ -167,13 +169,13 @@ func (rs *ReleaseSorter) Less(i, j int) bool {
return rs.rels[i].Created.After(rs.rels[j].Created)
}
-func (rs *ReleaseSorter) Swap(i, j int) {
+func (rs *releaseSorter) Swap(i, j int) {
rs.rels[i], rs.rels[j] = rs.rels[j], rs.rels[i]
}
// SortReleases sorts releases by number of commits and created time.
func SortReleases(rels []*Release) {
- sorter := &ReleaseSorter{rels: rels}
+ sorter := &releaseSorter{rels: rels}
sort.Sort(sorter)
}