mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-03 17:23:55 +00:00
Lint models/release.go
This commit is contained in:
parent
21e8deed89
commit
ece19f4a5e
|
@ -38,12 +38,14 @@ type Release struct {
|
||||||
CreatedUnix int64
|
CreatedUnix int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeforeInsert is invoked from XORM before inserting an object of this type.
|
||||||
func (r *Release) BeforeInsert() {
|
func (r *Release) BeforeInsert() {
|
||||||
if r.CreatedUnix == 0 {
|
if r.CreatedUnix == 0 {
|
||||||
r.CreatedUnix = time.Now().Unix()
|
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) {
|
func (r *Release) AfterSet(colName string, _ xorm.Cell) {
|
||||||
switch colName {
|
switch colName {
|
||||||
case "created_unix":
|
case "created_unix":
|
||||||
|
@ -151,15 +153,15 @@ func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err
|
||||||
return rels, err
|
return rels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReleaseSorter struct {
|
type releaseSorter struct {
|
||||||
rels []*Release
|
rels []*Release
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs *ReleaseSorter) Len() int {
|
func (rs *releaseSorter) Len() int {
|
||||||
return len(rs.rels)
|
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
|
diffNum := rs.rels[i].NumCommits - rs.rels[j].NumCommits
|
||||||
if diffNum != 0 {
|
if diffNum != 0 {
|
||||||
return 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)
|
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]
|
rs.rels[i], rs.rels[j] = rs.rels[j], rs.rels[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
// SortReleases sorts releases by number of commits and created time.
|
// SortReleases sorts releases by number of commits and created time.
|
||||||
func SortReleases(rels []*Release) {
|
func SortReleases(rels []*Release) {
|
||||||
sorter := &ReleaseSorter{rels: rels}
|
sorter := &releaseSorter{rels: rels}
|
||||||
sort.Sort(sorter)
|
sort.Sort(sorter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue