2016-02-27 16:31:24 +00:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
2020-01-24 19:00:29 +00:00
|
|
|
// Copyright 2020 The Gitea Authors.
|
2016-02-27 16:31:24 +00:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"html/template"
|
2016-08-30 03:00:06 +00:00
|
|
|
"regexp"
|
2016-02-27 16:31:24 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2020-10-13 00:01:57 +00:00
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
|
2019-09-24 13:22:39 +00:00
|
|
|
"xorm.io/builder"
|
2019-10-17 09:26:49 +00:00
|
|
|
"xorm.io/xorm"
|
2016-02-27 16:31:24 +00:00
|
|
|
)
|
|
|
|
|
2020-02-09 14:33:03 +00:00
|
|
|
// LabelColorPattern is a regexp witch can validate LabelColor
|
|
|
|
var LabelColorPattern = regexp.MustCompile("^#[0-9a-fA-F]{6}$")
|
|
|
|
|
|
|
|
// Label represents a label of repository for issues.
|
|
|
|
type Label struct {
|
2020-10-13 00:01:57 +00:00
|
|
|
ID int64 `xorm:"pk autoincr"`
|
|
|
|
RepoID int64 `xorm:"INDEX"`
|
|
|
|
OrgID int64 `xorm:"INDEX"`
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Color string `xorm:"VARCHAR(7)"`
|
|
|
|
NumIssues int
|
|
|
|
NumClosedIssues int
|
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
NumOpenIssues int `xorm:"-"`
|
|
|
|
NumOpenRepoIssues int64 `xorm:"-"`
|
|
|
|
IsChecked bool `xorm:"-"`
|
|
|
|
QueryString string `xorm:"-"`
|
|
|
|
IsSelected bool `xorm:"-"`
|
|
|
|
IsExcluded bool `xorm:"-"`
|
2020-02-09 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 03:00:06 +00:00
|
|
|
// GetLabelTemplateFile loads the label template file by given name,
|
2018-03-13 02:03:55 +00:00
|
|
|
// then parses and returns a list of name-color pairs and optionally description.
|
|
|
|
func GetLabelTemplateFile(name string) ([][3]string, error) {
|
2020-01-12 12:11:17 +00:00
|
|
|
data, err := GetRepoInitFile("label", name)
|
2016-08-30 03:00:06 +00:00
|
|
|
if err != nil {
|
2021-01-18 20:00:50 +00:00
|
|
|
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %v", err)}
|
2016-08-30 03:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lines := strings.Split(string(data), "\n")
|
2018-03-13 02:03:55 +00:00
|
|
|
list := make([][3]string, 0, len(lines))
|
2016-08-30 03:00:06 +00:00
|
|
|
for i := 0; i < len(lines); i++ {
|
|
|
|
line := strings.TrimSpace(lines[i])
|
|
|
|
if len(line) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-03-13 02:03:55 +00:00
|
|
|
parts := strings.SplitN(line, ";", 2)
|
|
|
|
|
|
|
|
fields := strings.SplitN(parts[0], " ", 2)
|
2016-08-30 03:00:06 +00:00
|
|
|
if len(fields) != 2 {
|
2021-01-18 20:00:50 +00:00
|
|
|
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("line is malformed: %s", line)}
|
2016-08-30 03:00:06 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 14:33:03 +00:00
|
|
|
color := strings.Trim(fields[0], " ")
|
|
|
|
if len(color) == 6 {
|
|
|
|
color = "#" + color
|
|
|
|
}
|
|
|
|
if !LabelColorPattern.MatchString(color) {
|
2021-01-18 20:00:50 +00:00
|
|
|
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("bad HTML color code in line: %s", line)}
|
2016-08-30 03:00:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 02:03:55 +00:00
|
|
|
var description string
|
|
|
|
|
|
|
|
if len(parts) > 1 {
|
|
|
|
description = strings.TrimSpace(parts[1])
|
|
|
|
}
|
|
|
|
|
2016-08-30 03:00:06 +00:00
|
|
|
fields[1] = strings.TrimSpace(fields[1])
|
2020-02-09 14:33:03 +00:00
|
|
|
list = append(list, [3]string{fields[1], color, description})
|
2016-08-30 03:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return list, nil
|
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// CalOpenIssues sets the number of open issues of a label based on the already stored number of closed issues.
|
2016-08-14 10:32:24 +00:00
|
|
|
func (label *Label) CalOpenIssues() {
|
|
|
|
label.NumOpenIssues = label.NumIssues - label.NumClosedIssues
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// CalOpenOrgIssues calculates the open issues of a label for a specific repo
|
|
|
|
func (label *Label) CalOpenOrgIssues(repoID, labelID int64) {
|
|
|
|
repoIDs := []int64{repoID}
|
|
|
|
labelIDs := []int64{labelID}
|
|
|
|
|
|
|
|
counts, _ := CountIssuesByRepo(&IssuesOptions{
|
|
|
|
RepoIDs: repoIDs,
|
|
|
|
LabelIDs: labelIDs,
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, count := range counts {
|
|
|
|
label.NumOpenRepoIssues += count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 04:10:38 +00:00
|
|
|
// LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked
|
|
|
|
func (label *Label) LoadSelectedLabelsAfterClick(currentSelectedLabels []int64) {
|
|
|
|
var labelQuerySlice []string
|
|
|
|
labelSelected := false
|
|
|
|
labelID := strconv.FormatInt(label.ID, 10)
|
|
|
|
for _, s := range currentSelectedLabels {
|
|
|
|
if s == label.ID {
|
|
|
|
labelSelected = true
|
2019-10-23 16:29:14 +00:00
|
|
|
} else if -s == label.ID {
|
|
|
|
labelSelected = true
|
|
|
|
label.IsExcluded = true
|
|
|
|
} else if s != 0 {
|
2019-01-23 04:10:38 +00:00
|
|
|
labelQuerySlice = append(labelQuerySlice, strconv.FormatInt(s, 10))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !labelSelected {
|
|
|
|
labelQuerySlice = append(labelQuerySlice, labelID)
|
|
|
|
}
|
|
|
|
label.IsSelected = labelSelected
|
|
|
|
label.QueryString = strings.Join(labelQuerySlice, ",")
|
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// BelongsToOrg returns true if label is an organization label
|
|
|
|
func (label *Label) BelongsToOrg() bool {
|
|
|
|
return label.OrgID > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// BelongsToRepo returns true if label is a repository label
|
|
|
|
func (label *Label) BelongsToRepo() bool {
|
|
|
|
return label.RepoID > 0
|
|
|
|
}
|
|
|
|
|
2016-02-27 16:31:24 +00:00
|
|
|
// ForegroundColor calculates the text color for labels based
|
|
|
|
// on their background color.
|
2016-11-25 08:11:12 +00:00
|
|
|
func (label *Label) ForegroundColor() template.CSS {
|
|
|
|
if strings.HasPrefix(label.Color, "#") {
|
|
|
|
if color, err := strconv.ParseUint(label.Color[1:], 16, 64); err == nil {
|
2016-02-27 16:31:24 +00:00
|
|
|
r := float32(0xFF & (color >> 16))
|
|
|
|
g := float32(0xFF & (color >> 8))
|
|
|
|
b := float32(0xFF & color)
|
|
|
|
luminance := (0.2126*r + 0.7152*g + 0.0722*b) / 255
|
|
|
|
|
2016-08-27 19:44:39 +00:00
|
|
|
if luminance < 0.66 {
|
2016-02-27 16:31:24 +00:00
|
|
|
return template.CSS("#fff")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// default to black
|
|
|
|
return template.CSS("#000")
|
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// .____ ___. .__
|
|
|
|
// | | _____ \_ |__ ____ | |
|
|
|
|
// | | \__ \ | __ \_/ __ \| |
|
|
|
|
// | |___ / __ \| \_\ \ ___/| |__
|
|
|
|
// >_______ (____ /___ /\___ >____/
|
|
|
|
|
2019-12-07 02:13:19 +00:00
|
|
|
func loadLabels(labelTemplate string) ([]string, error) {
|
|
|
|
list, err := GetLabelTemplateFile(labelTemplate)
|
|
|
|
if err != nil {
|
2021-01-18 20:00:50 +00:00
|
|
|
return nil, err
|
2019-12-07 02:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
labels := make([]string, len(list))
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
labels[i] = list[i][0]
|
|
|
|
}
|
|
|
|
return labels, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadLabelsFormatted loads the labels' list of a template file as a string separated by comma
|
|
|
|
func LoadLabelsFormatted(labelTemplate string) (string, error) {
|
|
|
|
labels, err := loadLabels(labelTemplate)
|
|
|
|
return strings.Join(labels, ", "), err
|
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
func initializeLabels(e Engine, id int64, labelTemplate string, isOrg bool) error {
|
2019-09-08 08:28:40 +00:00
|
|
|
list, err := GetLabelTemplateFile(labelTemplate)
|
|
|
|
if err != nil {
|
2021-01-18 20:00:50 +00:00
|
|
|
return err
|
2019-09-08 08:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
labels := make([]*Label, len(list))
|
|
|
|
for i := 0; i < len(list); i++ {
|
|
|
|
labels[i] = &Label{
|
|
|
|
Name: list[i][0],
|
|
|
|
Description: list[i][2],
|
|
|
|
Color: list[i][1],
|
|
|
|
}
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
if isOrg {
|
|
|
|
labels[i].OrgID = id
|
|
|
|
} else {
|
|
|
|
labels[i].RepoID = id
|
|
|
|
}
|
2019-09-08 08:28:40 +00:00
|
|
|
}
|
|
|
|
for _, label := range labels {
|
|
|
|
if err = newLabel(e, label); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-09 14:33:03 +00:00
|
|
|
// InitializeLabels adds a label set to a repository using a template
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
func InitializeLabels(ctx DBContext, repoID int64, labelTemplate string, isOrg bool) error {
|
|
|
|
return initializeLabels(ctx.e, repoID, labelTemplate, isOrg)
|
2019-09-08 08:28:40 +00:00
|
|
|
}
|
|
|
|
|
2017-06-25 06:15:09 +00:00
|
|
|
func newLabel(e Engine, label *Label) error {
|
|
|
|
_, err := e.Insert(label)
|
2016-02-27 16:31:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// NewLabel creates a new label
|
2017-06-25 06:15:09 +00:00
|
|
|
func NewLabel(label *Label) error {
|
2020-02-09 14:33:03 +00:00
|
|
|
if !LabelColorPattern.MatchString(label.Color) {
|
|
|
|
return fmt.Errorf("bad color code: %s", label.Color)
|
|
|
|
}
|
2017-06-25 06:15:09 +00:00
|
|
|
return newLabel(x, label)
|
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// NewLabels creates new labels
|
2017-06-25 06:15:09 +00:00
|
|
|
func NewLabels(labels ...*Label) error {
|
|
|
|
sess := x.NewSession()
|
|
|
|
defer sess.Close()
|
|
|
|
if err := sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, label := range labels {
|
2020-02-09 14:33:03 +00:00
|
|
|
if !LabelColorPattern.MatchString(label.Color) {
|
|
|
|
return fmt.Errorf("bad color code: %s", label.Color)
|
|
|
|
}
|
2017-06-25 06:15:09 +00:00
|
|
|
if err := newLabel(sess, label); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sess.Commit()
|
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// UpdateLabel updates label information.
|
|
|
|
func UpdateLabel(l *Label) error {
|
|
|
|
if !LabelColorPattern.MatchString(l.Color) {
|
|
|
|
return fmt.Errorf("bad color code: %s", l.Color)
|
|
|
|
}
|
2020-04-28 23:28:56 +00:00
|
|
|
return updateLabelCols(x, l, "name", "description", "color")
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteLabel delete a label
|
|
|
|
func DeleteLabel(id, labelID int64) error {
|
|
|
|
|
|
|
|
label, err := GetLabelByID(labelID)
|
|
|
|
if err != nil {
|
|
|
|
if IsErrLabelNotExist(err) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sess := x.NewSession()
|
|
|
|
defer sess.Close()
|
|
|
|
if err = sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if label.BelongsToOrg() && label.OrgID != id {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if label.BelongsToRepo() && label.RepoID != id {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err = sess.ID(labelID).Delete(new(Label)); err != nil {
|
|
|
|
return err
|
|
|
|
} else if _, err = sess.
|
|
|
|
Where("label_id = ?", labelID).
|
|
|
|
Delete(new(IssueLabel)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete comments about now deleted label_id
|
|
|
|
if _, err = sess.Where("label_id = ?", labelID).Cols("label_id").Delete(&Comment{}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sess.Commit()
|
|
|
|
}
|
|
|
|
|
|
|
|
// getLabelByID returns a label by label id
|
|
|
|
func getLabelByID(e Engine, labelID int64) (*Label, error) {
|
|
|
|
if labelID <= 0 {
|
|
|
|
return nil, ErrLabelNotExist{labelID}
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:50:11 +00:00
|
|
|
l := &Label{}
|
|
|
|
has, err := e.ID(labelID).Get(l)
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if !has {
|
|
|
|
return nil, ErrLabelNotExist{l.ID}
|
|
|
|
}
|
|
|
|
return l, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelByID returns a label by given ID.
|
|
|
|
func GetLabelByID(id int64) (*Label, error) {
|
|
|
|
return getLabelByID(x, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelsByIDs returns a list of labels by IDs
|
|
|
|
func GetLabelsByIDs(labelIDs []int64) ([]*Label, error) {
|
|
|
|
labels := make([]*Label, 0, len(labelIDs))
|
|
|
|
return labels, x.Table("label").
|
|
|
|
In("id", labelIDs).
|
|
|
|
Asc("name").
|
|
|
|
Cols("id").
|
|
|
|
Find(&labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
// __________ .__ __
|
|
|
|
// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
|
|
|
|
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
|
|
|
|
// | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
|
|
|
|
// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
|
|
|
|
// \/ \/|__| \/ \/
|
|
|
|
|
2016-10-07 17:17:27 +00:00
|
|
|
// getLabelInRepoByName returns a label by Name in given repository.
|
|
|
|
func getLabelInRepoByName(e Engine, repoID int64, labelName string) (*Label, error) {
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
if len(labelName) == 0 || repoID <= 0 {
|
|
|
|
return nil, ErrRepoLabelNotExist{0, repoID}
|
2016-10-07 17:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
l := &Label{
|
|
|
|
Name: labelName,
|
|
|
|
RepoID: repoID,
|
|
|
|
}
|
2017-02-01 01:31:35 +00:00
|
|
|
has, err := e.Get(l)
|
2016-10-07 17:17:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if !has {
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
return nil, ErrRepoLabelNotExist{0, l.RepoID}
|
2016-10-07 17:17:27 +00:00
|
|
|
}
|
|
|
|
return l, nil
|
|
|
|
}
|
|
|
|
|
2016-08-03 18:51:22 +00:00
|
|
|
// getLabelInRepoByID returns a label by ID in given repository.
|
|
|
|
func getLabelInRepoByID(e Engine, repoID, labelID int64) (*Label, error) {
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
if labelID <= 0 || repoID <= 0 {
|
|
|
|
return nil, ErrRepoLabelNotExist{labelID, repoID}
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 18:51:22 +00:00
|
|
|
l := &Label{
|
|
|
|
ID: labelID,
|
|
|
|
RepoID: repoID,
|
|
|
|
}
|
2017-02-01 01:31:35 +00:00
|
|
|
has, err := e.Get(l)
|
2016-02-27 16:31:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if !has {
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
return nil, ErrRepoLabelNotExist{l.ID, l.RepoID}
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
return l, nil
|
|
|
|
}
|
|
|
|
|
2016-12-02 08:28:45 +00:00
|
|
|
// GetLabelInRepoByName returns a label by name in given repository.
|
2016-10-07 17:17:27 +00:00
|
|
|
func GetLabelInRepoByName(repoID int64, labelName string) (*Label, error) {
|
|
|
|
return getLabelInRepoByName(x, repoID, labelName)
|
|
|
|
}
|
|
|
|
|
2019-02-04 15:20:44 +00:00
|
|
|
// GetLabelIDsInRepoByNames returns a list of labelIDs by names in a given
|
|
|
|
// repository.
|
|
|
|
// it silently ignores label names that do not belong to the repository.
|
|
|
|
func GetLabelIDsInRepoByNames(repoID int64, labelNames []string) ([]int64, error) {
|
|
|
|
labelIDs := make([]int64, 0, len(labelNames))
|
|
|
|
return labelIDs, x.Table("label").
|
|
|
|
Where("repo_id = ?", repoID).
|
|
|
|
In("name", labelNames).
|
|
|
|
Asc("name").
|
|
|
|
Cols("id").
|
|
|
|
Find(&labelIDs)
|
|
|
|
}
|
|
|
|
|
2020-03-30 05:30:39 +00:00
|
|
|
// BuildLabelNamesIssueIDsCondition returns a builder where get issue ids match label names
|
|
|
|
func BuildLabelNamesIssueIDsCondition(labelNames []string) *builder.Builder {
|
|
|
|
return builder.Select("issue_label.issue_id").
|
|
|
|
From("issue_label").
|
|
|
|
InnerJoin("label", "label.id = issue_label.label_id").
|
|
|
|
Where(
|
|
|
|
builder.In("label.name", labelNames),
|
|
|
|
).
|
|
|
|
GroupBy("issue_label.issue_id")
|
|
|
|
}
|
|
|
|
|
2016-08-03 18:51:22 +00:00
|
|
|
// GetLabelInRepoByID returns a label by ID in given repository.
|
|
|
|
func GetLabelInRepoByID(repoID, labelID int64) (*Label, error) {
|
|
|
|
return getLabelInRepoByID(x, repoID, labelID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelsInRepoByIDs returns a list of labels by IDs in given repository,
|
2019-02-04 15:20:44 +00:00
|
|
|
// it silently ignores label IDs that do not belong to the repository.
|
2016-08-03 18:51:22 +00:00
|
|
|
func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) {
|
|
|
|
labels := make([]*Label, 0, len(labelIDs))
|
2016-11-10 15:16:32 +00:00
|
|
|
return labels, x.
|
|
|
|
Where("repo_id = ?", repoID).
|
2016-11-12 08:29:18 +00:00
|
|
|
In("id", labelIDs).
|
2016-11-10 15:16:32 +00:00
|
|
|
Asc("name").
|
|
|
|
Find(&labels)
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 19:00:29 +00:00
|
|
|
func getLabelsByRepoID(e Engine, repoID int64, sortType string, listOptions ListOptions) ([]*Label, error) {
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
if repoID <= 0 {
|
|
|
|
return nil, ErrRepoLabelNotExist{0, repoID}
|
|
|
|
}
|
2016-02-27 16:31:24 +00:00
|
|
|
labels := make([]*Label, 0, 10)
|
2019-11-25 05:17:51 +00:00
|
|
|
sess := e.Where("repo_id = ?", repoID)
|
2016-12-24 14:41:09 +00:00
|
|
|
|
|
|
|
switch sortType {
|
|
|
|
case "reversealphabetically":
|
|
|
|
sess.Desc("name")
|
|
|
|
case "leastissues":
|
|
|
|
sess.Asc("num_issues")
|
|
|
|
case "mostissues":
|
|
|
|
sess.Desc("num_issues")
|
|
|
|
default:
|
|
|
|
sess.Asc("name")
|
|
|
|
}
|
|
|
|
|
2020-01-24 19:00:29 +00:00
|
|
|
if listOptions.Page != 0 {
|
|
|
|
sess = listOptions.setSessionPagination(sess)
|
|
|
|
}
|
|
|
|
|
2016-12-24 14:41:09 +00:00
|
|
|
return labels, sess.Find(&labels)
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 05:17:51 +00:00
|
|
|
// GetLabelsByRepoID returns all labels that belong to given repository by ID.
|
2020-01-24 19:00:29 +00:00
|
|
|
func GetLabelsByRepoID(repoID int64, sortType string, listOptions ListOptions) ([]*Label, error) {
|
|
|
|
return getLabelsByRepoID(x, repoID, sortType, listOptions)
|
2019-11-25 05:17:51 +00:00
|
|
|
}
|
|
|
|
|
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>
2020-04-01 04:14:46 +00:00
|
|
|
// ________
|
|
|
|
// \_____ \_______ ____
|
|
|
|
// / | \_ __ \/ ___\
|
|
|
|
// / | \ | \/ /_/ >
|
|
|
|
// \_______ /__| \___ /
|
|
|
|
// \/ /_____/
|
|
|
|
|
|
|
|
// getLabelInOrgByName returns a label by Name in given organization
|
|
|
|
func getLabelInOrgByName(e Engine, orgID int64, labelName string) (*Label, error) {
|
|
|
|
if len(labelName) == 0 || orgID <= 0 {
|
|
|
|
return nil, ErrOrgLabelNotExist{0, orgID}
|
|
|
|
}
|
|
|
|
|
|
|
|
l := &Label{
|
|
|
|
Name: labelName,
|
|
|
|
OrgID: orgID,
|
|
|
|
}
|
|
|
|
has, err := e.Get(l)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if !has {
|
|
|
|
return nil, ErrOrgLabelNotExist{0, l.OrgID}
|
|
|
|
}
|
|
|
|
return l, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// getLabelInOrgByID returns a label by ID in given organization.
|
|
|
|
func getLabelInOrgByID(e Engine, orgID, labelID int64) (*Label, error) {
|
|
|
|
if labelID <= 0 || orgID <= 0 {
|
|
|
|
return nil, ErrOrgLabelNotExist{labelID, orgID}
|
|
|
|
}
|
|
|
|
|
|
|
|
l := &Label{
|
|
|
|
ID: labelID,
|
|
|
|
OrgID: orgID,
|
|
|
|
}
|
|
|
|
has, err := e.Get(l)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if !has {
|
|
|
|
return nil, ErrOrgLabelNotExist{l.ID, l.OrgID}
|
|
|
|
}
|
|
|
|
return l, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelInOrgByName returns a label by name in given organization.
|
|
|
|
func GetLabelInOrgByName(orgID int64, labelName string) (*Label, error) {
|
|
|
|
return getLabelInOrgByName(x, orgID, labelName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelIDsInOrgByNames returns a list of labelIDs by names in a given
|
|
|
|
// organization.
|
|
|
|
func GetLabelIDsInOrgByNames(orgID int64, labelNames []string) ([]int64, error) {
|
|
|
|
if orgID <= 0 {
|
|
|
|
return nil, ErrOrgLabelNotExist{0, orgID}
|
|
|
|
}
|
|
|
|
labelIDs := make([]int64, 0, len(labelNames))
|
|
|
|
|
|
|
|
return labelIDs, x.Table("label").
|
|
|
|
Where("org_id = ?", orgID).
|
|
|
|
In("name", labelNames).
|
|
|
|
Asc("name").
|
|
|
|
Cols("id").
|
|
|
|
Find(&labelIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelIDsInOrgsByNames returns a list of labelIDs by names in one of the given
|
|
|
|
// organization.
|
|
|
|
// it silently ignores label names that do not belong to the organization.
|
|
|
|
func GetLabelIDsInOrgsByNames(orgIDs []int64, labelNames []string) ([]int64, error) {
|
|
|
|
labelIDs := make([]int64, 0, len(labelNames))
|
|
|
|
return labelIDs, x.Table("label").
|
|
|
|
In("org_id", orgIDs).
|
|
|
|
In("name", labelNames).
|
|
|
|
Asc("name").
|
|
|
|
Cols("id").
|
|
|
|
Find(&labelIDs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelInOrgByID returns a label by ID in given organization.
|
|
|
|
func GetLabelInOrgByID(orgID, labelID int64) (*Label, error) {
|
|
|
|
return getLabelInOrgByID(x, orgID, labelID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelsInOrgByIDs returns a list of labels by IDs in given organization,
|
|
|
|
// it silently ignores label IDs that do not belong to the organization.
|
|
|
|
func GetLabelsInOrgByIDs(orgID int64, labelIDs []int64) ([]*Label, error) {
|
|
|
|
labels := make([]*Label, 0, len(labelIDs))
|
|
|
|
return labels, x.
|
|
|
|
Where("org_id = ?", orgID).
|
|
|
|
In("id", labelIDs).
|
|
|
|
Asc("name").
|
|
|
|
Find(&labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLabelsByOrgID(e Engine, orgID int64, sortType string, listOptions ListOptions) ([]*Label, error) {
|
|
|
|
if orgID <= 0 {
|
|
|
|
return nil, ErrOrgLabelNotExist{0, orgID}
|
|
|
|
}
|
|
|
|
labels := make([]*Label, 0, 10)
|
|
|
|
sess := e.Where("org_id = ?", orgID)
|
|
|
|
|
|
|
|
switch sortType {
|
|
|
|
case "reversealphabetically":
|
|
|
|
sess.Desc("name")
|
|
|
|
case "leastissues":
|
|
|
|
sess.Asc("num_issues")
|
|
|
|
case "mostissues":
|
|
|
|
sess.Desc("num_issues")
|
|
|
|
default:
|
|
|
|
sess.Asc("name")
|
|
|
|
}
|
|
|
|
|
|
|
|
if listOptions.Page != 0 {
|
|
|
|
sess = listOptions.setSessionPagination(sess)
|
|
|
|
}
|
|
|
|
|
|
|
|
return labels, sess.Find(&labels)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelsByOrgID returns all labels that belong to given organization by ID.
|
|
|
|
func GetLabelsByOrgID(orgID int64, sortType string, listOptions ListOptions) ([]*Label, error) {
|
|
|
|
return getLabelsByOrgID(x, orgID, sortType, listOptions)
|
|
|
|
}
|
|
|
|
|
|
|
|
// .___
|
|
|
|
// | | ______ ________ __ ____
|
|
|
|
// | |/ ___// ___/ | \_/ __ \
|
|
|
|
// | |\___ \ \___ \| | /\ ___/
|
|
|
|
// |___/____ >____ >____/ \___ |
|
|
|
|
// \/ \/ \/
|
|
|
|
|
2016-02-27 16:31:24 +00:00
|
|
|
func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) {
|
2017-02-11 12:01:33 +00:00
|
|
|
var labels []*Label
|
|
|
|
return labels, e.Where("issue_label.issue_id = ?", issueID).
|
|
|
|
Join("LEFT", "issue_label", "issue_label.label_id = label.id").
|
|
|
|
Asc("label.name").
|
2016-11-10 15:16:32 +00:00
|
|
|
Find(&labels)
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabelsByIssueID returns all labels that belong to given issue by ID.
|
|
|
|
func GetLabelsByIssueID(issueID int64) ([]*Label, error) {
|
|
|
|
return getLabelsByIssueID(x, issueID)
|
|
|
|
}
|
|
|
|
|
2020-04-28 23:28:56 +00:00
|
|
|
func updateLabelCols(e Engine, l *Label, cols ...string) error {
|
2019-09-24 13:22:39 +00:00
|
|
|
_, err := e.ID(l.ID).
|
|
|
|
SetExpr("num_issues",
|
|
|
|
builder.Select("count(*)").From("issue_label").
|
|
|
|
Where(builder.Eq{"label_id": l.ID}),
|
|
|
|
).
|
|
|
|
SetExpr("num_closed_issues",
|
|
|
|
builder.Select("count(*)").From("issue_label").
|
|
|
|
InnerJoin("issue", "issue_label.issue_id = issue.id").
|
|
|
|
Where(builder.Eq{
|
|
|
|
"issue_label.label_id": l.ID,
|
|
|
|
"issue.is_closed": true,
|
|
|
|
}),
|
|
|
|
).
|
2020-04-28 23:28:56 +00:00
|
|
|
Cols(cols...).Update(l)
|
2016-02-27 16:31:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// .___ .____ ___. .__
|
|
|
|
// | | ______ ________ __ ____ | | _____ \_ |__ ____ | |
|
|
|
|
// | |/ ___// ___/ | \_/ __ \| | \__ \ | __ \_/ __ \| |
|
|
|
|
// | |\___ \ \___ \| | /\ ___/| |___ / __ \| \_\ \ ___/| |__
|
|
|
|
// |___/____ >____ >____/ \___ >_______ (____ /___ /\___ >____/
|
|
|
|
// \/ \/ \/ \/ \/ \/ \/
|
|
|
|
|
2017-01-05 00:50:34 +00:00
|
|
|
// IssueLabel represents an issue-label relation.
|
2016-02-27 16:31:24 +00:00
|
|
|
type IssueLabel struct {
|
|
|
|
ID int64 `xorm:"pk autoincr"`
|
|
|
|
IssueID int64 `xorm:"UNIQUE(s)"`
|
|
|
|
LabelID int64 `xorm:"UNIQUE(s)"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func hasIssueLabel(e Engine, issueID, labelID int64) bool {
|
2016-08-03 18:51:22 +00:00
|
|
|
has, _ := e.Where("issue_id = ? AND label_id = ?", issueID, labelID).Get(new(IssueLabel))
|
2016-02-27 16:31:24 +00:00
|
|
|
return has
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasIssueLabel returns true if issue has been labeled.
|
|
|
|
func HasIssueLabel(issueID, labelID int64) bool {
|
|
|
|
return hasIssueLabel(x, issueID, labelID)
|
|
|
|
}
|
|
|
|
|
2017-01-30 12:46:45 +00:00
|
|
|
func newIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (err error) {
|
2016-02-27 16:31:24 +00:00
|
|
|
if _, err = e.Insert(&IssueLabel{
|
|
|
|
IssueID: issue.ID,
|
|
|
|
LabelID: label.ID,
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-30 12:46:45 +00:00
|
|
|
if err = issue.loadRepo(e); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-01 02:44:39 +00:00
|
|
|
var opts = &CreateCommentOptions{
|
2019-11-15 18:18:09 +00:00
|
|
|
Type: CommentTypeLabel,
|
|
|
|
Doer: doer,
|
|
|
|
Repo: issue.Repo,
|
|
|
|
Issue: issue,
|
|
|
|
Label: label,
|
|
|
|
Content: "1",
|
2019-12-01 02:44:39 +00:00
|
|
|
}
|
2019-12-16 03:54:24 +00:00
|
|
|
if _, err = createComment(e, opts); err != nil {
|
2017-01-30 12:46:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-28 23:28:56 +00:00
|
|
|
return updateLabelCols(e, label, "num_issues", "num_closed_issue")
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewIssueLabel creates a new issue-label relation.
|
2017-01-30 12:46:45 +00:00
|
|
|
func NewIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
|
2016-08-03 18:51:22 +00:00
|
|
|
if HasIssueLabel(issue.ID, label.ID) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-27 16:31:24 +00:00
|
|
|
sess := x.NewSession()
|
2017-06-21 00:57:05 +00:00
|
|
|
defer sess.Close()
|
2016-02-27 16:31:24 +00:00
|
|
|
if err = sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-30 12:46:45 +00:00
|
|
|
if err = newIssueLabel(sess, issue, label, doer); err != nil {
|
2016-02-27 16:31:24 +00:00
|
|
|
return err
|
2016-08-03 18:51:22 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 06:49:11 +00:00
|
|
|
issue.Labels = nil
|
|
|
|
if err = issue.loadLabels(sess); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-08-03 18:51:22 +00:00
|
|
|
return sess.Commit()
|
|
|
|
}
|
|
|
|
|
2017-01-30 12:46:45 +00:00
|
|
|
func newIssueLabels(e *xorm.Session, issue *Issue, labels []*Label, doer *User) (err error) {
|
2016-08-03 18:51:22 +00:00
|
|
|
for i := range labels {
|
|
|
|
if hasIssueLabel(e, issue.ID, labels[i].ID) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-01-30 12:46:45 +00:00
|
|
|
if err = newIssueLabel(e, issue, labels[i], doer); err != nil {
|
2016-08-03 18:51:22 +00:00
|
|
|
return fmt.Errorf("newIssueLabel: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewIssueLabels creates a list of issue-label relations.
|
2017-01-30 12:46:45 +00:00
|
|
|
func NewIssueLabels(issue *Issue, labels []*Label, doer *User) (err error) {
|
2016-08-03 18:51:22 +00:00
|
|
|
sess := x.NewSession()
|
2017-06-21 00:57:05 +00:00
|
|
|
defer sess.Close()
|
2016-08-03 18:51:22 +00:00
|
|
|
if err = sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-30 12:46:45 +00:00
|
|
|
if err = newIssueLabels(sess, issue, labels, doer); err != nil {
|
2016-08-03 18:51:22 +00:00
|
|
|
return err
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 06:49:11 +00:00
|
|
|
issue.Labels = nil
|
|
|
|
if err = issue.loadLabels(sess); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-02-27 16:31:24 +00:00
|
|
|
return sess.Commit()
|
|
|
|
}
|
|
|
|
|
2017-02-01 01:31:35 +00:00
|
|
|
func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (err error) {
|
|
|
|
if count, err := e.Delete(&IssueLabel{
|
2016-02-27 16:31:24 +00:00
|
|
|
IssueID: issue.ID,
|
|
|
|
LabelID: label.ID,
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
2017-02-01 01:31:35 +00:00
|
|
|
} else if count == 0 {
|
|
|
|
return nil
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-30 12:46:45 +00:00
|
|
|
if err = issue.loadRepo(e); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-12-01 02:44:39 +00:00
|
|
|
var opts = &CreateCommentOptions{
|
2019-11-15 18:18:09 +00:00
|
|
|
Type: CommentTypeLabel,
|
|
|
|
Doer: doer,
|
|
|
|
Repo: issue.Repo,
|
|
|
|
Issue: issue,
|
|
|
|
Label: label,
|
2019-12-01 02:44:39 +00:00
|
|
|
}
|
2019-12-16 03:54:24 +00:00
|
|
|
if _, err = createComment(e, opts); err != nil {
|
2017-01-30 12:46:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-28 23:28:56 +00:00
|
|
|
return updateLabelCols(e, label, "num_issues", "num_closed_issue")
|
2016-02-27 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteIssueLabel deletes issue-label relation.
|
2017-02-01 01:31:35 +00:00
|
|
|
func DeleteIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
|
2016-02-27 16:31:24 +00:00
|
|
|
sess := x.NewSession()
|
2017-06-21 00:57:05 +00:00
|
|
|
defer sess.Close()
|
2016-02-27 16:31:24 +00:00
|
|
|
if err = sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-02-01 01:31:35 +00:00
|
|
|
if err = deleteIssueLabel(sess, issue, label, doer); err != nil {
|
2016-02-27 16:31:24 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-05 06:49:11 +00:00
|
|
|
issue.Labels = nil
|
|
|
|
if err = issue.loadLabels(sess); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-02-27 16:31:24 +00:00
|
|
|
return sess.Commit()
|
|
|
|
}
|