A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
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.

411 lines
11 KiB

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>
3 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>
3 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>
3 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
3 years ago
issue search on my related repositories (#9758) * adding search capability to user's issues dashboard * global issue search * placement of search bar on issues dashboard * fixed some bugs in the issue dashboard search * added unit test because IssueIDs option was added to UserIssueStatsOptions * some renaming of fields in the issue dashboard code to be more clear; also trying to fix issue of searching the right repos based on the filter * added unit test fro GetRepoIDsForIssuesOptions; fixed search lost on pagination; using shown issue status for open/close count; removed some debugging * fix issue with all count showing incorrectly * removed todo comment left in by mistake * typo pulling wrong count * fxied all count being off when selecting repositories * setting the opts.IsClosed after pulling repos to search, this is done so that the list of repo ids to serach for the keyword is not limited, we need to get all the issue ids for the shown issue stats * added "accessibleRepositoryCondition" check on the query to pull the repo ids to search for issues, this is an added protection to ensure we don't search repos the user does not have access to * added code so that in the issues search, we won't use an in clause of issues ids that goes over 1000 * fixed unit test * using 950 as the limit for issue search, removed unneeded group by in GetRepoIDsForIssuesOptions, showing search on pulls dashboard page too (not just issues) Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
2 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
4 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
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
3 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
3 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
3 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
3 years ago
issue search on my related repositories (#9758) * adding search capability to user's issues dashboard * global issue search * placement of search bar on issues dashboard * fixed some bugs in the issue dashboard search * added unit test because IssueIDs option was added to UserIssueStatsOptions * some renaming of fields in the issue dashboard code to be more clear; also trying to fix issue of searching the right repos based on the filter * added unit test fro GetRepoIDsForIssuesOptions; fixed search lost on pagination; using shown issue status for open/close count; removed some debugging * fix issue with all count showing incorrectly * removed todo comment left in by mistake * typo pulling wrong count * fxied all count being off when selecting repositories * setting the opts.IsClosed after pulling repos to search, this is done so that the list of repo ids to serach for the keyword is not limited, we need to get all the issue ids for the shown issue stats * added "accessibleRepositoryCondition" check on the query to pull the repo ids to search for issues, this is an added protection to ensure we don't search repos the user does not have access to * added code so that in the issues search, we won't use an in clause of issues ids that goes over 1000 * fixed unit test * using 950 as the limit for issue search, removed unneeded group by in GetRepoIDsForIssuesOptions, showing search on pulls dashboard page too (not just issues) Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
2 years ago
  1. // Copyright 2017 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. "sort"
  7. "testing"
  8. "time"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestIssue_ReplaceLabels(t *testing.T) {
  12. assert.NoError(t, PrepareTestDatabase())
  13. testSuccess := func(issueID int64, labelIDs []int64) {
  14. issue := AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
  15. repo := AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository)
  16. doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
  17. labels := make([]*Label, len(labelIDs))
  18. for i, labelID := range labelIDs {
  19. labels[i] = AssertExistsAndLoadBean(t, &Label{ID: labelID, RepoID: repo.ID}).(*Label)
  20. }
  21. assert.NoError(t, issue.ReplaceLabels(labels, doer))
  22. AssertCount(t, &IssueLabel{IssueID: issueID}, len(labelIDs))
  23. for _, labelID := range labelIDs {
  24. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
  25. }
  26. }
  27. testSuccess(1, []int64{2})
  28. testSuccess(1, []int64{1, 2})
  29. testSuccess(1, []int64{})
  30. }
  31. func Test_GetIssueIDsByRepoID(t *testing.T) {
  32. assert.NoError(t, PrepareTestDatabase())
  33. ids, err := GetIssueIDsByRepoID(1)
  34. assert.NoError(t, err)
  35. assert.Len(t, ids, 5)
  36. }
  37. func TestIssueAPIURL(t *testing.T) {
  38. assert.NoError(t, PrepareTestDatabase())
  39. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  40. err := issue.LoadAttributes()
  41. assert.NoError(t, err)
  42. assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL())
  43. }
  44. func TestGetIssuesByIDs(t *testing.T) {
  45. assert.NoError(t, PrepareTestDatabase())
  46. testSuccess := func(expectedIssueIDs, nonExistentIssueIDs []int64) {
  47. issues, err := GetIssuesByIDs(append(expectedIssueIDs, nonExistentIssueIDs...))
  48. assert.NoError(t, err)
  49. actualIssueIDs := make([]int64, len(issues))
  50. for i, issue := range issues {
  51. actualIssueIDs[i] = issue.ID
  52. }
  53. assert.Equal(t, expectedIssueIDs, actualIssueIDs)
  54. }
  55. testSuccess([]int64{1, 2, 3}, []int64{})
  56. testSuccess([]int64{1, 2, 3}, []int64{NonexistentID})
  57. }
  58. func TestGetParticipantIDsByIssue(t *testing.T) {
  59. assert.NoError(t, PrepareTestDatabase())
  60. checkParticipants := func(issueID int64, userIDs []int) {
  61. issue, err := GetIssueByID(issueID)
  62. assert.NoError(t, err)
  63. participants, err := issue.getParticipantIDsByIssue(x)
  64. if assert.NoError(t, err) {
  65. participantsIDs := make([]int, len(participants))
  66. for i, uid := range participants {
  67. participantsIDs[i] = int(uid)
  68. }
  69. sort.Ints(participantsIDs)
  70. sort.Ints(userIDs)
  71. assert.Equal(t, userIDs, participantsIDs)
  72. }
  73. }
  74. // User 1 is issue1 poster (see fixtures/issue.yml)
  75. // User 2 only labeled issue1 (see fixtures/comment.yml)
  76. // Users 3 and 5 made actual comments (see fixtures/comment.yml)
  77. // User 3 is inactive, thus not active participant
  78. checkParticipants(1, []int{1, 5})
  79. }
  80. func TestIssue_ClearLabels(t *testing.T) {
  81. tests := []struct {
  82. issueID int64
  83. doerID int64
  84. }{
  85. {1, 2}, // non-pull-request, has labels
  86. {2, 2}, // pull-request, has labels
  87. {3, 2}, // pull-request, has no labels
  88. }
  89. for _, test := range tests {
  90. assert.NoError(t, PrepareTestDatabase())
  91. issue := AssertExistsAndLoadBean(t, &Issue{ID: test.issueID}).(*Issue)
  92. doer := AssertExistsAndLoadBean(t, &User{ID: test.doerID}).(*User)
  93. assert.NoError(t, issue.ClearLabels(doer))
  94. AssertNotExistsBean(t, &IssueLabel{IssueID: test.issueID})
  95. }
  96. }
  97. func TestUpdateIssueCols(t *testing.T) {
  98. assert.NoError(t, PrepareTestDatabase())
  99. issue := AssertExistsAndLoadBean(t, &Issue{}).(*Issue)
  100. const newTitle = "New Title for unit test"
  101. issue.Title = newTitle
  102. prevContent := issue.Content
  103. issue.Content = "This should have no effect"
  104. now := time.Now().Unix()
  105. assert.NoError(t, updateIssueCols(x, issue, "name"))
  106. then := time.Now().Unix()
  107. updatedIssue := AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)
  108. assert.EqualValues(t, newTitle, updatedIssue.Title)
  109. assert.EqualValues(t, prevContent, updatedIssue.Content)
  110. AssertInt64InRange(t, now, then, int64(updatedIssue.UpdatedUnix))
  111. }
  112. func TestIssues(t *testing.T) {
  113. assert.NoError(t, PrepareTestDatabase())
  114. for _, test := range []struct {
  115. Opts IssuesOptions
  116. ExpectedIssueIDs []int64
  117. }{
  118. {
  119. IssuesOptions{
  120. AssigneeID: 1,
  121. SortType: "oldest",
  122. },
  123. []int64{1, 6},
  124. },
  125. {
  126. IssuesOptions{
  127. RepoIDs: []int64{1, 3},
  128. SortType: "oldest",
  129. ListOptions: ListOptions{
  130. Page: 1,
  131. PageSize: 4,
  132. },
  133. },
  134. []int64{1, 2, 3, 5},
  135. },
  136. {
  137. IssuesOptions{
  138. LabelIDs: []int64{1},
  139. ListOptions: ListOptions{
  140. Page: 1,
  141. PageSize: 4,
  142. },
  143. },
  144. []int64{2, 1},
  145. },
  146. {
  147. IssuesOptions{
  148. LabelIDs: []int64{1, 2},
  149. ListOptions: ListOptions{
  150. Page: 1,
  151. PageSize: 4,
  152. },
  153. },
  154. []int64{}, // issues with **both** label 1 and 2, none of these issues matches, TODO: add more tests
  155. },
  156. } {
  157. issues, err := Issues(&test.Opts)
  158. assert.NoError(t, err)
  159. if assert.Len(t, issues, len(test.ExpectedIssueIDs)) {
  160. for i, issue := range issues {
  161. assert.EqualValues(t, test.ExpectedIssueIDs[i], issue.ID)
  162. }
  163. }
  164. }
  165. }
  166. func TestGetUserIssueStats(t *testing.T) {
  167. assert.NoError(t, PrepareTestDatabase())
  168. for _, test := range []struct {
  169. Opts UserIssueStatsOptions
  170. ExpectedIssueStats IssueStats
  171. }{
  172. {
  173. UserIssueStatsOptions{
  174. UserID: 1,
  175. RepoIDs: []int64{1},
  176. FilterMode: FilterModeAll,
  177. },
  178. IssueStats{
  179. YourRepositoriesCount: 0,
  180. AssignCount: 1,
  181. CreateCount: 1,
  182. OpenCount: 0,
  183. ClosedCount: 0,
  184. },
  185. },
  186. {
  187. UserIssueStatsOptions{
  188. UserID: 1,
  189. FilterMode: FilterModeAssign,
  190. },
  191. IssueStats{
  192. YourRepositoriesCount: 0,
  193. AssignCount: 2,
  194. CreateCount: 2,
  195. OpenCount: 2,
  196. ClosedCount: 0,
  197. },
  198. },
  199. {
  200. UserIssueStatsOptions{
  201. UserID: 1,
  202. FilterMode: FilterModeCreate,
  203. },
  204. IssueStats{
  205. YourRepositoriesCount: 0,
  206. AssignCount: 2,
  207. CreateCount: 2,
  208. OpenCount: 2,
  209. ClosedCount: 0,
  210. },
  211. },
  212. {
  213. UserIssueStatsOptions{
  214. UserID: 2,
  215. UserRepoIDs: []int64{1, 2},
  216. FilterMode: FilterModeAll,
  217. IsClosed: true,
  218. },
  219. IssueStats{
  220. YourRepositoriesCount: 2,
  221. AssignCount: 0,
  222. CreateCount: 2,
  223. OpenCount: 2,
  224. ClosedCount: 2,
  225. },
  226. },
  227. {
  228. UserIssueStatsOptions{
  229. UserID: 1,
  230. FilterMode: FilterModeMention,
  231. },
  232. IssueStats{
  233. YourRepositoriesCount: 0,
  234. AssignCount: 2,
  235. CreateCount: 2,
  236. OpenCount: 0,
  237. ClosedCount: 0,
  238. },
  239. },
  240. {
  241. UserIssueStatsOptions{
  242. UserID: 1,
  243. FilterMode: FilterModeCreate,
  244. IssueIDs: []int64{1},
  245. },
  246. IssueStats{
  247. YourRepositoriesCount: 0,
  248. AssignCount: 1,
  249. CreateCount: 1,
  250. OpenCount: 1,
  251. ClosedCount: 0,
  252. },
  253. },
  254. } {
  255. stats, err := GetUserIssueStats(test.Opts)
  256. if !assert.NoError(t, err) {
  257. continue
  258. }
  259. assert.Equal(t, test.ExpectedIssueStats, *stats)
  260. }
  261. }
  262. func TestIssue_loadTotalTimes(t *testing.T) {
  263. assert.NoError(t, PrepareTestDatabase())
  264. ms, err := GetIssueByID(2)
  265. assert.NoError(t, err)
  266. assert.NoError(t, ms.loadTotalTimes(x))
  267. assert.Equal(t, int64(3682), ms.TotalTrackedTime)
  268. }
  269. func TestIssue_SearchIssueIDsByKeyword(t *testing.T) {
  270. assert.NoError(t, PrepareTestDatabase())
  271. total, ids, err := SearchIssueIDsByKeyword("issue2", []int64{1}, 10, 0)
  272. assert.NoError(t, err)
  273. assert.EqualValues(t, 1, total)
  274. assert.EqualValues(t, []int64{2}, ids)
  275. total, ids, err = SearchIssueIDsByKeyword("first", []int64{1}, 10, 0)
  276. assert.NoError(t, err)
  277. assert.EqualValues(t, 1, total)
  278. assert.EqualValues(t, []int64{1}, ids)
  279. total, ids, err = SearchIssueIDsByKeyword("for", []int64{1}, 10, 0)
  280. assert.NoError(t, err)
  281. assert.EqualValues(t, 5, total)
  282. assert.ElementsMatch(t, []int64{1, 2, 3, 5, 11}, ids)
  283. // issue1's comment id 2
  284. total, ids, err = SearchIssueIDsByKeyword("good", []int64{1}, 10, 0)
  285. assert.NoError(t, err)
  286. assert.EqualValues(t, 1, total)
  287. assert.EqualValues(t, []int64{1}, ids)
  288. }
  289. func TestGetRepoIDsForIssuesOptions(t *testing.T) {
  290. assert.NoError(t, PrepareTestDatabase())
  291. user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  292. for _, test := range []struct {
  293. Opts IssuesOptions
  294. ExpectedRepoIDs []int64
  295. }{
  296. {
  297. IssuesOptions{
  298. AssigneeID: 2,
  299. },
  300. []int64{3},
  301. },
  302. {
  303. IssuesOptions{
  304. RepoIDs: []int64{1, 2},
  305. },
  306. []int64{1, 2},
  307. },
  308. } {
  309. repoIDs, err := GetRepoIDsForIssuesOptions(&test.Opts, user)
  310. assert.NoError(t, err)
  311. if assert.Len(t, repoIDs, len(test.ExpectedRepoIDs)) {
  312. for i, repoID := range repoIDs {
  313. assert.EqualValues(t, test.ExpectedRepoIDs[i], repoID)
  314. }
  315. }
  316. }
  317. }
  318. func testInsertIssue(t *testing.T, title, content string) {
  319. repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  320. user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  321. issue := Issue{
  322. RepoID: repo.ID,
  323. PosterID: user.ID,
  324. Title: title,
  325. Content: content,
  326. }
  327. err := NewIssue(repo, &issue, nil, nil)
  328. assert.NoError(t, err)
  329. var newIssue Issue
  330. has, err := x.ID(issue.ID).Get(&newIssue)
  331. assert.NoError(t, err)
  332. assert.True(t, has)
  333. assert.EqualValues(t, issue.Title, newIssue.Title)
  334. assert.EqualValues(t, issue.Content, newIssue.Content)
  335. // there are 5 issues and max index is 5 on repository 1, so this one should 6
  336. assert.EqualValues(t, 6, newIssue.Index)
  337. _, err = x.ID(issue.ID).Delete(new(Issue))
  338. assert.NoError(t, err)
  339. }
  340. func TestIssue_InsertIssue(t *testing.T) {
  341. assert.NoError(t, PrepareTestDatabase())
  342. testInsertIssue(t, "my issue1", "special issue's comments?")
  343. testInsertIssue(t, `my issue2, this is my son's love \n \r \ `, "special issue's '' comments?")
  344. }
  345. func TestIssue_ResolveMentions(t *testing.T) {
  346. assert.NoError(t, PrepareTestDatabase())
  347. testSuccess := func(owner, repo, doer string, mentions []string, expected []int64) {
  348. o := AssertExistsAndLoadBean(t, &User{LowerName: owner}).(*User)
  349. r := AssertExistsAndLoadBean(t, &Repository{OwnerID: o.ID, LowerName: repo}).(*Repository)
  350. issue := &Issue{RepoID: r.ID}
  351. d := AssertExistsAndLoadBean(t, &User{LowerName: doer}).(*User)
  352. resolved, err := issue.ResolveMentionsByVisibility(DefaultDBContext(), d, mentions)
  353. assert.NoError(t, err)
  354. ids := make([]int64, len(resolved))
  355. for i, user := range resolved {
  356. ids[i] = user.ID
  357. }
  358. sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
  359. assert.EqualValues(t, expected, ids)
  360. }
  361. // Public repo, existing user
  362. testSuccess("user2", "repo1", "user1", []string{"user5"}, []int64{5})
  363. // Public repo, non-existing user
  364. testSuccess("user2", "repo1", "user1", []string{"nonexisting"}, []int64{})
  365. // Public repo, doer
  366. testSuccess("user2", "repo1", "user1", []string{"user1"}, []int64{})
  367. // Private repo, team member
  368. testSuccess("user17", "big_test_private_4", "user20", []string{"user2"}, []int64{2})
  369. // Private repo, not a team member
  370. testSuccess("user17", "big_test_private_4", "user20", []string{"user5"}, []int64{})
  371. // Private repo, whole team
  372. testSuccess("user17", "big_test_private_4", "user15", []string{"user17/owners"}, []int64{18})
  373. }