diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 49 | ||||
-rw-r--r-- | models/issue_label.go | 13 | ||||
-rw-r--r-- | models/issue_test.go | 9 | ||||
-rw-r--r-- | models/pull_list.go | 2 |
4 files changed, 53 insertions, 20 deletions
diff --git a/models/issue.go b/models/issue.go index 17205cc2fa..78413468b2 100644 --- a/models/issue.go +++ b/models/issue.go @@ -9,6 +9,7 @@ import ( "path" "regexp" "sort" + "strconv" "strings" "code.gitea.io/gitea/modules/base" @@ -378,6 +379,12 @@ func (issue *Issue) apiFormat(e Engine) *api.Issue { Updated: issue.UpdatedUnix.AsTime(), } + apiIssue.Repo = &api.RepositoryMeta{ + ID: issue.Repo.ID, + Name: issue.Repo.Name, + FullName: issue.Repo.FullName(), + } + if issue.ClosedUnix != 0 { apiIssue.Closed = issue.ClosedUnix.AsTimePtr() } @@ -1047,11 +1054,13 @@ type IssuesOptions struct { LabelIDs []int64 SortType string IssueIDs []int64 + // prioritize issues from this repo + PriorityRepoID int64 } // sortIssuesSession sort an issues-related session based on the provided // sortType string -func sortIssuesSession(sess *xorm.Session, sortType string) { +func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64) { switch sortType { case "oldest": sess.Asc("issue.created_unix") @@ -1069,6 +1078,8 @@ func sortIssuesSession(sess *xorm.Session, sortType string) { sess.Asc("issue.deadline_unix") case "farduedate": sess.Desc("issue.deadline_unix") + case "priorityrepo": + sess.OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(priorityRepoID, 10) + " THEN 1 ELSE 2 END, issue.created_unix DESC") default: sess.Desc("issue.created_unix") } @@ -1170,7 +1181,7 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { defer sess.Close() opts.setupSession(sess) - sortIssuesSession(sess, opts.SortType) + sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID) issues := make([]*Issue, 0, setting.UI.IssuePagingNum) if err := sess.Find(&issues); err != nil { @@ -1476,8 +1487,8 @@ func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen } // SearchIssueIDsByKeyword search issues on database -func SearchIssueIDsByKeyword(kw string, repoID int64, limit, start int) (int64, []int64, error) { - var repoCond = builder.Eq{"repo_id": repoID} +func SearchIssueIDsByKeyword(kw string, repoIDs []int64, limit, start int) (int64, []int64, error) { + var repoCond = builder.In("repo_id", repoIDs) var subQuery = builder.Select("id").From("issue").Where(repoCond) var cond = builder.And( repoCond, @@ -1566,33 +1577,43 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *Us return sess.Commit() } +// DependencyInfo represents high level information about an issue which is a dependency of another issue. +type DependencyInfo struct { + Issue `xorm:"extends"` + Repository `xorm:"extends"` +} + // Get Blocked By Dependencies, aka all issues this issue is blocked by. -func (issue *Issue) getBlockedByDependencies(e Engine) (issueDeps []*Issue, err error) { +func (issue *Issue) getBlockedByDependencies(e Engine) (issueDeps []*DependencyInfo, err error) { return issueDeps, e. - Table("issue_dependency"). - Select("issue.*"). - Join("INNER", "issue", "issue.id = issue_dependency.dependency_id"). + Table("issue"). + Join("INNER", "repository", "repository.id = issue.repo_id"). + Join("INNER", "issue_dependency", "issue_dependency.dependency_id = issue.id"). Where("issue_id = ?", issue.ID). + //sort by repo id then created date, with the issues of the same repo at the beginning of the list + OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(issue.RepoID, 10) + " THEN 0 ELSE issue.repo_id END, issue.created_unix DESC"). Find(&issueDeps) } // Get Blocking Dependencies, aka all issues this issue blocks. -func (issue *Issue) getBlockingDependencies(e Engine) (issueDeps []*Issue, err error) { +func (issue *Issue) getBlockingDependencies(e Engine) (issueDeps []*DependencyInfo, err error) { return issueDeps, e. - Table("issue_dependency"). - Select("issue.*"). - Join("INNER", "issue", "issue.id = issue_dependency.issue_id"). + Table("issue"). + Join("INNER", "repository", "repository.id = issue.repo_id"). + Join("INNER", "issue_dependency", "issue_dependency.issue_id = issue.id"). Where("dependency_id = ?", issue.ID). + //sort by repo id then created date, with the issues of the same repo at the beginning of the list + OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(issue.RepoID, 10) + " THEN 0 ELSE issue.repo_id END, issue.created_unix DESC"). Find(&issueDeps) } // BlockedByDependencies finds all Dependencies an issue is blocked by -func (issue *Issue) BlockedByDependencies() ([]*Issue, error) { +func (issue *Issue) BlockedByDependencies() ([]*DependencyInfo, error) { return issue.getBlockedByDependencies(x) } // BlockingDependencies returns all blocking dependencies, aka all other issues a given issue blocks -func (issue *Issue) BlockingDependencies() ([]*Issue, error) { +func (issue *Issue) BlockingDependencies() ([]*DependencyInfo, error) { return issue.getBlockingDependencies(x) } diff --git a/models/issue_label.go b/models/issue_label.go index 1fc873cfd4..497756af5b 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -250,6 +250,19 @@ func GetLabelIDsInRepoByNames(repoID int64, labelNames []string) ([]int64, error Find(&labelIDs) } +// GetLabelIDsInReposByNames returns a list of labelIDs by names in one of the given +// repositories. +// it silently ignores label names that do not belong to the repository. +func GetLabelIDsInReposByNames(repoIDs []int64, labelNames []string) ([]int64, error) { + labelIDs := make([]int64, 0, len(labelNames)) + return labelIDs, x.Table("label"). + In("repo_id", repoIDs). + In("name", labelNames). + Asc("name"). + Cols("id"). + Find(&labelIDs) +} + // GetLabelInRepoByID returns a label by ID in given repository. func GetLabelInRepoByID(repoID, labelID int64) (*Label, error) { return getLabelInRepoByID(x, repoID, labelID) diff --git a/models/issue_test.go b/models/issue_test.go index 592a0e3d77..d16c1de25d 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -264,24 +264,23 @@ func TestIssue_loadTotalTimes(t *testing.T) { func TestIssue_SearchIssueIDsByKeyword(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) - - total, ids, err := SearchIssueIDsByKeyword("issue2", 1, 10, 0) + total, ids, err := SearchIssueIDsByKeyword("issue2", []int64{1}, 10, 0) assert.NoError(t, err) assert.EqualValues(t, 1, total) assert.EqualValues(t, []int64{2}, ids) - total, ids, err = SearchIssueIDsByKeyword("first", 1, 10, 0) + total, ids, err = SearchIssueIDsByKeyword("first", []int64{1}, 10, 0) assert.NoError(t, err) assert.EqualValues(t, 1, total) assert.EqualValues(t, []int64{1}, ids) - total, ids, err = SearchIssueIDsByKeyword("for", 1, 10, 0) + total, ids, err = SearchIssueIDsByKeyword("for", []int64{1}, 10, 0) assert.NoError(t, err) assert.EqualValues(t, 4, total) assert.EqualValues(t, []int64{1, 2, 3, 5}, ids) // issue1's comment id 2 - total, ids, err = SearchIssueIDsByKeyword("good", 1, 10, 0) + total, ids, err = SearchIssueIDsByKeyword("good", []int64{1}, 10, 0) assert.NoError(t, err) assert.EqualValues(t, 1, total) assert.EqualValues(t, []int64{1}, ids) diff --git a/models/pull_list.go b/models/pull_list.go index 4ec6fdde3b..2c2f53f4a1 100644 --- a/models/pull_list.go +++ b/models/pull_list.go @@ -87,7 +87,7 @@ func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest, prs := make([]*PullRequest, 0, ItemsPerPage) findSession, err := listPullRequestStatement(baseRepoID, opts) - sortIssuesSession(findSession, opts.SortType) + sortIssuesSession(findSession, opts.SortType, 0) if err != nil { log.Error("listPullRequestStatement: %v", err) return nil, maxResults, err |