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.

129 lines
3.3 KiB

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
5 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
5 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
5 years ago
  1. // Copyright 2018 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 repo
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/setting"
  10. )
  11. // AddDependency adds new dependencies
  12. func AddDependency(ctx *context.Context) {
  13. issueIndex := ctx.ParamsInt64("index")
  14. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
  15. if err != nil {
  16. ctx.ServerError("GetIssueByIndex", err)
  17. return
  18. }
  19. // Check if the Repo is allowed to have dependencies
  20. if !ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull) {
  21. ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
  22. return
  23. }
  24. depID := ctx.QueryInt64("newDependency")
  25. if err = issue.LoadRepo(); err != nil {
  26. ctx.ServerError("LoadRepo", err)
  27. return
  28. }
  29. // Redirect
  30. defer ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
  31. // Dependency
  32. dep, err := models.GetIssueByID(depID)
  33. if err != nil {
  34. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_issue_not_exist"))
  35. return
  36. }
  37. // Check if both issues are in the same repo if cross repository dependencies is not enabled
  38. if issue.RepoID != dep.RepoID && !setting.Service.AllowCrossRepositoryDependencies {
  39. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_same_repo"))
  40. return
  41. }
  42. // Check if issue and dependency is the same
  43. if dep.ID == issue.ID {
  44. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_same_issue"))
  45. return
  46. }
  47. err = models.CreateIssueDependency(ctx.User, issue, dep)
  48. if err != nil {
  49. if models.IsErrDependencyExists(err) {
  50. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists"))
  51. return
  52. } else if models.IsErrCircularDependency(err) {
  53. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_cannot_create_circular"))
  54. return
  55. } else {
  56. ctx.ServerError("CreateOrUpdateIssueDependency", err)
  57. return
  58. }
  59. }
  60. }
  61. // RemoveDependency removes the dependency
  62. func RemoveDependency(ctx *context.Context) {
  63. issueIndex := ctx.ParamsInt64("index")
  64. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
  65. if err != nil {
  66. ctx.ServerError("GetIssueByIndex", err)
  67. return
  68. }
  69. // Check if the Repo is allowed to have dependencies
  70. if !ctx.Repo.CanCreateIssueDependencies(ctx.User, issue.IsPull) {
  71. ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
  72. return
  73. }
  74. depID := ctx.QueryInt64("removeDependencyID")
  75. if err = issue.LoadRepo(); err != nil {
  76. ctx.ServerError("LoadRepo", err)
  77. return
  78. }
  79. // Dependency Type
  80. depTypeStr := ctx.Req.PostForm.Get("dependencyType")
  81. var depType models.DependencyType
  82. switch depTypeStr {
  83. case "blockedBy":
  84. depType = models.DependencyTypeBlockedBy
  85. case "blocking":
  86. depType = models.DependencyTypeBlocking
  87. default:
  88. ctx.Error(http.StatusBadRequest, "GetDependecyType")
  89. return
  90. }
  91. // Dependency
  92. dep, err := models.GetIssueByID(depID)
  93. if err != nil {
  94. ctx.ServerError("GetIssueByID", err)
  95. return
  96. }
  97. if err = models.RemoveIssueDependency(ctx.User, issue, dep, depType); err != nil {
  98. if models.IsErrDependencyNotExists(err) {
  99. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist"))
  100. return
  101. }
  102. ctx.ServerError("RemoveIssueDependency", err)
  103. return
  104. }
  105. // Redirect
  106. ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
  107. }