Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

issue_label_test.go 12KB

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>
il y a 4 ans
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>
il y a 4 ans
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>
il y a 4 ans
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>
il y a 4 ans
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>
il y a 4 ans
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>
il y a 4 ans
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>
il y a 4 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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.Equal(t, *label, *newLabel)
  217. CheckConsistencyFor(t, &Label{}, &Repository{})
  218. }
  219. func TestDeleteLabel(t *testing.T) {
  220. assert.NoError(t, PrepareTestDatabase())
  221. label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  222. assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
  223. AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
  224. assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
  225. AssertNotExistsBean(t, &Label{ID: label.ID})
  226. assert.NoError(t, DeleteLabel(NonexistentID, NonexistentID))
  227. CheckConsistencyFor(t, &Label{}, &Repository{})
  228. }
  229. func TestHasIssueLabel(t *testing.T) {
  230. assert.NoError(t, PrepareTestDatabase())
  231. assert.True(t, HasIssueLabel(1, 1))
  232. assert.False(t, HasIssueLabel(1, 2))
  233. assert.False(t, HasIssueLabel(NonexistentID, NonexistentID))
  234. }
  235. func TestNewIssueLabel(t *testing.T) {
  236. assert.NoError(t, PrepareTestDatabase())
  237. label := AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  238. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  239. doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  240. // add new IssueLabel
  241. prevNumIssues := label.NumIssues
  242. assert.NoError(t, NewIssueLabel(issue, label, doer))
  243. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
  244. AssertExistsAndLoadBean(t, &Comment{
  245. Type: CommentTypeLabel,
  246. PosterID: doer.ID,
  247. IssueID: issue.ID,
  248. LabelID: label.ID,
  249. Content: "1",
  250. })
  251. label = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  252. assert.EqualValues(t, prevNumIssues+1, label.NumIssues)
  253. // re-add existing IssueLabel
  254. assert.NoError(t, NewIssueLabel(issue, label, doer))
  255. CheckConsistencyFor(t, &Issue{}, &Label{})
  256. }
  257. func TestNewIssueLabels(t *testing.T) {
  258. assert.NoError(t, PrepareTestDatabase())
  259. label1 := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  260. label2 := AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  261. issue := AssertExistsAndLoadBean(t, &Issue{ID: 5}).(*Issue)
  262. doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  263. assert.NoError(t, NewIssueLabels(issue, []*Label{label1, label2}, doer))
  264. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
  265. AssertExistsAndLoadBean(t, &Comment{
  266. Type: CommentTypeLabel,
  267. PosterID: doer.ID,
  268. IssueID: issue.ID,
  269. LabelID: label1.ID,
  270. Content: "1",
  271. })
  272. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
  273. label1 = AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
  274. assert.EqualValues(t, 3, label1.NumIssues)
  275. assert.EqualValues(t, 1, label1.NumClosedIssues)
  276. label2 = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
  277. assert.EqualValues(t, 1, label2.NumIssues)
  278. assert.EqualValues(t, 1, label2.NumClosedIssues)
  279. // corner case: test empty slice
  280. assert.NoError(t, NewIssueLabels(issue, []*Label{}, doer))
  281. CheckConsistencyFor(t, &Issue{}, &Label{})
  282. }
  283. func TestDeleteIssueLabel(t *testing.T) {
  284. assert.NoError(t, PrepareTestDatabase())
  285. testSuccess := func(labelID, issueID, doerID int64) {
  286. label := AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
  287. issue := AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
  288. doer := AssertExistsAndLoadBean(t, &User{ID: doerID}).(*User)
  289. expectedNumIssues := label.NumIssues
  290. expectedNumClosedIssues := label.NumClosedIssues
  291. if BeanExists(t, &IssueLabel{IssueID: issueID, LabelID: labelID}) {
  292. expectedNumIssues--
  293. if issue.IsClosed {
  294. expectedNumClosedIssues--
  295. }
  296. }
  297. assert.NoError(t, DeleteIssueLabel(issue, label, doer))
  298. AssertNotExistsBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
  299. AssertExistsAndLoadBean(t, &Comment{
  300. Type: CommentTypeLabel,
  301. PosterID: doerID,
  302. IssueID: issueID,
  303. LabelID: labelID,
  304. }, `content=""`)
  305. label = AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
  306. assert.EqualValues(t, expectedNumIssues, label.NumIssues)
  307. assert.EqualValues(t, expectedNumClosedIssues, label.NumClosedIssues)
  308. }
  309. testSuccess(1, 1, 2)
  310. testSuccess(2, 5, 2)
  311. testSuccess(1, 1, 2) // delete non-existent IssueLabel
  312. CheckConsistencyFor(t, &Issue{}, &Label{})
  313. }