MCPcopy Create free account
hub / github.com/gogs/gogs / buildIssuesQuery

Function buildIssuesQuery

internal/database/issue.go:913–977  ·  view source on GitHub ↗

buildIssuesQuery returns nil if it foresees there won't be any value returned.

(opts *IssuesOptions)

Source from the content-addressed store, hash-verified

911
912// buildIssuesQuery returns nil if it foresees there won't be any value returned.
913func buildIssuesQuery(opts *IssuesOptions) *xorm.Session {
914 sess := x.NewSession()
915
916 if opts.Page <= 0 {
917 opts.Page = 1
918 }
919
920 if opts.RepoID > 0 {
921 sess.Where("issue.repo_id=?", opts.RepoID).And("issue.is_closed=?", opts.IsClosed)
922 } else if opts.RepoIDs != nil {
923 // In case repository IDs are provided but actually no repository has issue.
924 if len(opts.RepoIDs) == 0 {
925 return nil
926 }
927 sess.In("issue.repo_id", opts.RepoIDs).And("issue.is_closed=?", opts.IsClosed)
928 } else {
929 sess.Where("issue.is_closed=?", opts.IsClosed)
930 }
931
932 if opts.AssigneeID > 0 {
933 sess.And("issue.assignee_id=?", opts.AssigneeID)
934 } else if opts.PosterID > 0 {
935 sess.And("issue.poster_id=?", opts.PosterID)
936 }
937
938 if opts.MilestoneID > 0 {
939 sess.And("issue.milestone_id=?", opts.MilestoneID)
940 }
941
942 sess.And("issue.is_pull=?", opts.IsPull)
943
944 switch opts.SortType {
945 case "oldest":
946 sess.Asc("issue.created_unix")
947 case "recentupdate":
948 sess.Desc("issue.updated_unix")
949 case "leastupdate":
950 sess.Asc("issue.updated_unix")
951 case "mostcomment":
952 sess.Desc("issue.num_comments")
953 case "leastcomment":
954 sess.Asc("issue.num_comments")
955 case "priority":
956 sess.Desc("issue.priority")
957 default:
958 sess.Desc("issue.created_unix")
959 }
960
961 if len(opts.Labels) > 0 && opts.Labels != "0" {
962 labelIDs := strings.Split(opts.Labels, ",")
963 if len(labelIDs) > 0 {
964 sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").In("issue_label.label_id", labelIDs)
965 }
966 }
967
968 if opts.IsMention {
969 sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").And("issue_user.is_mentioned = ?", true)
970

Callers 2

IssuesCountFunction · 0.85
IssuesFunction · 0.85

Calls 3

WhereMethod · 0.80
InMethod · 0.80
SplitMethod · 0.80

Tested by

no test coverage detected