aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2017-01-06 19:19:18 -0200
committerGitHub <noreply@github.com>2017-01-06 19:19:18 -0200
commit03b45284e1845f81d996c7f1cb059e8a8eebfe29 (patch)
treedc80ceec2706ee96bcb4b3403166d289ace58868 /models/issue.go
parent84b7d29d34e0d51e0c67e2e35803e8e611da7965 (diff)
parent72bfabfada8fc485b88eb4547b7d3575789a69c8 (diff)
downloadgitea-03b45284e1845f81d996c7f1cb059e8a8eebfe29.tar.gz
gitea-03b45284e1845f81d996c7f1cb059e8a8eebfe29.zip
Merge pull request #555 from ethantkoenig/tests/pull
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 b8f23d5948..c0377e6348 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, ","))