aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-01-01 13:15:09 -0500
committerEthan Koenig <ethantkoenig@gmail.com>2017-01-06 10:08:23 -0500
commit72bfabfada8fc485b88eb4547b7d3575789a69c8 (patch)
tree838a128004ac7e3417816171c1f3e60b98edcd57 /models/issue.go
parent1a7fc53c98f06f79955d217f91c8a5553e5a27b3 (diff)
downloadgitea-72bfabfada8fc485b88eb4547b7d3575789a69c8.tar.gz
gitea-72bfabfada8fc485b88eb4547b7d3575789a69c8.zip
Unit tests for models/pull.go
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go38
1 files changed, 22 insertions, 16 deletions
diff --git a/models/issue.go b/models/issue.go
index 315c91e159..0cf92a8647 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -876,6 +876,27 @@ type IssuesOptions struct {
SortType string
}
+// sortIssuesSession sort an issues-related session based on the provided
+// sortType string
+func sortIssuesSession(sess *xorm.Session, sortType string) {
+ switch sortType {
+ case "oldest":
+ sess.Asc("issue.created_unix")
+ case "recentupdate":
+ sess.Desc("issue.updated_unix")
+ case "leastupdate":
+ sess.Asc("issue.updated_unix")
+ case "mostcomment":
+ sess.Desc("issue.num_comments")
+ case "leastcomment":
+ sess.Asc("issue.num_comments")
+ case "priority":
+ sess.Desc("issue.priority")
+ default:
+ sess.Desc("issue.created_unix")
+ }
+}
+
// Issues returns a list of issues by given conditions.
func Issues(opts *IssuesOptions) ([]*Issue, error) {
if opts.Page <= 0 {
@@ -912,22 +933,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
sess.And("issue.is_pull=?", opts.IsPull)
- switch opts.SortType {
- case "oldest":
- sess.Asc("issue.created_unix")
- case "recentupdate":
- sess.Desc("issue.updated_unix")
- case "leastupdate":
- sess.Asc("issue.updated_unix")
- case "mostcomment":
- sess.Desc("issue.num_comments")
- case "leastcomment":
- sess.Asc("issue.num_comments")
- case "priority":
- sess.Desc("issue.priority")
- default:
- sess.Desc("issue.created_unix")
- }
+ sortIssuesSession(sess, opts.SortType)
if len(opts.Labels) > 0 && opts.Labels != "0" {
labelIDs, err := base.StringsToInt64s(strings.Split(opts.Labels, ","))