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.

380 lines
12 KiB

Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
2 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
2 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
2 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
2 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
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
2 years ago
Add Organization Wide Labels (#10814) * Add organization wide labels Implement organization wide labels similar to organization wide webhooks. This lets you create individual labels for organizations that can be used for all repos under that organization (so being able to reuse the same label across multiple repos). This makes it possible for small organizations with many repos to use labels effectively. Fixes #7406 * Add migration * remove comments * fix tests * Update options/locale/locale_en-US.ini Removed unused translation string * show org labels in issue search label filter * Use more clear var name * rename migration after merge from master * comment typo * update migration again after rebase with master * check for orgID <=0 per guillep2k review * fmt * Apply suggestions from code review Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * remove unused code * Make sure RepoID is 0 when searching orgID per code review * more changes/code review requests * More descriptive translation var per code review * func description/delete comment when issue label deleted instead of hiding it * remove comment * only use issues in that repo when calculating number of open issues for org label on repo label page * Add integration test for IssuesSearch API with labels * remove unused function * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Use subquery in GetLabelIDsInReposByNames * Fix tests to use correct orgID * fix more tests * IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well * update comment for clarity * Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition * Don't sort repos by date in IssuesSearch API After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45 Returns different results for MySQL than other engines. However, the similar query: SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30 Returns the same results. This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function. * linter is back! * code review * remove now unused option * Fix newline at end of files * more unused code * update to master * check for matching ids before query * Update models/issue_label.go Co-Authored-By: 6543 <6543@obermui.de> * Update models/issue_label.go * update comments * Update routers/org/setting.go Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
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. "html/template"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. // TODO TestGetLabelTemplateFile
  11. func TestLabel_CalOpenIssues(t *testing.T) {
  12. assert.NoError(t, PrepareTestDatabase())
  13. label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  14. label.CalOpenIssues()
  15. assert.EqualValues(t, 2, label.NumOpenIssues)
  16. }
  17. func TestLabel_ForegroundColor(t *testing.T) {
  18. assert.NoError(t, PrepareTestDatabase())
  19. label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  20. assert.Equal(t, template.CSS("#000"), label.ForegroundColor())
  21. label = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  22. assert.Equal(t, template.CSS("#fff"), label.ForegroundColor())
  23. }
  24. func TestNewLabels(t *testing.T) {
  25. assert.NoError(t, PrepareTestDatabase())
  26. labels := []*Label{
  27. {RepoID: 2, Name: "labelName2", Color: "#123456"},
  28. {RepoID: 3, Name: "labelName3", Color: "#23456F"},
  29. }
  30. assert.Error(t, NewLabel(&Label{RepoID: 3, Name: "invalid Color", Color: ""}))
  31. assert.Error(t, NewLabel(&Label{RepoID: 3, Name: "invalid Color", Color: "123456"}))
  32. assert.Error(t, NewLabel(&Label{RepoID: 3, Name: "invalid Color", Color: "#12345G"}))
  33. for _, label := range labels {
  34. AssertNotExistsBean(t, label)
  35. }
  36. assert.NoError(t, NewLabels(labels...))
  37. for _, label := range labels {
  38. AssertExistsAndLoadBean(t, label, Cond("id = ?", label.ID))
  39. }
  40. CheckConsistencyFor(t, &Label{}, &Repository{})
  41. }
  42. func TestGetLabelByID(t *testing.T) {
  43. assert.NoError(t, PrepareTestDatabase())
  44. label, err := GetLabelByID(1)
  45. assert.NoError(t, err)
  46. assert.EqualValues(t, 1, label.ID)
  47. _, err = GetLabelByID(NonexistentID)
  48. assert.True(t, IsErrLabelNotExist(err))
  49. }
  50. func TestGetLabelInRepoByName(t *testing.T) {
  51. assert.NoError(t, PrepareTestDatabase())
  52. label, err := GetLabelInRepoByName(1, "label1")
  53. assert.NoError(t, err)
  54. assert.EqualValues(t, 1, label.ID)
  55. assert.Equal(t, "label1", label.Name)
  56. _, err = GetLabelInRepoByName(1, "")
  57. assert.True(t, IsErrRepoLabelNotExist(err))
  58. _, err = GetLabelInRepoByName(NonexistentID, "nonexistent")
  59. assert.True(t, IsErrRepoLabelNotExist(err))
  60. }
  61. func TestGetLabelInRepoByNames(t *testing.T) {
  62. assert.NoError(t, PrepareTestDatabase())
  63. labelIDs, err := GetLabelIDsInRepoByNames(1, []string{"label1", "label2"})
  64. assert.NoError(t, err)
  65. assert.Len(t, labelIDs, 2)
  66. assert.Equal(t, int64(1), labelIDs[0])
  67. assert.Equal(t, int64(2), labelIDs[1])
  68. }
  69. func TestGetLabelInRepoByNamesDiscardsNonExistentLabels(t *testing.T) {
  70. assert.NoError(t, PrepareTestDatabase())
  71. // label3 doesn't exists.. See labels.yml
  72. labelIDs, err := GetLabelIDsInRepoByNames(1, []string{"label1", "label2", "label3"})
  73. assert.NoError(t, err)
  74. assert.Len(t, labelIDs, 2)
  75. assert.Equal(t, int64(1), labelIDs[0])
  76. assert.Equal(t, int64(2), labelIDs[1])
  77. assert.NoError(t, err)
  78. }
  79. func TestGetLabelInRepoByID(t *testing.T) {
  80. assert.NoError(t, PrepareTestDatabase())
  81. label, err := GetLabelInRepoByID(1, 1)
  82. assert.NoError(t, err)
  83. assert.EqualValues(t, 1, label.ID)
  84. _, err = GetLabelInRepoByID(1, -1)
  85. assert.True(t, IsErrRepoLabelNotExist(err))
  86. _, err = GetLabelInRepoByID(NonexistentID, NonexistentID)
  87. assert.True(t, IsErrRepoLabelNotExist(err))
  88. }
  89. func TestGetLabelsInRepoByIDs(t *testing.T) {
  90. assert.NoError(t, PrepareTestDatabase())
  91. labels, err := GetLabelsInRepoByIDs(1, []int64{1, 2, NonexistentID})
  92. assert.NoError(t, err)
  93. if assert.Len(t, labels, 2) {
  94. assert.EqualValues(t, 1, labels[0].ID)
  95. assert.EqualValues(t, 2, labels[1].ID)
  96. }
  97. }
  98. func TestGetLabelsByRepoID(t *testing.T) {
  99. assert.NoError(t, PrepareTestDatabase())
  100. testSuccess := func(repoID int64, sortType string, expectedIssueIDs []int64) {
  101. labels, err := GetLabelsByRepoID(repoID, sortType, ListOptions{})
  102. assert.NoError(t, err)
  103. assert.Len(t, labels, len(expectedIssueIDs))
  104. for i, label := range labels {
  105. assert.EqualValues(t, expectedIssueIDs[i], label.ID)
  106. }
  107. }
  108. testSuccess(1, "leastissues", []int64{2, 1})
  109. testSuccess(1, "mostissues", []int64{1, 2})
  110. testSuccess(1, "reversealphabetically", []int64{2, 1})
  111. testSuccess(1, "default", []int64{1, 2})
  112. }
  113. // Org vrsions
  114. func TestGetLabelInOrgByName(t *testing.T) {
  115. assert.NoError(t, PrepareTestDatabase())
  116. label, err := GetLabelInOrgByName(3, "orglabel3")
  117. assert.NoError(t, err)
  118. assert.EqualValues(t, 3, label.ID)
  119. assert.Equal(t, "orglabel3", label.Name)
  120. _, err = GetLabelInOrgByName(3, "")
  121. assert.True(t, IsErrOrgLabelNotExist(err))
  122. _, err = GetLabelInOrgByName(0, "orglabel3")
  123. assert.True(t, IsErrOrgLabelNotExist(err))
  124. _, err = GetLabelInOrgByName(-1, "orglabel3")
  125. assert.True(t, IsErrOrgLabelNotExist(err))
  126. _, err = GetLabelInOrgByName(NonexistentID, "nonexistent")
  127. assert.True(t, IsErrOrgLabelNotExist(err))
  128. }
  129. func TestGetLabelInOrgByNames(t *testing.T) {
  130. assert.NoError(t, PrepareTestDatabase())
  131. labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4"})
  132. assert.NoError(t, err)
  133. assert.Len(t, labelIDs, 2)
  134. assert.Equal(t, int64(3), labelIDs[0])
  135. assert.Equal(t, int64(4), labelIDs[1])
  136. }
  137. func TestGetLabelInOrgByNamesDiscardsNonExistentLabels(t *testing.T) {
  138. assert.NoError(t, PrepareTestDatabase())
  139. // orglabel99 doesn't exists.. See labels.yml
  140. labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4", "orglabel99"})
  141. assert.NoError(t, err)
  142. assert.Len(t, labelIDs, 2)
  143. assert.Equal(t, int64(3), labelIDs[0])
  144. assert.Equal(t, int64(4), labelIDs[1])
  145. assert.NoError(t, err)
  146. }
  147. func TestGetLabelInOrgByID(t *testing.T) {
  148. assert.NoError(t, PrepareTestDatabase())
  149. label, err := GetLabelInOrgByID(3, 3)
  150. assert.NoError(t, err)
  151. assert.EqualValues(t, 3, label.ID)
  152. _, err = GetLabelInOrgByID(3, -1)
  153. assert.True(t, IsErrOrgLabelNotExist(err))
  154. _, err = GetLabelInOrgByID(0, 3)
  155. assert.True(t, IsErrOrgLabelNotExist(err))
  156. _, err = GetLabelInOrgByID(-1, 3)
  157. assert.True(t, IsErrOrgLabelNotExist(err))
  158. _, err = GetLabelInOrgByID(NonexistentID, NonexistentID)
  159. assert.True(t, IsErrOrgLabelNotExist(err))
  160. }
  161. func TestGetLabelsInOrgByIDs(t *testing.T) {
  162. assert.NoError(t, PrepareTestDatabase())
  163. labels, err := GetLabelsInOrgByIDs(3, []int64{3, 4, NonexistentID})
  164. assert.NoError(t, err)
  165. if assert.Len(t, labels, 2) {
  166. assert.EqualValues(t, 3, labels[0].ID)
  167. assert.EqualValues(t, 4, labels[1].ID)
  168. }
  169. }
  170. func TestGetLabelsByOrgID(t *testing.T) {
  171. assert.NoError(t, PrepareTestDatabase())
  172. testSuccess := func(orgID int64, sortType string, expectedIssueIDs []int64) {
  173. labels, err := GetLabelsByOrgID(orgID, sortType, ListOptions{})
  174. assert.NoError(t, err)
  175. assert.Len(t, labels, len(expectedIssueIDs))
  176. for i, label := range labels {
  177. assert.EqualValues(t, expectedIssueIDs[i], label.ID)
  178. }
  179. }
  180. testSuccess(3, "leastissues", []int64{3, 4})
  181. testSuccess(3, "mostissues", []int64{4, 3})
  182. testSuccess(3, "reversealphabetically", []int64{4, 3})
  183. testSuccess(3, "default", []int64{3, 4})
  184. var err error
  185. _, err = GetLabelsByOrgID(0, "leastissues", ListOptions{})
  186. assert.True(t, IsErrOrgLabelNotExist(err))
  187. _, err = GetLabelsByOrgID(-1, "leastissues", ListOptions{})
  188. assert.True(t, IsErrOrgLabelNotExist(err))
  189. }
  190. //
  191. func TestGetLabelsByIssueID(t *testing.T) {
  192. assert.NoError(t, PrepareTestDatabase())
  193. labels, err := GetLabelsByIssueID(1)
  194. assert.NoError(t, err)
  195. if assert.Len(t, labels, 1) {
  196. assert.EqualValues(t, 1, labels[0].ID)
  197. }
  198. labels, err = GetLabelsByIssueID(NonexistentID)
  199. assert.NoError(t, err)
  200. assert.Len(t, labels, 0)
  201. }
  202. func TestUpdateLabel(t *testing.T) {
  203. assert.NoError(t, PrepareTestDatabase())
  204. label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  205. // make sure update wont overwrite it
  206. update := &Label{
  207. ID: label.ID,
  208. Color: "#ffff00",
  209. Name: "newLabelName",
  210. Description: label.Description,
  211. }
  212. label.Color = update.Color
  213. label.Name = update.Name
  214. assert.NoError(t, UpdateLabel(update))
  215. newLabel := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  216. assert.EqualValues(t, label.ID, newLabel.ID)
  217. assert.EqualValues(t, label.Color, newLabel.Color)
  218. assert.EqualValues(t, label.Name, newLabel.Name)
  219. assert.EqualValues(t, label.Description, newLabel.Description)
  220. CheckConsistencyFor(t, &Label{}, &Repository{})
  221. }
  222. func TestDeleteLabel(t *testing.T) {
  223. assert.NoError(t, PrepareTestDatabase())
  224. label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  225. assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
  226. AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
  227. assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
  228. AssertNotExistsBean(t, &Label{ID: label.ID})
  229. assert.NoError(t, DeleteLabel(NonexistentID, NonexistentID))
  230. CheckConsistencyFor(t, &Label{}, &Repository{})
  231. }
  232. func TestHasIssueLabel(t *testing.T) {
  233. assert.NoError(t, PrepareTestDatabase())
  234. assert.True(t, HasIssueLabel(1, 1))
  235. assert.False(t, HasIssueLabel(1, 2))
  236. assert.False(t, HasIssueLabel(NonexistentID, NonexistentID))
  237. }
  238. func TestNewIssueLabel(t *testing.T) {
  239. assert.NoError(t, PrepareTestDatabase())
  240. label := AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  241. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  242. doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  243. // add new IssueLabel
  244. prevNumIssues := label.NumIssues
  245. assert.NoError(t, NewIssueLabel(issue, label, doer))
  246. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
  247. AssertExistsAndLoadBean(t, &Comment{
  248. Type: CommentTypeLabel,
  249. PosterID: doer.ID,
  250. IssueID: issue.ID,
  251. LabelID: label.ID,
  252. Content: "1",
  253. })
  254. label = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  255. assert.EqualValues(t, prevNumIssues+1, label.NumIssues)
  256. // re-add existing IssueLabel
  257. assert.NoError(t, NewIssueLabel(issue, label, doer))
  258. CheckConsistencyFor(t, &Issue{}, &Label{})
  259. }
  260. func TestNewIssueLabels(t *testing.T) {
  261. assert.NoError(t, PrepareTestDatabase())
  262. label1 := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  263. label2 := AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  264. issue := AssertExistsAndLoadBean(t, &Issue{ID: 5}).(*Issue)
  265. doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  266. assert.NoError(t, NewIssueLabels(issue, []*Label{label1, label2}, doer))
  267. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
  268. AssertExistsAndLoadBean(t, &Comment{
  269. Type: CommentTypeLabel,
  270. PosterID: doer.ID,
  271. IssueID: issue.ID,
  272. LabelID: label1.ID,
  273. Content: "1",
  274. })
  275. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
  276. label1 = AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  277. assert.EqualValues(t, 3, label1.NumIssues)
  278. assert.EqualValues(t, 1, label1.NumClosedIssues)
  279. label2 = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  280. assert.EqualValues(t, 1, label2.NumIssues)
  281. assert.EqualValues(t, 1, label2.NumClosedIssues)
  282. // corner case: test empty slice
  283. assert.NoError(t, NewIssueLabels(issue, []*Label{}, doer))
  284. CheckConsistencyFor(t, &Issue{}, &Label{})
  285. }
  286. func TestDeleteIssueLabel(t *testing.T) {
  287. assert.NoError(t, PrepareTestDatabase())
  288. testSuccess := func(labelID, issueID, doerID int64) {
  289. label := AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
  290. issue := AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
  291. doer := AssertExistsAndLoadBean(t, &User{ID: doerID}).(*User)
  292. expectedNumIssues := label.NumIssues
  293. expectedNumClosedIssues := label.NumClosedIssues
  294. if BeanExists(t, &IssueLabel{IssueID: issueID, LabelID: labelID}) {
  295. expectedNumIssues--
  296. if issue.IsClosed {
  297. expectedNumClosedIssues--
  298. }
  299. }
  300. assert.NoError(t, DeleteIssueLabel(issue, label, doer))
  301. AssertNotExistsBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
  302. AssertExistsAndLoadBean(t, &Comment{
  303. Type: CommentTypeLabel,
  304. PosterID: doerID,
  305. IssueID: issueID,
  306. LabelID: labelID,
  307. }, `content=""`)
  308. label = AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
  309. assert.EqualValues(t, expectedNumIssues, label.NumIssues)
  310. assert.EqualValues(t, expectedNumClosedIssues, label.NumClosedIssues)
  311. }
  312. testSuccess(1, 1, 2)
  313. testSuccess(2, 5, 2)
  314. testSuccess(1, 1, 2) // delete non-existent IssueLabel
  315. CheckConsistencyFor(t, &Issue{}, &Label{})
  316. }