You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pull_list.go 4.9KB

API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/modules/base"
  8. "code.gitea.io/gitea/modules/git"
  9. "code.gitea.io/gitea/modules/log"
  10. "xorm.io/xorm"
  11. )
  12. // PullRequestsOptions holds the options for PRs
  13. type PullRequestsOptions struct {
  14. ListOptions
  15. State string
  16. SortType string
  17. Labels []string
  18. MilestoneID int64
  19. }
  20. func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xorm.Session, error) {
  21. sess := x.Where("pull_request.base_repo_id=?", baseRepoID)
  22. sess.Join("INNER", "issue", "pull_request.issue_id = issue.id")
  23. switch opts.State {
  24. case "closed", "open":
  25. sess.And("issue.is_closed=?", opts.State == "closed")
  26. }
  27. if labelIDs, err := base.StringsToInt64s(opts.Labels); err != nil {
  28. return nil, err
  29. } else if len(labelIDs) > 0 {
  30. sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").
  31. In("issue_label.label_id", labelIDs)
  32. }
  33. if opts.MilestoneID > 0 {
  34. sess.And("issue.milestone_id=?", opts.MilestoneID)
  35. }
  36. return sess, nil
  37. }
  38. // GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
  39. // by given head information (repo and branch).
  40. func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) {
  41. prs := make([]*PullRequest, 0, 2)
  42. return prs, x.
  43. Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ?",
  44. repoID, branch, false, false).
  45. Join("INNER", "issue", "issue.id = pull_request.issue_id").
  46. Find(&prs)
  47. }
  48. // GetUnmergedPullRequestsByBaseInfo returns all pull requests that are open and has not been merged
  49. // by given base information (repo and branch).
  50. func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequest, error) {
  51. prs := make([]*PullRequest, 0, 2)
  52. return prs, x.
  53. Where("base_repo_id=? AND base_branch=? AND has_merged=? AND issue.is_closed=?",
  54. repoID, branch, false, false).
  55. Join("INNER", "issue", "issue.id=pull_request.issue_id").
  56. Find(&prs)
  57. }
  58. // GetPullRequestIDsByCheckStatus returns all pull requests according the special checking status.
  59. func GetPullRequestIDsByCheckStatus(status PullRequestStatus) ([]int64, error) {
  60. prs := make([]int64, 0, 10)
  61. return prs, x.Table("pull_request").
  62. Where("status=?", status).
  63. Cols("pull_request.id").
  64. Find(&prs)
  65. }
  66. // PullRequests returns all pull requests for a base Repo by the given conditions
  67. func PullRequests(baseRepoID int64, opts *PullRequestsOptions) ([]*PullRequest, int64, error) {
  68. if opts.Page <= 0 {
  69. opts.Page = 1
  70. }
  71. countSession, err := listPullRequestStatement(baseRepoID, opts)
  72. if err != nil {
  73. log.Error("listPullRequestStatement: %v", err)
  74. return nil, 0, err
  75. }
  76. maxResults, err := countSession.Count(new(PullRequest))
  77. if err != nil {
  78. log.Error("Count PRs: %v", err)
  79. return nil, maxResults, err
  80. }
  81. findSession, err := listPullRequestStatement(baseRepoID, opts)
  82. sortIssuesSession(findSession, opts.SortType, 0)
  83. if err != nil {
  84. log.Error("listPullRequestStatement: %v", err)
  85. return nil, maxResults, err
  86. }
  87. findSession = opts.setSessionPagination(findSession)
  88. prs := make([]*PullRequest, 0, opts.PageSize)
  89. return prs, maxResults, findSession.Find(&prs)
  90. }
  91. // PullRequestList defines a list of pull requests
  92. type PullRequestList []*PullRequest
  93. func (prs PullRequestList) loadAttributes(e Engine) error {
  94. if len(prs) == 0 {
  95. return nil
  96. }
  97. // Load issues.
  98. issueIDs := prs.getIssueIDs()
  99. issues := make([]*Issue, 0, len(issueIDs))
  100. if err := e.
  101. Where("id > 0").
  102. In("id", issueIDs).
  103. Find(&issues); err != nil {
  104. return fmt.Errorf("find issues: %v", err)
  105. }
  106. set := make(map[int64]*Issue)
  107. for i := range issues {
  108. set[issues[i].ID] = issues[i]
  109. }
  110. for i := range prs {
  111. prs[i].Issue = set[prs[i].IssueID]
  112. }
  113. return nil
  114. }
  115. func (prs PullRequestList) getIssueIDs() []int64 {
  116. issueIDs := make([]int64, 0, len(prs))
  117. for i := range prs {
  118. issueIDs = append(issueIDs, prs[i].IssueID)
  119. }
  120. return issueIDs
  121. }
  122. // LoadAttributes load all the prs attributes
  123. func (prs PullRequestList) LoadAttributes() error {
  124. return prs.loadAttributes(x)
  125. }
  126. func (prs PullRequestList) invalidateCodeComments(e Engine, doer *User, repo *git.Repository, branch string) error {
  127. if len(prs) == 0 {
  128. return nil
  129. }
  130. issueIDs := prs.getIssueIDs()
  131. var codeComments []*Comment
  132. if err := e.
  133. Where("type = ? and invalidated = ?", CommentTypeCode, false).
  134. In("issue_id", issueIDs).
  135. Find(&codeComments); err != nil {
  136. return fmt.Errorf("find code comments: %v", err)
  137. }
  138. for _, comment := range codeComments {
  139. if err := comment.CheckInvalidation(repo, doer, branch); err != nil {
  140. return err
  141. }
  142. }
  143. return nil
  144. }
  145. // InvalidateCodeComments will lookup the prs for code comments which got invalidated by change
  146. func (prs PullRequestList) InvalidateCodeComments(doer *User, repo *git.Repository, branch string) error {
  147. return prs.invalidateCodeComments(x, doer, repo, branch)
  148. }