From e7ef94e00f1319e5fb876f47fee28728bd671f07 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 17 Feb 2023 22:02:20 +0800 Subject: [PATCH 01/14] Introduce customized HTML elements, fix incorrect AppUrl usages in templates (#22861) This PR follows: * #21986 * #22831 This PR also introduce customized HTML elements, which would also help problems like: * #17760 * #21429 * #21440 With customized HTML elements, there won't be any load-search-replace operations, and it can avoid page flicking (which @silverwind cares a lot). Browser support: https://developer.mozilla.org/en-US/docs/Web/API/Window/customElements # FAQ ## Why the component has the prefix? As usual, I would strongly suggest to add prefixes for our own/private names. The dedicated prefix will avoid conflicts in the future, and it makes it easier to introduce various 3rd components, like GitHub's `relative-time` component. If there is no prefix, it's impossible to introduce another public component with the same name in the future. ## Why the `custcomp.js` is loaded before HTML body? The `index.js` is after HTML body. Customized components must be registered before the content loading. Otherwise there would be still some flicking. `custcomp.js` should have its own dependencies and should be very light, so it won't affect the page loading time too much. ## Why use `data-url` attribute but not use the `textContent`? According to the standard, the `connectedCallback` occurs on the tag-opening moment. The element's children are not ready yet. ## Why not use `{{.GuessCurrentOrigin $.ctx ...}}` to let backend decide the absolute URL? It's difficult for backend to guess the correct protocol(scheme) correctly with zero configuration. Generating the absolute URL from frontend can guarantee that the URL is 100% correct -- since the user is visiting it. # Screenshot
![image](https://user-images.githubusercontent.com/2114189/218256757-a267c8ba-3108-4755-9ae5-329f1b08f615.png)
--- templates/base/head_script.tmpl | 1 + templates/package/content/cargo.tmpl | 2 +- templates/package/content/chef.tmpl | 2 +- templates/package/content/composer.tmpl | 2 +- templates/package/content/conan.tmpl | 2 +- templates/package/content/conda.tmpl | 6 +++--- templates/package/content/generic.tmpl | 7 +++++-- templates/package/content/helm.tmpl | 2 +- templates/package/content/maven.tmpl | 8 ++++---- templates/package/content/npm.tmpl | 2 +- templates/package/content/nuget.tmpl | 2 +- templates/package/content/pub.tmpl | 2 +- templates/package/content/pypi.tmpl | 2 +- templates/package/content/rubygems.tmpl | 4 ++-- templates/package/content/vagrant.tmpl | 2 +- templates/post-install.tmpl | 2 +- .../view_content/pull_merge_instruction.tmpl | 3 +-- templates/repo/view_list.tmpl | 2 +- templates/swagger/ui.tmpl | 4 ++-- web_src/js/webcomponents/GiteaOriginUrl.js | 17 +++++++++++++++++ webpack.config.js | 3 +++ 21 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 web_src/js/webcomponents/GiteaOriginUrl.js diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index 1b130d9cb49df..ca8c7e6a77341 100644 --- a/templates/base/head_script.tmpl +++ b/templates/base/head_script.tmpl @@ -46,3 +46,4 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. {{/* in case some pages don't render the pageData, we make sure it is an object to prevent null access */}} window.config.pageData = window.config.pageData || {}; + diff --git a/templates/package/content/cargo.tmpl b/templates/package/content/cargo.tmpl index 54c40a5b0dc0a..f78647ca69c63 100644 --- a/templates/package/content/cargo.tmpl +++ b/templates/package/content/cargo.tmpl @@ -8,7 +8,7 @@ default = "gitea" [registries.gitea] -index = "{{AppUrl}}{{.PackageDescriptor.Owner.Name}}/_cargo-index.git" +index = "" [net] git-fetch-with-cli = true diff --git a/templates/package/content/chef.tmpl b/templates/package/content/chef.tmpl index f0f8de7bd5587..edc175f9beddc 100644 --- a/templates/package/content/chef.tmpl +++ b/templates/package/content/chef.tmpl @@ -4,7 +4,7 @@
-
knife[:supermarket_site] = '{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/chef'
+
knife[:supermarket_site] = ''
diff --git a/templates/package/content/composer.tmpl b/templates/package/content/composer.tmpl index 8cc18f8ba8fb7..9acf20955c891 100644 --- a/templates/package/content/composer.tmpl +++ b/templates/package/content/composer.tmpl @@ -7,7 +7,7 @@
{
 	"repositories": [{
 			"type": "composer",
-			"url": "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/composer"
+			"url": ""
 		}
 	]
 }
diff --git a/templates/package/content/conan.tmpl b/templates/package/content/conan.tmpl index c496cee55cf62..138890f334c52 100644 --- a/templates/package/content/conan.tmpl +++ b/templates/package/content/conan.tmpl @@ -4,7 +4,7 @@
-
conan remote add gitea {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conan
+
conan remote add gitea 
diff --git a/templates/package/content/conda.tmpl b/templates/package/content/conda.tmpl index ecc26bce98e64..3c79d3902fae6 100644 --- a/templates/package/content/conda.tmpl +++ b/templates/package/content/conda.tmpl @@ -4,11 +4,11 @@
-
channel_alias: {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conda
+				
channel_alias: 
 channels:
-  - {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conda
+  - 
 default_channels:
-  - {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/conda
+ -
diff --git a/templates/package/content/generic.tmpl b/templates/package/content/generic.tmpl index 2948d9eb02cac..eae4d670f9c6f 100644 --- a/templates/package/content/generic.tmpl +++ b/templates/package/content/generic.tmpl @@ -4,8 +4,11 @@
-
{{range .PackageDescriptor.Files}}curl {{AppUrl}}api/packages/{{$.PackageDescriptor.Owner.Name}}/generic/{{$.PackageDescriptor.Package.Name}}/{{$.PackageDescriptor.Version.Version}}/{{.File.Name}}
-{{end}}
+

+					{{- range .PackageDescriptor.Files -}}
+curl 
+ {{- end -}} +
diff --git a/templates/package/content/helm.tmpl b/templates/package/content/helm.tmpl index 59cdc157b4087..fc190e0e459bb 100644 --- a/templates/package/content/helm.tmpl +++ b/templates/package/content/helm.tmpl @@ -4,7 +4,7 @@
-
helm repo add gitea {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/helm
+				
helm repo add gitea 
 helm repo update
diff --git a/templates/package/content/maven.tmpl b/templates/package/content/maven.tmpl index 0b5612151c577..ff89145fd0023 100644 --- a/templates/package/content/maven.tmpl +++ b/templates/package/content/maven.tmpl @@ -7,19 +7,19 @@
<repositories>
 	<repository>
 		<id>gitea</id>
-		<url>{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven</url>
+			<url></url>
 	</repository>
 </repositories>
 
 <distributionManagement>
 	<repository>
 		<id>gitea</id>
-		<url>{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven</url>
+		<url></url>
 	</repository>
 
 	<snapshotRepository>
 		<id>gitea</id>
-		<url>{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven</url>
+		<url></url>
 	</snapshotRepository>
 </distributionManagement>
@@ -37,7 +37,7 @@
-
mvn dependency:get -DremoteRepositories={{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/maven -Dartifact={{.PackageDescriptor.Metadata.GroupID}}:{{.PackageDescriptor.Metadata.ArtifactID}}:{{.PackageDescriptor.Version.Version}}
+
mvn dependency:get -DremoteRepositories= -Dartifact={{.PackageDescriptor.Metadata.GroupID}}:{{.PackageDescriptor.Metadata.ArtifactID}}:{{.PackageDescriptor.Version.Version}}
diff --git a/templates/package/content/npm.tmpl b/templates/package/content/npm.tmpl index 33d51d4dfd87d..ea514c5263ad9 100644 --- a/templates/package/content/npm.tmpl +++ b/templates/package/content/npm.tmpl @@ -4,7 +4,7 @@
-
{{if .PackageDescriptor.Metadata.Scope}}{{.PackageDescriptor.Metadata.Scope}}:{{end}}registry={{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/npm/
+
{{if .PackageDescriptor.Metadata.Scope}}{{.PackageDescriptor.Metadata.Scope}}:{{end}}registry=
diff --git a/templates/package/content/nuget.tmpl b/templates/package/content/nuget.tmpl index 4ea41fa826a28..8ed2f04e4a55f 100644 --- a/templates/package/content/nuget.tmpl +++ b/templates/package/content/nuget.tmpl @@ -4,7 +4,7 @@
-
dotnet nuget add source --name Gitea --username your_username --password your_token {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/nuget/index.json
+
dotnet nuget add source --name Gitea --username your_username --password your_token 
diff --git a/templates/package/content/pub.tmpl b/templates/package/content/pub.tmpl index 999e48ce82011..e81439d4daece 100644 --- a/templates/package/content/pub.tmpl +++ b/templates/package/content/pub.tmpl @@ -4,7 +4,7 @@
-
dart pub add {{.PackageDescriptor.Package.Name}}:{{.PackageDescriptor.Version.Version}} --hosted-url={{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/pub/
+
dart pub add {{.PackageDescriptor.Package.Name}}:{{.PackageDescriptor.Version.Version}} --hosted-url=
diff --git a/templates/package/content/pypi.tmpl b/templates/package/content/pypi.tmpl index 1ae243813de65..830ba9bd67e54 100644 --- a/templates/package/content/pypi.tmpl +++ b/templates/package/content/pypi.tmpl @@ -4,7 +4,7 @@
-
pip install --index-url {{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/pypi/simple {{.PackageDescriptor.Package.Name}}
+
pip install --index-url 
diff --git a/templates/package/content/rubygems.tmpl b/templates/package/content/rubygems.tmpl index 0cb7b670b1dea..d8190ba4f59df 100644 --- a/templates/package/content/rubygems.tmpl +++ b/templates/package/content/rubygems.tmpl @@ -4,11 +4,11 @@
-
gem install {{.PackageDescriptor.Package.Name}} --version "{{.PackageDescriptor.Version.Version}}" --source "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems"
+
gem install {{.PackageDescriptor.Package.Name}} --version "{{.PackageDescriptor.Version.Version}}" --source ""
-
source "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/rubygems" do
+				
source "" do
 	gem "{{.PackageDescriptor.Package.Name}}", "{{.PackageDescriptor.Version.Version}}"
 end
diff --git a/templates/package/content/vagrant.tmpl b/templates/package/content/vagrant.tmpl index 7bd686e6ab689..a6a92f5ecd8cb 100644 --- a/templates/package/content/vagrant.tmpl +++ b/templates/package/content/vagrant.tmpl @@ -4,7 +4,7 @@
-
vagrant box add --box-version {{.PackageDescriptor.Version.Version}} "{{AppUrl}}api/packages/{{.PackageDescriptor.Owner.Name}}/vagrant/{{.PackageDescriptor.Package.Name}}"
+
vagrant box add --box-version {{.PackageDescriptor.Version.Version}} ""
diff --git a/templates/post-install.tmpl b/templates/post-install.tmpl index e098f43fda82e..0d6cd3082c185 100644 --- a/templates/post-install.tmpl +++ b/templates/post-install.tmpl @@ -13,7 +13,7 @@
diff --git a/templates/repo/issue/view_content/pull_merge_instruction.tmpl b/templates/repo/issue/view_content/pull_merge_instruction.tmpl index 39349d6ca42f7..5a7f6e867b551 100644 --- a/templates/repo/issue/view_content/pull_merge_instruction.tmpl +++ b/templates/repo/issue/view_content/pull_merge_instruction.tmpl @@ -5,8 +5,7 @@
{{if eq $.Issue.PullRequest.Flow 0}}
git checkout -b {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{$.Issue.PullRequest.HeadRepo.OwnerName}}-{{end}}{{$.Issue.PullRequest.HeadBranch}} {{$.Issue.PullRequest.BaseBranch}}
- {{/* the only legacy HTMLURL used in template, which doesn't affect users too much and is very diffcult to fix, it should be fixed together with other AppUrl usages*/}} -
git pull {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{$.Issue.PullRequest.HeadRepo.HTMLURL}}{{else}}origin{{end}} {{$.Issue.PullRequest.HeadBranch}}
+
git pull {{if ne $.Issue.PullRequest.HeadRepo.ID $.Issue.PullRequest.BaseRepo.ID}}{{else}}origin{{end}} {{$.Issue.PullRequest.HeadBranch}}
{{else}}
git fetch origin {{$.Issue.PullRequest.GetGitRefName}}:{{$.Issue.PullRequest.HeadBranch}}
{{end}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index 45d098d3c54dd..ab7065015c1f2 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -52,7 +52,7 @@ {{if $entry.IsSubModule}} {{svg "octicon-file-submodule"}} - {{$refURL := $subModuleFile.RefURL AppUrl $.Repository.FullName $.SSHDomain}} + {{$refURL := $subModuleFile.RefURL AppUrl $.Repository.FullName $.SSHDomain}} {{/* FIXME: the usage of AppUrl seems incorrect, it would be fixed in the future, use AppSubUrl instead */}} {{if $refURL}} {{$entry.Name}}@{{ShortSha $subModuleFile.RefID}} {{else}} diff --git a/templates/swagger/ui.tmpl b/templates/swagger/ui.tmpl index d4d0889f9d4ab..57b560bc1591d 100644 --- a/templates/swagger/ui.tmpl +++ b/templates/swagger/ui.tmpl @@ -6,8 +6,8 @@ - {{svg "octicon-reply"}}{{.locale.Tr "return_to_gitea"}} -
+ {{svg "octicon-reply"}}{{.locale.Tr "return_to_gitea"}} +
diff --git a/web_src/js/webcomponents/GiteaOriginUrl.js b/web_src/js/webcomponents/GiteaOriginUrl.js new file mode 100644 index 0000000000000..47fd13bfc1d7e --- /dev/null +++ b/web_src/js/webcomponents/GiteaOriginUrl.js @@ -0,0 +1,17 @@ +// this is a Gitea's private HTML component, it converts an absolute or relative URL to an absolute URL with the current origin +window.customElements.define('gitea-origin-url', class extends HTMLElement { + connectedCallback() { + const urlStr = this.getAttribute('data-url'); + try { + // only process absolute HTTP/HTTPS URL or relative URLs ('/xxx' or '//host/xxx') + if (urlStr.startsWith('http://') || urlStr.startsWith('https://') || urlStr.startsWith('/')) { + const url = new URL(urlStr, window.origin); + url.protocol = window.location.protocol; + url.host = window.location.host; + this.textContent = url.toString(); + return; + } + } catch {} + this.textContent = urlStr; + } +}); diff --git a/webpack.config.js b/webpack.config.js index e5e592052e115..2ac463abef2b6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -59,6 +59,9 @@ export default { fileURLToPath(new URL('web_src/fomantic/build/semantic.css', import.meta.url)), fileURLToPath(new URL('web_src/less/index.less', import.meta.url)), ], + webcomponents: [ + fileURLToPath(new URL('web_src/js/webcomponents/GiteaOriginUrl.js', import.meta.url)), + ], swagger: [ fileURLToPath(new URL('web_src/js/standalone/swagger.js', import.meta.url)), fileURLToPath(new URL('web_src/less/standalone/swagger.less', import.meta.url)), From 8bba7e30b2833d750af0345b75a3998785ef55ef Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 18 Feb 2023 02:47:06 +0100 Subject: [PATCH 02/14] webview: Fix overflowing diff body (#22959) If the content is quite large the diff body overflows the container and can not be read. This is fixed by setting the diff body maximum width to 100% and enable overflow scrollbars: before | after ---|--- ![Screenshot_20230217_184716](https://user-images.githubusercontent.com/1855448/219733934-75bec38c-7cfe-47bb-b001-b090c02b769e.png) | ![Screenshot_20230217_184655](https://user-images.githubusercontent.com/1855448/219733971-4db092d1-ffcb-4298-a640-f740a3ac430b.png) Signed-off-by: Ferdinand Thiessen --- web_src/less/_repository.less | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 39362722de535..f7087d4d30519 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -3187,6 +3187,7 @@ td.blob-excerpt { } #diff-file-boxes { flex: 1; + max-width: 100%; } #diff-file-tree { @@ -3295,6 +3296,10 @@ td.blob-excerpt { } } +.diff-file-body { + overflow-x: scroll; +} + .diff-stats-bar { display: inline-block; background-color: var(--color-red); From 007d181bb51330c4c24e78c2f40a2e49cae45ed9 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sat, 18 Feb 2023 06:36:38 +0100 Subject: [PATCH 03/14] Notify on container image create (#22806) Fixes #22791 --------- Co-authored-by: Lunny Xiao --- routers/api/packages/container/manifest.go | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/routers/api/packages/container/manifest.go b/routers/api/packages/container/manifest.go index 6167d00f311a9..e36c6a851bf03 100644 --- a/routers/api/packages/container/manifest.go +++ b/routers/api/packages/container/manifest.go @@ -17,6 +17,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" packages_module "code.gitea.io/gitea/modules/packages" container_module "code.gitea.io/gitea/modules/packages/container" "code.gitea.io/gitea/modules/util" @@ -71,11 +72,9 @@ func processManifest(mci *manifestCreationInfo, buf *packages_module.HashedBuffe } if isImageManifestMediaType(mci.MediaType) { - d, err := processImageManifest(mci, buf) - return d, err + return processImageManifest(mci, buf) } else if isImageIndexMediaType(mci.MediaType) { - d, err := processImageManifestIndex(mci, buf) - return d, err + return processImageManifestIndex(mci, buf) } return "", errManifestInvalid } @@ -182,6 +181,10 @@ func processImageManifest(mci *manifestCreationInfo, buf *packages_module.Hashed return err } + if err := notifyPackageCreate(mci.Creator, pv); err != nil { + return err + } + manifestDigest = digest return nil @@ -271,6 +274,10 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H return err } + if err := notifyPackageCreate(mci.Creator, pv); err != nil { + return err + } + manifestDigest = digest return nil @@ -282,6 +289,17 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H return manifestDigest, nil } +func notifyPackageCreate(doer *user_model.User, pv *packages_model.PackageVersion) error { + pd, err := packages_model.GetPackageDescriptor(db.DefaultContext, pv) + if err != nil { + return err + } + + notification.NotifyPackageCreate(db.DefaultContext, doer, pd) + + return nil +} + func createPackageAndVersion(ctx context.Context, mci *manifestCreationInfo, metadata *container_module.Metadata) (*packages_model.PackageVersion, error) { created := true p := &packages_model.Package{ From bd66fa586a0da58c4cf2f5f8390aef4bac9d0527 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Sat, 18 Feb 2023 21:11:03 +0900 Subject: [PATCH 04/14] Rename `repo.GetOwner` to `repo.LoadOwner` (#22967) Fixes https://github.com/go-gitea/gitea/issues/22963 --------- Co-authored-by: Yarden Shoham --- models/activities/action.go | 2 +- models/git/protected_branch.go | 4 ++-- models/issues/comment.go | 4 ++-- models/issues/issue.go | 2 +- models/issues/pull.go | 2 +- models/perm/access/access.go | 8 ++++---- models/perm/access/access_test.go | 4 ++-- models/perm/access/repo_permission.go | 8 ++++---- models/repo/repo.go | 8 ++++---- models/repo/update.go | 2 +- models/repo/user_repo.go | 4 ++-- models/repo_collaboration_test.go | 2 +- modules/context/repo.go | 12 ++++++------ modules/doctor/misc.go | 2 +- modules/repository/collaborator_test.go | 2 +- modules/repository/create.go | 6 +++--- modules/repository/delete.go | 2 +- modules/test/context_tests.go | 2 +- routers/api/v1/repo/repo.go | 2 +- routers/api/v1/user/repo.go | 4 ++-- routers/web/repo/compare.go | 2 +- routers/web/repo/http.go | 4 ++-- routers/web/repo/issue.go | 4 ++-- routers/web/repo/pull.go | 8 ++++---- routers/web/repo/setting.go | 2 +- routers/web/repo/view.go | 4 ++-- services/convert/issue.go | 2 +- services/convert/repository.go | 2 +- services/pull/check.go | 4 ++-- services/pull/merge.go | 6 +++--- services/pull/temp_repo.go | 12 ++++++------ services/repository/review.go | 2 +- services/repository/transfer.go | 2 +- 33 files changed, 68 insertions(+), 68 deletions(-) diff --git a/models/activities/action.go b/models/activities/action.go index 8e7492c008f76..2e845bf89e660 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -534,7 +534,7 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error { repo = act.Repo // check repo owner exist. - if err := act.Repo.GetOwner(ctx); err != nil { + if err := act.Repo.LoadOwner(ctx); err != nil { return fmt.Errorf("can't get repo owner: %w", err) } } else if act.Repo == nil { diff --git a/models/git/protected_branch.go b/models/git/protected_branch.go index 355a7464c1fcc..eef7e3935af87 100644 --- a/models/git/protected_branch.go +++ b/models/git/protected_branch.go @@ -314,8 +314,8 @@ type WhitelistOptions struct { // This function also performs check if whitelist user and team's IDs have been changed // to avoid unnecessary whitelist delete and regenerate. func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) { - if err = repo.GetOwner(ctx); err != nil { - return fmt.Errorf("GetOwner: %v", err) + if err = repo.LoadOwner(ctx); err != nil { + return fmt.Errorf("LoadOwner: %v", err) } whitelist, err := updateUserWhitelist(ctx, repo, protectBranch.WhitelistUserIDs, opts.UserIDs) diff --git a/models/issues/comment.go b/models/issues/comment.go index 36e7b8e785e30..a47dc7c151340 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -620,7 +620,7 @@ func (c *Comment) LoadAssigneeUserAndTeam() error { return err } - if err = c.Issue.Repo.GetOwner(db.DefaultContext); err != nil { + if err = c.Issue.Repo.LoadOwner(db.DefaultContext); err != nil { return err } @@ -824,7 +824,7 @@ func CreateComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, return nil, err } - if err = opts.Repo.GetOwner(ctx); err != nil { + if err = opts.Repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/issues/issue.go b/models/issues/issue.go index e0dcf3d269ee0..b1c7fdbf7ed27 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -2099,7 +2099,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u resolved := make(map[string]bool, 10) var mentionTeams []string - if err := issue.Repo.GetOwner(ctx); err != nil { + if err := issue.Repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/issues/pull.go b/models/issues/pull.go index 3f8b0bc7acb6c..6a1dc31556247 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -498,7 +498,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) { return false, err } - if err := pr.Issue.Repo.GetOwner(ctx); err != nil { + if err := pr.Issue.Repo.LoadOwner(ctx); err != nil { return false, err } diff --git a/models/perm/access/access.go b/models/perm/access/access.go index 48ecf78a8c891..2d1b2daa62011 100644 --- a/models/perm/access/access.go +++ b/models/perm/access/access.go @@ -85,8 +85,8 @@ func updateUserAccess(accessMap map[int64]*userAccess, user *user_model.User, mo // FIXME: do cross-comparison so reduce deletions and additions to the minimum? func refreshAccesses(ctx context.Context, repo *repo_model.Repository, accessMap map[int64]*userAccess) (err error) { minMode := perm.AccessModeRead - if err := repo.GetOwner(ctx); err != nil { - return fmt.Errorf("GetOwner: %w", err) + if err := repo.LoadOwner(ctx); err != nil { + return fmt.Errorf("LoadOwner: %w", err) } // If the repo isn't private and isn't owned by a organization, @@ -143,7 +143,7 @@ func refreshCollaboratorAccesses(ctx context.Context, repoID int64, accessMap ma func RecalculateTeamAccesses(ctx context.Context, repo *repo_model.Repository, ignTeamID int64) (err error) { accessMap := make(map[int64]*userAccess, 20) - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return err } else if !repo.Owner.IsOrganization() { return fmt.Errorf("owner is not an organization: %d", repo.OwnerID) @@ -199,7 +199,7 @@ func RecalculateUserAccess(ctx context.Context, repo *repo_model.Repository, uid accessMode = collaborator.Mode } - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return err } else if repo.Owner.IsOrganization() { var teams []organization.Team diff --git a/models/perm/access/access_test.go b/models/perm/access/access_test.go index bd828a1e9d4e0..79b131fe89643 100644 --- a/models/perm/access/access_test.go +++ b/models/perm/access/access_test.go @@ -97,7 +97,7 @@ func TestRepository_RecalculateAccesses(t *testing.T) { // test with organization repo assert.NoError(t, unittest.PrepareTestDatabase()) repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}) - assert.NoError(t, repo1.GetOwner(db.DefaultContext)) + assert.NoError(t, repo1.LoadOwner(db.DefaultContext)) _, err := db.GetEngine(db.DefaultContext).Delete(&repo_model.Collaboration{UserID: 2, RepoID: 3}) assert.NoError(t, err) @@ -114,7 +114,7 @@ func TestRepository_RecalculateAccesses2(t *testing.T) { // test with non-organization repo assert.NoError(t, unittest.PrepareTestDatabase()) repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) - assert.NoError(t, repo1.GetOwner(db.DefaultContext)) + assert.NoError(t, repo1.LoadOwner(db.DefaultContext)) _, err := db.GetEngine(db.DefaultContext).Delete(&repo_model.Collaboration{UserID: 4, RepoID: 4}) assert.NoError(t, err) diff --git a/models/perm/access/repo_permission.go b/models/perm/access/repo_permission.go index a6bf9b6744a52..ee76e482001a1 100644 --- a/models/perm/access/repo_permission.go +++ b/models/perm/access/repo_permission.go @@ -175,7 +175,7 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use } } - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return } @@ -210,7 +210,7 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use return } - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return } if !repo.Owner.IsOrganization() { @@ -281,7 +281,7 @@ func IsUserRealRepoAdmin(repo *repo_model.Repository, user *user_model.User) (bo return true, nil } - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return false, err } @@ -378,7 +378,7 @@ func HasAccess(ctx context.Context, userID int64, repo *repo_model.Repository) ( // getUsersWithAccessMode returns users that have at least given access mode to the repository. func getUsersWithAccessMode(ctx context.Context, repo *repo_model.Repository, mode perm_model.AccessMode) (_ []*user_model.User, err error) { - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/repo/repo.go b/models/repo/repo.go index e7ec93a22a416..dcffb63fd1970 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -237,7 +237,7 @@ func (repo *Repository) AfterLoad() { // LoadAttributes loads attributes of the repository. func (repo *Repository) LoadAttributes(ctx context.Context) error { // Load owner - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return fmt.Errorf("load owner: %w", err) } @@ -373,8 +373,8 @@ func (repo *Repository) GetUnit(ctx context.Context, tp unit.Type) (*RepoUnit, e return nil, ErrUnitTypeNotExist{tp} } -// GetOwner returns the repository owner -func (repo *Repository) GetOwner(ctx context.Context) (err error) { +// LoadOwner loads owner user +func (repo *Repository) LoadOwner(ctx context.Context) (err error) { if repo.Owner != nil { return nil } @@ -388,7 +388,7 @@ func (repo *Repository) GetOwner(ctx context.Context) (err error) { // It creates a fake object that contains error details // when error occurs. func (repo *Repository) MustOwner(ctx context.Context) *user_model.User { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return &user_model.User{ Name: "error", FullName: err.Error(), diff --git a/models/repo/update.go b/models/repo/update.go index 8dd1097450e4a..f4cb67bb8f0e5 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -143,7 +143,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s return err } - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return err } diff --git a/models/repo/user_repo.go b/models/repo/user_repo.go index 0d5b8579e01c1..cdb266e014a96 100644 --- a/models/repo/user_repo.go +++ b/models/repo/user_repo.go @@ -61,7 +61,7 @@ func GetWatchedRepos(ctx context.Context, userID int64, private bool, listOption // GetRepoAssignees returns all users that have write access and can be assigned to issues // of the repository, func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.User, err error) { - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { return nil, err } @@ -111,7 +111,7 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us // TODO: may be we should have a busy choice for users to block review request to them. func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64) ([]*user_model.User, error) { // Get the owner of the repository - this often already pre-cached and if so saves complexity for the following queries - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return nil, err } diff --git a/models/repo_collaboration_test.go b/models/repo_collaboration_test.go index 94c5ab5291550..95fb35fe6d950 100644 --- a/models/repo_collaboration_test.go +++ b/models/repo_collaboration_test.go @@ -17,7 +17,7 @@ func TestRepository_DeleteCollaboration(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) - assert.NoError(t, repo.GetOwner(db.DefaultContext)) + assert.NoError(t, repo.LoadOwner(db.DefaultContext)) assert.NoError(t, DeleteCollaboration(repo, 4)) unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4}) diff --git a/modules/context/repo.go b/modules/context/repo.go index a38376ff460f1..e4ac65e9618c4 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -273,8 +273,8 @@ func RetrieveBaseRepo(ctx *Context, repo *repo_model.Repository) { } ctx.ServerError("GetBaseRepo", err) return - } else if err = repo.BaseRepo.GetOwner(ctx); err != nil { - ctx.ServerError("BaseRepo.GetOwner", err) + } else if err = repo.BaseRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("BaseRepo.LoadOwner", err) return } } @@ -290,8 +290,8 @@ func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) { } ctx.ServerError("GetTemplateRepo", err) return - } else if err = templateRepo.GetOwner(ctx); err != nil { - ctx.ServerError("TemplateRepo.GetOwner", err) + } else if err = templateRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("TemplateRepo.LoadOwner", err) return } @@ -356,8 +356,8 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) { func repoAssignment(ctx *Context, repo *repo_model.Repository) { var err error - if err = repo.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err = repo.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return } diff --git a/modules/doctor/misc.go b/modules/doctor/misc.go index 73df51390102a..f20b5b26d5484 100644 --- a/modules/doctor/misc.go +++ b/modules/doctor/misc.go @@ -141,7 +141,7 @@ func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) err if owner, has := cache.Get(repo.OwnerID); has { repo.Owner = owner.(*user_model.User) } else { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return err } cache.Add(repo.OwnerID, repo.Owner) diff --git a/modules/repository/collaborator_test.go b/modules/repository/collaborator_test.go index 6cf239d0eadae..c772806819329 100644 --- a/modules/repository/collaborator_test.go +++ b/modules/repository/collaborator_test.go @@ -23,7 +23,7 @@ func TestRepository_AddCollaborator(t *testing.T) { testSuccess := func(repoID, userID int64) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) - assert.NoError(t, repo.GetOwner(db.DefaultContext)) + assert.NoError(t, repo.LoadOwner(db.DefaultContext)) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}) assert.NoError(t, AddCollaborator(db.DefaultContext, repo, user)) unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID}, &user_model.User{ID: userID}) diff --git a/modules/repository/create.go b/modules/repository/create.go index b9a72ad573743..1704ea792cbf8 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -335,7 +335,7 @@ func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error { // CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon... func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return err } @@ -379,8 +379,8 @@ func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibili } if visibilityChanged { - if err = repo.GetOwner(ctx); err != nil { - return fmt.Errorf("getOwner: %w", err) + if err = repo.LoadOwner(ctx); err != nil { + return fmt.Errorf("LoadOwner: %w", err) } if repo.Owner.IsOrganization() { // Organization repository need to recalculate access table when visibility is changed. diff --git a/modules/repository/delete.go b/modules/repository/delete.go index c7e05e666967d..01674db4a105a 100644 --- a/modules/repository/delete.go +++ b/modules/repository/delete.go @@ -16,7 +16,7 @@ func CanUserDelete(repo *repo_model.Repository, user *user_model.User) (bool, er return true, nil } - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return false, err } diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index d50f8efc755f9..6c434c201b53e 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -86,7 +86,7 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) { // LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has // already been populated. func LoadGitRepo(t *testing.T, ctx *context.Context) { - assert.NoError(t, ctx.Repo.Repository.GetOwner(ctx)) + assert.NoError(t, ctx.Repo.Repository.LoadOwner(ctx)) var err error ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath()) assert.NoError(t, err) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index f5db45ffea06b..0395198e209a3 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -201,7 +201,7 @@ func Search(ctx *context.APIContext) { results := make([]*api.Repository, len(repos)) for i, repo := range repos { - if err = repo.GetOwner(ctx); err != nil { + if err = repo.LoadOwner(ctx); err != nil { ctx.JSON(http.StatusInternalServerError, api.SearchError{ OK: false, Error: err.Error(), diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index d566c072fba77..dcb14780a7291 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -119,8 +119,8 @@ func ListMyRepos(ctx *context.APIContext) { results := make([]*api.Repository, len(repos)) for i, repo := range repos { - if err = repo.GetOwner(ctx); err != nil { - ctx.Error(http.StatusInternalServerError, "GetOwner", err) + if err = repo.LoadOwner(ctx); err != nil { + ctx.Error(http.StatusInternalServerError, "LoadOwner", err) return } accessMode, err := access_model.AccessLevel(ctx, ctx.Doer, repo) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 5b6faf4d83bc5..4e40867de204c 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -279,7 +279,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { } return nil } - if err := ci.HeadRepo.GetOwner(ctx); err != nil { + if err := ci.HeadRepo.LoadOwner(ctx); err != nil { if user_model.IsErrUserNotExist(err) { ctx.NotFound("GetUserByName", nil) } else { diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index e82b94b9e847e..9d4ffccc6de56 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -146,8 +146,8 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { // don't allow anonymous pulls if organization is not public if isPublicPull { - if err := repo.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err := repo.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 42dcfb382d8de..62565af50f35f 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2157,8 +2157,8 @@ func UpdatePullReviewRequest(ctx *context.Context) { } if reviewID < 0 { // negative reviewIDs represent team requests - if err := issue.Repo.GetOwner(ctx); err != nil { - ctx.ServerError("issue.Repo.GetOwner", err) + if err := issue.Repo.LoadOwner(ctx); err != nil { + ctx.ServerError("issue.Repo.LoadOwner", err) return } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index ad17005d9049b..c7a59da8a8b15 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -119,8 +119,8 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository { return nil } - if err := forkRepo.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err := forkRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return nil } @@ -1315,8 +1315,8 @@ func CleanUpPullRequest(ctx *context.Context) { } else if err = pr.LoadBaseRepo(ctx); err != nil { ctx.ServerError("LoadBaseRepo", err) return - } else if err = pr.HeadRepo.GetOwner(ctx); err != nil { - ctx.ServerError("HeadRepo.GetOwner", err) + } else if err = pr.HeadRepo.LoadOwner(ctx); err != nil { + ctx.ServerError("HeadRepo.LoadOwner", err) return } diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 436438c4366f0..387a917412f1e 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -650,7 +650,7 @@ func SettingsPost(ctx *context.Context) { ctx.Error(http.StatusNotFound) return } - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { ctx.ServerError("Convert Fork", err) return } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 99043e3ee7e3f..e3c61fa408bdb 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1033,8 +1033,8 @@ func Forks(ctx *context.Context) { } for _, fork := range forks { - if err = fork.GetOwner(ctx); err != nil { - ctx.ServerError("GetOwner", err) + if err = fork.LoadOwner(ctx); err != nil { + ctx.ServerError("LoadOwner", err) return } } diff --git a/services/convert/issue.go b/services/convert/issue.go index 02f25e6e0e6a7..dccf2f3727845 100644 --- a/services/convert/issue.go +++ b/services/convert/issue.go @@ -32,7 +32,7 @@ func ToAPIIssue(ctx context.Context, issue *issues_model.Issue) *api.Issue { if err := issue.LoadRepo(ctx); err != nil { return &api.Issue{} } - if err := issue.Repo.GetOwner(ctx); err != nil { + if err := issue.Repo.LoadOwner(ctx); err != nil { return &api.Issue{} } diff --git a/services/convert/repository.go b/services/convert/repository.go index 5db68e837934d..fc965a94572af 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -100,7 +100,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc hasProjects = true } - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return nil } diff --git a/services/pull/check.go b/services/pull/check.go index ea5cccbdec8ef..310ea2e7147b7 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -261,8 +261,8 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool { // When the commit author is unknown set the BaseRepo owner as merger if merger == nil { if pr.BaseRepo.Owner == nil { - if err = pr.BaseRepo.GetOwner(ctx); err != nil { - log.Error("%-v BaseRepo.GetOwner: %v", pr, err) + if err = pr.BaseRepo.LoadOwner(ctx); err != nil { + log.Error("%-v BaseRepo.LoadOwner: %v", pr, err) return false } } diff --git a/services/pull/merge.go b/services/pull/merge.go index a3d69df8df048..3ac67d91b72f1 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -199,8 +199,8 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U if err := pr.Issue.LoadRepo(hammerCtx); err != nil { log.Error("LoadRepo for issue [%d]: %v", pr.ID, err) } - if err := pr.Issue.Repo.GetOwner(hammerCtx); err != nil { - log.Error("GetOwner for PR [%d]: %v", pr.ID, err) + if err := pr.Issue.Repo.LoadOwner(hammerCtx); err != nil { + log.Error("LoadOwner for PR [%d]: %v", pr.ID, err) } if wasAutoMerged { @@ -573,7 +573,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode } var headUser *user_model.User - err = pr.HeadRepo.GetOwner(ctx) + err = pr.HeadRepo.LoadOwner(ctx) if err != nil { if !user_model.IsErrUserNotExist(err) { log.Error("Can't find user: %d for head repository - %v", pr.HeadRepo.OwnerID, err) diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go index d49a15cea00ad..e0d6b4a158f6b 100644 --- a/services/pull/temp_repo.go +++ b/services/pull/temp_repo.go @@ -38,12 +38,12 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str return "", &repo_model.ErrRepoNotExist{ ID: pr.BaseRepoID, } - } else if err := pr.HeadRepo.GetOwner(ctx); err != nil { - log.Error("HeadRepo.GetOwner: %v", err) - return "", fmt.Errorf("HeadRepo.GetOwner: %w", err) - } else if err := pr.BaseRepo.GetOwner(ctx); err != nil { - log.Error("BaseRepo.GetOwner: %v", err) - return "", fmt.Errorf("BaseRepo.GetOwner: %w", err) + } else if err := pr.HeadRepo.LoadOwner(ctx); err != nil { + log.Error("HeadRepo.LoadOwner: %v", err) + return "", fmt.Errorf("HeadRepo.LoadOwner: %w", err) + } else if err := pr.BaseRepo.LoadOwner(ctx); err != nil { + log.Error("BaseRepo.LoadOwner: %v", err) + return "", fmt.Errorf("BaseRepo.LoadOwner: %w", err) } // Clone base repo. diff --git a/services/repository/review.go b/services/repository/review.go index d30d61ee06683..6b5f096053214 100644 --- a/services/repository/review.go +++ b/services/repository/review.go @@ -12,7 +12,7 @@ import ( // GetReviewerTeams get all teams can be requested to review func GetReviewerTeams(repo *repo_model.Repository) ([]*organization.Team, error) { - if err := repo.GetOwner(db.DefaultContext); err != nil { + if err := repo.LoadOwner(db.DefaultContext); err != nil { return nil, err } if !repo.Owner.IsOrganization() { diff --git a/services/repository/transfer.go b/services/repository/transfer.go index f4afb7e2dec28..8c167552da06f 100644 --- a/services/repository/transfer.go +++ b/services/repository/transfer.go @@ -26,7 +26,7 @@ var repoWorkingPool = sync.NewExclusivePool() // TransferOwnership transfers all corresponding setting from old user to new one. func TransferOwnership(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*organization.Team) error { - if err := repo.GetOwner(ctx); err != nil { + if err := repo.LoadOwner(ctx); err != nil { return err } for _, team := range teams { From feed1ff38f88115f27ea2357a97c21e5277aac88 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 18 Feb 2023 15:41:31 +0200 Subject: [PATCH 05/14] Rename "People" to "Members" in organization page and use a better icon (#22960) `member` is how it's named in the code Closes #22931 Before | After --- | --- ![image](https://user-images.githubusercontent.com/20454870/219781155-69a8476e-0f04-4b70-bda5-ea6fa8ce676c.png) | ![image](https://user-images.githubusercontent.com/20454870/219780887-61644c27-36a2-4e1f-8f98-be3911883b49.png) --------- Signed-off-by: Yarden Shoham Co-authored-by: delvh --- docs/content/page/index.en-us.md | 2 +- options/locale/locale_en-US.ini | 2 +- templates/org/home.tmpl | 2 +- templates/org/menu.tmpl | 2 +- templates/user/overview/header.tmpl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/content/page/index.en-us.md b/docs/content/page/index.en-us.md index a0923db72ae49..60e50efad38c7 100644 --- a/docs/content/page/index.en-us.md +++ b/docs/content/page/index.en-us.md @@ -106,7 +106,7 @@ You can try it out using [the online demo](https://try.gitea.io/). - Permission to create organizations - Permission to import repositories - Organization management - - People + - Members - Teams - Avatar - Hooks diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8410fef81e26c..51ae8c7a02286 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2364,7 +2364,7 @@ org_full_name_holder = Organization Full Name org_name_helper = Organization names should be short and memorable. create_org = Create Organization repo_updated = Updated -people = People +members = Members teams = Teams code = Code lower_members = members diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 1b3cabbde721c..e1adaf1c1b163 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -42,7 +42,7 @@
{{end}}

- {{.locale.Tr "org.people"}} + {{.locale.Tr "org.members"}} diff --git a/templates/org/menu.tmpl b/templates/org/menu.tmpl index 5f543424fce32..7ca47cd32c56e 100644 --- a/templates/org/menu.tmpl +++ b/templates/org/menu.tmpl @@ -18,7 +18,7 @@ {{end}} {{if .IsOrganizationMember}} - {{svg "octicon-organization"}} {{$.locale.Tr "org.people"}} + {{svg "octicon-person"}} {{$.locale.Tr "org.members"}} {{if .NumMembers}}
{{.NumMembers}}
{{end}} diff --git a/templates/user/overview/header.tmpl b/templates/user/overview/header.tmpl index eac23fe53f0f0..2449f5fc323e8 100644 --- a/templates/user/overview/header.tmpl +++ b/templates/user/overview/header.tmpl @@ -39,7 +39,7 @@ {{if .ContextUser.IsOrganization}} {{if .IsOrganizationMember}}
- {{svg "octicon-organization"}} {{$.locale.Tr "org.people"}} + {{svg "octicon-person"}} {{$.locale.Tr "org.members"}} {{if .NumMembers}}
{{.NumMembers}}
{{end}} From 6221a6fd5450692ae27e5602b41fc9ebd9150736 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 18 Feb 2023 20:17:39 +0100 Subject: [PATCH 06/14] Scoped labels (#22585) Add a new "exclusive" option per label. This makes it so that when the label is named `scope/name`, no other label with the same `scope/` prefix can be set on an issue. The scope is determined by the last occurence of `/`, so for example `scope/alpha/name` and `scope/beta/name` are considered to be in different scopes and can coexist. Exclusive scopes are not enforced by any database rules, however they are enforced when editing labels at the models level, automatically removing any existing labels in the same scope when either attaching a new label or replacing all labels. In menus use a circle instead of checkbox to indicate they function as radio buttons per scope. Issue filtering by label ensures that only a single scoped label is selected at a time. Clicking with alt key can be used to remove a scoped label, both when editing individual issues and batch editing. Label rendering refactor for consistency and code simplification: * Labels now consistently have the same shape, emojis and tooltips everywhere. This includes the label list and label assignment menus. * In label list, show description below label same as label menus. * Don't use exactly black/white text colors to look a bit nicer. * Simplify text color computation. There is no point computing luminance in linear color space, as this is a perceptual problem and sRGB is closer to perceptually linear. * Increase height of label assignment menus to show more labels. Showing only 3-4 labels at a time leads to a lot of scrolling. * Render all labels with a new RenderLabel template helper function. Label creation and editing in multiline modal menu: * Change label creation to open a modal menu like label editing. * Change menu layout to place name, description and colors on separate lines. * Don't color cancel button red in label editing modal menu. * Align text to the left in model menu for better readability and consistent with settings layout elsewhere. Custom exclusive scoped label rendering: * Display scoped label prefix and suffix with slightly darker and lighter background color respectively, and a slanted edge between them similar to the `/` symbol. * In menus exclusive labels are grouped with a divider line. --------- Co-authored-by: Yarden Shoham Co-authored-by: Lauris BH --- models/fixtures/issue.yml | 17 +++ models/fixtures/label.yml | 45 ++++++++ models/fixtures/repository.yml | 12 ++ models/fixtures/user.yml | 2 +- models/issues/issue.go | 27 +++++ models/issues/issue_test.go | 19 ++-- models/issues/label.go | 106 +++++++++++------- models/issues/label_test.go | 45 +++++++- .../Test_DeleteOrphanedIssueLabels/label.yml | 5 + models/migrations/migrations.go | 2 + models/migrations/v1_19/v244.go | 16 +++ modules/migration/label.go | 1 + modules/structs/issue_label.go | 9 +- modules/templates/helper.go | 70 +++++++++++- options/locale/locale_en-US.ini | 9 +- routers/api/v1/org/label.go | 4 + routers/api/v1/repo/label.go | 4 + routers/web/org/org_labels.go | 2 + routers/web/repo/issue.go | 18 ++- routers/web/repo/issue_label.go | 18 ++- services/convert/issue.go | 1 + services/forms/repo_form.go | 1 + services/migrations/main_test.go | 1 + services/repository/template.go | 1 + templates/projects/view.tmpl | 2 +- .../repo/issue/labels/edit_delete_label.tmpl | 42 ++++--- templates/repo/issue/labels/label.tmpl | 6 +- templates/repo/issue/labels/label_list.tmpl | 34 +++--- templates/repo/issue/labels/label_new.tmpl | 56 ++++++--- templates/repo/issue/list.tmpl | 16 ++- templates/repo/issue/milestone_issues.tmpl | 4 +- templates/repo/issue/new_form.tmpl | 16 ++- .../repo/issue/view_content/sidebar.tmpl | 16 ++- templates/repo/projects/view.tmpl | 2 +- templates/shared/issuelist.tmpl | 2 +- templates/swagger/v1_json.tmpl | 18 ++- tests/integration/api_issue_test.go | 14 +-- tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/issue_test.go | 14 +-- web_src/js/components/ContextPopup.vue | 23 +--- web_src/js/features/common-issue.js | 5 +- web_src/js/features/comp/LabelEdit.js | 69 ++++++++++-- web_src/js/features/repo-legacy.js | 74 +++++++----- web_src/js/features/repo-projects.js | 20 +--- web_src/js/utils.js | 15 +++ web_src/less/_base.less | 12 +- web_src/less/_repository.less | 54 ++++++--- 47 files changed, 709 insertions(+), 242 deletions(-) create mode 100644 models/migrations/v1_19/v244.go diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 4dea8add138ed..174345ff5a1fc 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -287,3 +287,20 @@ created_unix: 1602935696 updated_unix: 1602935696 is_locked: false + +- + id: 18 + repo_id: 55 + index: 1 + poster_id: 2 + original_author_id: 0 + name: issue for scoped labels + content: content + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: false + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false diff --git a/models/fixtures/label.yml b/models/fixtures/label.yml index 57bf80445712f..ab4d5ef944045 100644 --- a/models/fixtures/label.yml +++ b/models/fixtures/label.yml @@ -4,6 +4,7 @@ org_id: 0 name: label1 color: '#abcdef' + exclusive: false num_issues: 2 num_closed_issues: 0 @@ -13,6 +14,7 @@ org_id: 0 name: label2 color: '#000000' + exclusive: false num_issues: 1 num_closed_issues: 1 @@ -22,6 +24,7 @@ org_id: 3 name: orglabel3 color: '#abcdef' + exclusive: false num_issues: 0 num_closed_issues: 0 @@ -31,6 +34,7 @@ org_id: 3 name: orglabel4 color: '#000000' + exclusive: false num_issues: 1 num_closed_issues: 0 @@ -40,5 +44,46 @@ org_id: 0 name: pull-test-label color: '#000000' + exclusive: false + num_issues: 0 + num_closed_issues: 0 + +- + id: 6 + repo_id: 55 + org_id: 0 + name: unscoped_label + color: '#000000' + exclusive: false + num_issues: 0 + num_closed_issues: 0 + +- + id: 7 + repo_id: 55 + org_id: 0 + name: scope/label1 + color: '#000000' + exclusive: true + num_issues: 0 + num_closed_issues: 0 + +- + id: 8 + repo_id: 55 + org_id: 0 + name: scope/label2 + color: '#000000' + exclusive: true + num_issues: 0 + num_closed_issues: 0 + +- + id: 9 + repo_id: 55 + org_id: 0 + name: scope/subscope/label2 + color: '#000000' + exclusive: true num_issues: 0 num_closed_issues: 0 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index ef3cfbbbec7c5..58f9b919acfbc 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1622,3 +1622,15 @@ is_archived: false is_private: true status: 0 + +- + id: 55 + owner_id: 2 + owner_name: user2 + lower_name: scoped_label + name: scoped_label + is_empty: false + is_archived: false + is_private: true + num_issues: 1 + status: 0 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 63a5e0f890552..0a1d85b48b558 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -66,7 +66,7 @@ num_followers: 2 num_following: 1 num_stars: 2 - num_repos: 10 + num_repos: 11 num_teams: 0 num_members: 0 visibility: 0 diff --git a/models/issues/issue.go b/models/issues/issue.go index b1c7fdbf7ed27..9d7dea01772cc 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -538,6 +538,31 @@ func (ts labelSorter) Swap(i, j int) { []*Label(ts)[i], []*Label(ts)[j] = []*Label(ts)[j], []*Label(ts)[i] } +// Ensure only one label of a given scope exists, with labels at the end of the +// array getting preference over earlier ones. +func RemoveDuplicateExclusiveLabels(labels []*Label) []*Label { + validLabels := make([]*Label, 0, len(labels)) + + for i, label := range labels { + scope := label.ExclusiveScope() + if scope != "" { + foundOther := false + for _, otherLabel := range labels[i+1:] { + if otherLabel.ExclusiveScope() == scope { + foundOther = true + break + } + } + if foundOther { + continue + } + } + validLabels = append(validLabels, label) + } + + return validLabels +} + // ReplaceIssueLabels removes all current labels and add new labels to the issue. // Triggers appropriate WebHooks, if any. func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) { @@ -555,6 +580,8 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e return err } + labels = RemoveDuplicateExclusiveLabels(labels) + sort.Sort(labelSorter(labels)) sort.Sort(labelSorter(issue.Labels)) diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index de1da19ab9fad..3a83d8d2b791e 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -25,7 +25,7 @@ import ( func TestIssue_ReplaceLabels(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - testSuccess := func(issueID int64, labelIDs []int64) { + testSuccess := func(issueID int64, labelIDs, expectedLabelIDs []int64) { issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issueID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) @@ -35,15 +35,20 @@ func TestIssue_ReplaceLabels(t *testing.T) { labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID, RepoID: repo.ID}) } assert.NoError(t, issues_model.ReplaceIssueLabels(issue, labels, doer)) - unittest.AssertCount(t, &issues_model.IssueLabel{IssueID: issueID}, len(labelIDs)) - for _, labelID := range labelIDs { + unittest.AssertCount(t, &issues_model.IssueLabel{IssueID: issueID}, len(expectedLabelIDs)) + for _, labelID := range expectedLabelIDs { unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issueID, LabelID: labelID}) } } - testSuccess(1, []int64{2}) - testSuccess(1, []int64{1, 2}) - testSuccess(1, []int64{}) + testSuccess(1, []int64{2}, []int64{2}) + testSuccess(1, []int64{1, 2}, []int64{1, 2}) + testSuccess(1, []int64{}, []int64{}) + + // mutually exclusive scoped labels 7 and 8 + testSuccess(18, []int64{6, 7}, []int64{6, 7}) + testSuccess(18, []int64{7, 8}, []int64{8}) + testSuccess(18, []int64{6, 8, 7}, []int64{6, 7}) } func Test_GetIssueIDsByRepoID(t *testing.T) { @@ -523,5 +528,5 @@ func TestCountIssues(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{}) assert.NoError(t, err) - assert.EqualValues(t, 17, count) + assert.EqualValues(t, 18, count) } diff --git a/models/issues/label.go b/models/issues/label.go index dbb7a139effdf..0dd12fb5c9af0 100644 --- a/models/issues/label.go +++ b/models/issues/label.go @@ -7,8 +7,6 @@ package issues import ( "context" "fmt" - "html/template" - "math" "regexp" "strconv" "strings" @@ -89,6 +87,7 @@ type Label struct { RepoID int64 `xorm:"INDEX"` OrgID int64 `xorm:"INDEX"` Name string + Exclusive bool Description string Color string `xorm:"VARCHAR(7)"` NumIssues int @@ -128,18 +127,22 @@ func (label *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) } // LoadSelectedLabelsAfterClick calculates the set of selected labels when a label is clicked -func (label *Label) LoadSelectedLabelsAfterClick(currentSelectedLabels []int64) { +func (label *Label) LoadSelectedLabelsAfterClick(currentSelectedLabels []int64, currentSelectedExclusiveScopes []string) { var labelQuerySlice []string labelSelected := false labelID := strconv.FormatInt(label.ID, 10) - for _, s := range currentSelectedLabels { + labelScope := label.ExclusiveScope() + for i, s := range currentSelectedLabels { if s == label.ID { labelSelected = true } else if -s == label.ID { labelSelected = true label.IsExcluded = true } else if s != 0 { - labelQuerySlice = append(labelQuerySlice, strconv.FormatInt(s, 10)) + // Exclude other labels in the same scope from selection + if s < 0 || labelScope == "" || labelScope != currentSelectedExclusiveScopes[i] { + labelQuerySlice = append(labelQuerySlice, strconv.FormatInt(s, 10)) + } } } if !labelSelected { @@ -159,49 +162,43 @@ func (label *Label) BelongsToRepo() bool { return label.RepoID > 0 } -// SrgbToLinear converts a component of an sRGB color to its linear intensity -// See: https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation_(sRGB_to_CIE_XYZ) -func SrgbToLinear(color uint8) float64 { - flt := float64(color) / 255 - if flt <= 0.04045 { - return flt / 12.92 +// Get color as RGB values in 0..255 range +func (label *Label) ColorRGB() (float64, float64, float64, error) { + color, err := strconv.ParseUint(label.Color[1:], 16, 64) + if err != nil { + return 0, 0, 0, err } - return math.Pow((flt+0.055)/1.055, 2.4) -} - -// Luminance returns the luminance of an sRGB color -func Luminance(color uint32) float64 { - r := SrgbToLinear(uint8(0xFF & (color >> 16))) - g := SrgbToLinear(uint8(0xFF & (color >> 8))) - b := SrgbToLinear(uint8(0xFF & color)) - // luminance ratios for sRGB - return 0.2126*r + 0.7152*g + 0.0722*b + r := float64(uint8(0xFF & (uint32(color) >> 16))) + g := float64(uint8(0xFF & (uint32(color) >> 8))) + b := float64(uint8(0xFF & uint32(color))) + return r, g, b, nil } -// LuminanceThreshold is the luminance at which white and black appear to have the same contrast -// i.e. x such that 1.05 / (x + 0.05) = (x + 0.05) / 0.05 -// i.e. math.Sqrt(1.05*0.05) - 0.05 -const LuminanceThreshold float64 = 0.179 - -// ForegroundColor calculates the text color for labels based -// on their background color. -func (label *Label) ForegroundColor() template.CSS { +// Determine if label text should be light or dark to be readable on background color +func (label *Label) UseLightTextColor() bool { if strings.HasPrefix(label.Color, "#") { - if color, err := strconv.ParseUint(label.Color[1:], 16, 64); err == nil { - // NOTE: see web_src/js/components/ContextPopup.vue for similar implementation - luminance := Luminance(uint32(color)) - - // prefer white or black based upon contrast - if luminance < LuminanceThreshold { - return template.CSS("#fff") - } - return template.CSS("#000") + if r, g, b, err := label.ColorRGB(); err == nil { + // Perceived brightness from: https://www.w3.org/TR/AERT/#color-contrast + // In the future WCAG 3 APCA may be a better solution + brightness := (0.299*r + 0.587*g + 0.114*b) / 255 + return brightness < 0.35 } } - // default to black - return template.CSS("#000") + return false +} + +// Return scope substring of label name, or empty string if none exists +func (label *Label) ExclusiveScope() string { + if !label.Exclusive { + return "" + } + lastIndex := strings.LastIndex(label.Name, "/") + if lastIndex == -1 || lastIndex == 0 || lastIndex == len(label.Name)-1 { + return "" + } + return label.Name[:lastIndex] } // NewLabel creates a new label @@ -253,7 +250,7 @@ func UpdateLabel(l *Label) error { if !LabelColorPattern.MatchString(l.Color) { return fmt.Errorf("bad color code: %s", l.Color) } - return updateLabelCols(db.DefaultContext, l, "name", "description", "color") + return updateLabelCols(db.DefaultContext, l, "name", "description", "color", "exclusive") } // DeleteLabel delete a label @@ -620,6 +617,29 @@ func newIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *user_m return updateLabelCols(ctx, label, "num_issues", "num_closed_issue") } +// Remove all issue labels in the given exclusive scope +func RemoveDuplicateExclusiveIssueLabels(ctx context.Context, issue *Issue, label *Label, doer *user_model.User) (err error) { + scope := label.ExclusiveScope() + if scope == "" { + return nil + } + + var toRemove []*Label + for _, issueLabel := range issue.Labels { + if label.ID != issueLabel.ID && issueLabel.ExclusiveScope() == scope { + toRemove = append(toRemove, issueLabel) + } + } + + for _, issueLabel := range toRemove { + if err = deleteIssueLabel(ctx, issue, issueLabel, doer); err != nil { + return err + } + } + + return nil +} + // NewIssueLabel creates a new issue-label relation. func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error) { if HasIssueLabel(db.DefaultContext, issue.ID, label.ID) { @@ -641,6 +661,10 @@ func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error return nil } + if err = RemoveDuplicateExclusiveIssueLabels(ctx, issue, label, doer); err != nil { + return nil + } + if err = newIssueLabel(ctx, issue, label, doer); err != nil { return err } diff --git a/models/issues/label_test.go b/models/issues/label_test.go index 239e328d475c4..0e45e0db0bac6 100644 --- a/models/issues/label_test.go +++ b/models/issues/label_test.go @@ -4,7 +4,6 @@ package issues_test import ( - "html/template" "testing" "code.gitea.io/gitea/models/db" @@ -25,13 +24,22 @@ func TestLabel_CalOpenIssues(t *testing.T) { assert.EqualValues(t, 2, label.NumOpenIssues) } -func TestLabel_ForegroundColor(t *testing.T) { +func TestLabel_TextColor(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1}) - assert.Equal(t, template.CSS("#000"), label.ForegroundColor()) + assert.False(t, label.UseLightTextColor()) label = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 2}) - assert.Equal(t, template.CSS("#fff"), label.ForegroundColor()) + assert.True(t, label.UseLightTextColor()) +} + +func TestLabel_ExclusiveScope(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 7}) + assert.Equal(t, "scope", label.ExclusiveScope()) + + label = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 9}) + assert.Equal(t, "scope/subscope", label.ExclusiveScope()) } func TestNewLabels(t *testing.T) { @@ -266,6 +274,7 @@ func TestUpdateLabel(t *testing.T) { Color: "#ffff00", Name: "newLabelName", Description: label.Description, + Exclusive: false, } label.Color = update.Color label.Name = update.Name @@ -323,6 +332,34 @@ func TestNewIssueLabel(t *testing.T) { unittest.CheckConsistencyFor(t, &issues_model.Issue{}, &issues_model.Label{}) } +func TestNewIssueExclusiveLabel(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 18}) + doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + + otherLabel := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 6}) + exclusiveLabelA := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 7}) + exclusiveLabelB := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 8}) + + // coexisting regular and exclusive label + assert.NoError(t, issues_model.NewIssueLabel(issue, otherLabel, doer)) + assert.NoError(t, issues_model.NewIssueLabel(issue, exclusiveLabelA, doer)) + unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: otherLabel.ID}) + unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelA.ID}) + + // exclusive label replaces existing one + assert.NoError(t, issues_model.NewIssueLabel(issue, exclusiveLabelB, doer)) + unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: otherLabel.ID}) + unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelB.ID}) + unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelA.ID}) + + // exclusive label replaces existing one again + assert.NoError(t, issues_model.NewIssueLabel(issue, exclusiveLabelA, doer)) + unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: otherLabel.ID}) + unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelA.ID}) + unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: exclusiveLabelB.ID}) +} + func TestNewIssueLabels(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) label1 := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1}) diff --git a/models/migrations/fixtures/Test_DeleteOrphanedIssueLabels/label.yml b/models/migrations/fixtures/Test_DeleteOrphanedIssueLabels/label.yml index d651c87d5b0d6..085b7f0882d5e 100644 --- a/models/migrations/fixtures/Test_DeleteOrphanedIssueLabels/label.yml +++ b/models/migrations/fixtures/Test_DeleteOrphanedIssueLabels/label.yml @@ -4,6 +4,7 @@ org_id: 0 name: label1 color: '#abcdef' + exclusive: false num_issues: 2 num_closed_issues: 0 @@ -13,6 +14,7 @@ org_id: 0 name: label2 color: '#000000' + exclusive: false num_issues: 1 num_closed_issues: 1 - @@ -21,6 +23,7 @@ org_id: 3 name: orglabel3 color: '#abcdef' + exclusive: false num_issues: 0 num_closed_issues: 0 @@ -30,6 +33,7 @@ org_id: 3 name: orglabel4 color: '#000000' + exclusive: false num_issues: 1 num_closed_issues: 0 @@ -39,5 +43,6 @@ org_id: 0 name: pull-test-label color: '#000000' + exclusive: false num_issues: 0 num_closed_issues: 0 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 73c44f008a6cc..c7497becd1130 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -459,6 +459,8 @@ var migrations = []Migration{ NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable), // v242 -> v243 NewMigration("Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText), + // v243 -> v244 + NewMigration("Add exclusive label", v1_19.AddExclusiveLabel), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_19/v244.go b/models/migrations/v1_19/v244.go new file mode 100644 index 0000000000000..55bbfafb2fa4a --- /dev/null +++ b/models/migrations/v1_19/v244.go @@ -0,0 +1,16 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_19 //nolint + +import ( + "xorm.io/xorm" +) + +func AddExclusiveLabel(x *xorm.Engine) error { + type Label struct { + Exclusive bool + } + + return x.Sync(new(Label)) +} diff --git a/modules/migration/label.go b/modules/migration/label.go index 38f0eb10dad64..4927be3c0bd11 100644 --- a/modules/migration/label.go +++ b/modules/migration/label.go @@ -9,4 +9,5 @@ type Label struct { Name string `json:"name"` Color string `json:"color"` Description string `json:"description"` + Exclusive bool `json:"exclusive"` } diff --git a/modules/structs/issue_label.go b/modules/structs/issue_label.go index 5c622797f4417..5bb6cc3b845b5 100644 --- a/modules/structs/issue_label.go +++ b/modules/structs/issue_label.go @@ -9,6 +9,8 @@ package structs type Label struct { ID int64 `json:"id"` Name string `json:"name"` + // example: false + Exclusive bool `json:"exclusive"` // example: 00aabb Color string `json:"color"` Description string `json:"description"` @@ -19,6 +21,8 @@ type Label struct { type CreateLabelOption struct { // required:true Name string `json:"name" binding:"Required"` + // example: false + Exclusive bool `json:"exclusive"` // required:true // example: #00aabb Color string `json:"color" binding:"Required"` @@ -27,7 +31,10 @@ type CreateLabelOption struct { // EditLabelOption options for editing a label type EditLabelOption struct { - Name *string `json:"name"` + Name *string `json:"name"` + // example: false + Exclusive *bool `json:"exclusive"` + // example: #00aabb Color *string `json:"color"` Description *string `json:"description"` } diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 8f8f565c1f141..4ffd0a5dee03b 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -7,10 +7,12 @@ package templates import ( "bytes" "context" + "encoding/hex" "errors" "fmt" "html" "html/template" + "math" "mime" "net/url" "path/filepath" @@ -382,6 +384,9 @@ func NewFuncMap() []template.FuncMap { // the table is NOT sorted with this header return "" }, + "RenderLabel": func(label *issues_model.Label) template.HTML { + return template.HTML(RenderLabel(label)) + }, "RenderLabels": func(labels []*issues_model.Label, repoLink string) template.HTML { htmlCode := `` for _, label := range labels { @@ -389,8 +394,8 @@ func NewFuncMap() []template.FuncMap { if label == nil { continue } - htmlCode += fmt.Sprintf("
%s ", - repoLink, label.ID, label.ForegroundColor(), label.Color, html.EscapeString(label.Description), RenderEmoji(label.Name)) + htmlCode += fmt.Sprintf("%s ", + repoLink, label.ID, RenderLabel(label)) } htmlCode += "" return template.HTML(htmlCode) @@ -801,6 +806,67 @@ func RenderIssueTitle(ctx context.Context, text, urlPrefix string, metas map[str return template.HTML(renderedText) } +// RenderLabel renders a label +func RenderLabel(label *issues_model.Label) string { + labelScope := label.ExclusiveScope() + + textColor := "#111" + if label.UseLightTextColor() { + textColor = "#eee" + } + + description := emoji.ReplaceAliases(template.HTMLEscapeString(label.Description)) + + if labelScope == "" { + // Regular label + return fmt.Sprintf("
%s
", + textColor, label.Color, description, RenderEmoji(label.Name)) + } + + // Scoped label + scopeText := RenderEmoji(labelScope) + itemText := RenderEmoji(label.Name[len(labelScope)+1:]) + + itemColor := label.Color + scopeColor := label.Color + if r, g, b, err := label.ColorRGB(); err == nil { + // Make scope and item background colors slightly darker and lighter respectively. + // More contrast needed with higher luminance, empirically tweaked. + luminance := (0.299*r + 0.587*g + 0.114*b) / 255 + contrast := 0.01 + luminance*0.06 + // Ensure we add the same amount of contrast also near 0 and 1. + darken := contrast + math.Max(luminance+contrast-1.0, 0.0) + lighten := contrast + math.Max(contrast-luminance, 0.0) + // Compute factor to keep RGB values proportional. + darkenFactor := math.Max(luminance-darken, 0.0) / math.Max(luminance, 1.0/255.0) + lightenFactor := math.Min(luminance+lighten, 1.0) / math.Max(luminance, 1.0/255.0) + + scopeBytes := []byte{ + uint8(math.Min(math.Round(r*darkenFactor), 255)), + uint8(math.Min(math.Round(g*darkenFactor), 255)), + uint8(math.Min(math.Round(b*darkenFactor), 255)), + } + itemBytes := []byte{ + uint8(math.Min(math.Round(r*lightenFactor), 255)), + uint8(math.Min(math.Round(g*lightenFactor), 255)), + uint8(math.Min(math.Round(b*lightenFactor), 255)), + } + + itemColor = "#" + hex.EncodeToString(itemBytes) + scopeColor = "#" + hex.EncodeToString(scopeBytes) + } + + return fmt.Sprintf(""+ + "
%s
"+ + "
 
"+ + "
%s
"+ + "
", + description, + textColor, scopeColor, scopeText, + itemColor, scopeColor, + textColor, itemColor, itemText) +} + // RenderEmoji renders html text with emoji post processors func RenderEmoji(text string) template.HTML { renderedText, err := markup.RenderEmoji(template.HTMLEscapeString(text)) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 51ae8c7a02286..411a585c81d60 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1395,9 +1395,12 @@ issues.sign_in_require_desc = Sign in to join this conversation issues.edit = Edit issues.cancel = Cancel issues.save = Save -issues.label_title = Label name -issues.label_description = Label description -issues.label_color = Label color +issues.label_title = Name +issues.label_description = Description +issues.label_color = Color +issues.label_exclusive = Exclusive +issues.label_exclusive_desc = Name the label scope/item to make it mutually exclusive with other scope/ labels. +issues.label_exclusive_warning = Any conflicting scoped labels will be removed when editing the labels of an issue or pull request. issues.label_count = %d labels issues.label_open_issues = %d open issues/pull requests issues.label_edit = Edit diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index 5d0455cdd4f41..938fe79df64cc 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -94,6 +94,7 @@ func CreateLabel(ctx *context.APIContext) { label := &issues_model.Label{ Name: form.Name, + Exclusive: form.Exclusive, Color: form.Color, OrgID: ctx.Org.Organization.ID, Description: form.Description, @@ -195,6 +196,9 @@ func EditLabel(ctx *context.APIContext) { if form.Name != nil { label.Name = *form.Name } + if form.Exclusive != nil { + label.Exclusive = *form.Exclusive + } if form.Color != nil { label.Color = strings.Trim(*form.Color, " ") if len(label.Color) == 6 { diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 411c0274e6c78..a06d26e837335 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -156,6 +156,7 @@ func CreateLabel(ctx *context.APIContext) { label := &issues_model.Label{ Name: form.Name, + Exclusive: form.Exclusive, Color: form.Color, RepoID: ctx.Repo.Repository.ID, Description: form.Description, @@ -218,6 +219,9 @@ func EditLabel(ctx *context.APIContext) { if form.Name != nil { label.Name = *form.Name } + if form.Exclusive != nil { + label.Exclusive = *form.Exclusive + } if form.Color != nil { label.Color = strings.Trim(*form.Color, " ") if len(label.Color) == 6 { diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go index 1c910a93a50bd..e96627762bd54 100644 --- a/routers/web/org/org_labels.go +++ b/routers/web/org/org_labels.go @@ -45,6 +45,7 @@ func NewLabel(ctx *context.Context) { l := &issues_model.Label{ OrgID: ctx.Org.Organization.ID, Name: form.Title, + Exclusive: form.Exclusive, Description: form.Description, Color: form.Color, } @@ -70,6 +71,7 @@ func UpdateLabel(ctx *context.Context) { } l.Name = form.Title + l.Exclusive = form.Exclusive l.Description = form.Description l.Color = form.Color if err := issues_model.UpdateLabel(l); err != nil { diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 62565af50f35f..05ba26a70cda6 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -332,8 +332,24 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti labels = append(labels, orgLabels...) } + // Get the exclusive scope for every label ID + labelExclusiveScopes := make([]string, 0, len(labelIDs)) + for _, labelID := range labelIDs { + foundExclusiveScope := false + for _, label := range labels { + if label.ID == labelID || label.ID == -labelID { + labelExclusiveScopes = append(labelExclusiveScopes, label.ExclusiveScope()) + foundExclusiveScope = true + break + } + } + if !foundExclusiveScope { + labelExclusiveScopes = append(labelExclusiveScopes, "") + } + } + for _, l := range labels { - l.LoadSelectedLabelsAfterClick(labelIDs) + l.LoadSelectedLabelsAfterClick(labelIDs, labelExclusiveScopes) } ctx.Data["Labels"] = labels ctx.Data["NumLabels"] = len(labels) diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 66e8920bd99c0..d4fece9f014b7 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -113,6 +113,7 @@ func NewLabel(ctx *context.Context) { l := &issues_model.Label{ RepoID: ctx.Repo.Repository.ID, Name: form.Title, + Exclusive: form.Exclusive, Description: form.Description, Color: form.Color, } @@ -138,6 +139,7 @@ func UpdateLabel(ctx *context.Context) { } l.Name = form.Title + l.Exclusive = form.Exclusive l.Description = form.Description l.Color = form.Color if err := issues_model.UpdateLabel(l); err != nil { @@ -175,7 +177,7 @@ func UpdateIssueLabel(ctx *context.Context) { return } } - case "attach", "detach", "toggle": + case "attach", "detach", "toggle", "toggle-alt": label, err := issues_model.GetLabelByID(ctx, ctx.FormInt64("id")) if err != nil { if issues_model.IsErrRepoLabelNotExist(err) { @@ -189,12 +191,18 @@ func UpdateIssueLabel(ctx *context.Context) { if action == "toggle" { // detach if any issues already have label, otherwise attach action = "attach" - for _, issue := range issues { - if issues_model.HasIssueLabel(ctx, issue.ID, label.ID) { - action = "detach" - break + if label.ExclusiveScope() == "" { + for _, issue := range issues { + if issues_model.HasIssueLabel(ctx, issue.ID, label.ID) { + action = "detach" + break + } } } + } else if action == "toggle-alt" { + // always detach with alt key pressed, to be able to remove + // scoped labels + action = "detach" } if action == "attach" { diff --git a/services/convert/issue.go b/services/convert/issue.go index dccf2f3727845..e79fcfcccb7bb 100644 --- a/services/convert/issue.go +++ b/services/convert/issue.go @@ -182,6 +182,7 @@ func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_m result := &api.Label{ ID: label.ID, Name: label.Name, + Exclusive: label.Exclusive, Color: strings.TrimLeft(label.Color, "#"), Description: label.Description, } diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index c1b58009688b4..ff0916f8e195c 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -564,6 +564,7 @@ func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) b type CreateLabelForm struct { ID int64 Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"` + Exclusive bool `form:"exclusive"` Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"` Color string `binding:"Required;MaxSize(7)" locale:"repo.issues.label_color"` } diff --git a/services/migrations/main_test.go b/services/migrations/main_test.go index 30875f6e5ba4c..42c433fb0031f 100644 --- a/services/migrations/main_test.go +++ b/services/migrations/main_test.go @@ -59,6 +59,7 @@ func assertCommentsEqual(t *testing.T, expected, actual []*base.Comment) { func assertLabelEqual(t *testing.T, expected, actual *base.Label) { assert.Equal(t, expected.Name, actual.Name) + assert.Equal(t, expected.Exclusive, actual.Exclusive) assert.Equal(t, expected.Color, actual.Color) assert.Equal(t, expected.Description, actual.Description) } diff --git a/services/repository/template.go b/services/repository/template.go index 13e0749869396..8c75948c418b8 100644 --- a/services/repository/template.go +++ b/services/repository/template.go @@ -31,6 +31,7 @@ func GenerateIssueLabels(ctx context.Context, templateRepo, generateRepo *repo_m newLabels = append(newLabels, &issues_model.Label{ RepoID: generateRepo.ID, Name: templateLabel.Name, + Exclusive: templateLabel.Exclusive, Description: templateLabel.Description, Color: templateLabel.Color, }) diff --git a/templates/projects/view.tmpl b/templates/projects/view.tmpl index 112e6be7ce41f..b25cf2526ebe5 100644 --- a/templates/projects/view.tmpl +++ b/templates/projects/view.tmpl @@ -234,7 +234,7 @@ {{if or .Labels .Assignees}}
{{range .Labels}} - {{.Name | RenderEmoji}} + {{RenderLabel .}} {{end}}
{{range .Assignees}} diff --git a/templates/repo/issue/labels/edit_delete_label.tmpl b/templates/repo/issue/labels/edit_delete_label.tmpl index a0479dde1bf3f..450061e8357c2 100644 --- a/templates/repo/issue/labels/edit_delete_label.tmpl +++ b/templates/repo/issue/labels/edit_delete_label.tmpl @@ -26,31 +26,45 @@
{{.CsrfTokenHtml}} -
-
-
- -
+
+ +
+
-
-
- -
+
+
+
+ +
+
+ {{.locale.Tr "repo.issues.label_exclusive_desc" | Safe}} +
+ {{svg "octicon-alert"}} {{.locale.Tr "repo.issues.label_exclusive_warning" | Safe}} +
+
+
+ +
+ +
+
+
+
-
-
- {{template "repo/issue/label_precolors"}} +
+ {{template "repo/issue/label_precolors"}} +
-
+
{{.locale.Tr "cancel"}}
-
+
{{.locale.Tr "save"}}
diff --git a/templates/repo/issue/labels/label.tmpl b/templates/repo/issue/labels/label.tmpl index 0afe5cb6e7b1e..87d8f0c41c2c3 100644 --- a/templates/repo/issue/labels/label.tmpl +++ b/templates/repo/issue/labels/label.tmpl @@ -1,9 +1,7 @@ - {{.label.Name | RenderEmoji}} + {{RenderLabel .label}} diff --git a/templates/repo/issue/labels/label_list.tmpl b/templates/repo/issue/labels/label_list.tmpl index 464c9fe208d58..e8f00fa256ce8 100644 --- a/templates/repo/issue/labels/label_list.tmpl +++ b/templates/repo/issue/labels/label_list.tmpl @@ -30,28 +30,24 @@ {{range .Labels}}
  • -
    -
    {{svg "octicon-tag"}} {{.Name | RenderEmoji}}
    +
    + {{RenderLabel .}} + {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    -
    -
    - {{.Description | RenderEmoji}} -
    -
    -
    - {{svg "octicon-issue-opened"}} {{$.locale.Tr "repo.issues.label_open_issues" .NumOpenRepoIssues}} +
    diff --git a/templates/repo/issue/labels/label_new.tmpl b/templates/repo/issue/labels/label_new.tmpl index 035a4db8000fc..62f7155b745c8 100644 --- a/templates/repo/issue/labels/label_new.tmpl +++ b/templates/repo/issue/labels/label_new.tmpl @@ -1,27 +1,47 @@ -
    -
    - {{.CsrfTokenHtml}} -
    -
    +
    @@ -161,7 +161,7 @@ diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 8fbd9d256a20e..2a6fcaa995bd4 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -53,14 +53,26 @@ {{end}}
    {{.locale.Tr "repo.issues.new.clear_labels"}}
    {{if or .Labels .OrgLabels}} + {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}}
    + {{$previousExclusiveScope := "_no_scope"}} {{range .OrgLabels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}} {{else}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 9ba46f3715d6e..8cd34ede6e982 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -123,13 +123,25 @@ {{end}}
    {{.locale.Tr "repo.issues.new.clear_labels"}}
    {{if or .Labels .OrgLabels}} + {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}}
    + {{$previousExclusiveScope := "_no_scope"}} {{range .OrgLabels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}} {{else}} diff --git a/templates/repo/projects/view.tmpl b/templates/repo/projects/view.tmpl index de0911e6cde80..a4ada87353562 100644 --- a/templates/repo/projects/view.tmpl +++ b/templates/repo/projects/view.tmpl @@ -245,7 +245,7 @@ {{if or .Labels .Assignees}}
    {{range .Labels}} - {{.Name | RenderEmoji}} + {{RenderLabel .}} {{end}}
    {{range .Assignees}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index a246b700930fe..a43047c79de91 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -42,7 +42,7 @@ {{end}} {{range .Labels}} - {{.Name | RenderEmoji}} + {{RenderLabel .}} {{end}}
    diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 00fc3b60c4548..2a675766abc92 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -15348,6 +15348,11 @@ "type": "string", "x-go-name": "Description" }, + "exclusive": { + "type": "boolean", + "x-go-name": "Exclusive", + "example": false + }, "name": { "type": "string", "x-go-name": "Name" @@ -16283,12 +16288,18 @@ "properties": { "color": { "type": "string", - "x-go-name": "Color" + "x-go-name": "Color", + "example": "#00aabb" }, "description": { "type": "string", "x-go-name": "Description" }, + "exclusive": { + "type": "boolean", + "x-go-name": "Exclusive", + "example": false + }, "name": { "type": "string", "x-go-name": "Name" @@ -17615,6 +17626,11 @@ "type": "string", "x-go-name": "Description" }, + "exclusive": { + "type": "boolean", + "x-go-name": "Exclusive", + "example": false + }, "id": { "type": "integer", "format": "int64", diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index 2f27978a371d6..4344c15ea45f3 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -174,7 +174,7 @@ func TestAPISearchIssues(t *testing.T) { token := getUserToken(t, "user2") // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 15 // from the fixtures + expectedIssueCount := 16 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -198,7 +198,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 8) + assert.Len(t, apiIssues, 9) query.Del("since") query.Del("before") @@ -214,15 +214,15 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count")) - assert.Len(t, apiIssues, 17) + assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) + assert.Len(t, apiIssues, 18) query.Add("limit", "10") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 10) query = url.Values{"assigned": {"true"}, "state": {"all"}, "token": {token}} @@ -251,7 +251,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 6) + assert.Len(t, apiIssues, 7) query = url.Values{"owner": {"user3"}, "token": {token}} // organization link.RawQuery = query.Encode() @@ -272,7 +272,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 15 // from the fixtures + expectedIssueCount := 16 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index 6e80ebc19c2f2..29fff8ba72618 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -34,7 +34,7 @@ func TestNodeinfo(t *testing.T) { assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) assert.Equal(t, 24, nodeinfo.Usage.Users.Total) - assert.Equal(t, 17, nodeinfo.Usage.LocalPosts) + assert.Equal(t, 18, nodeinfo.Usage.LocalPosts) assert.Equal(t, 2, nodeinfo.Usage.LocalComments) }) } diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index c913a2000c892..eccf3c3795d9d 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -356,7 +356,7 @@ func TestSearchIssues(t *testing.T) { session := loginUser(t, "user2") - expectedIssueCount := 15 // from the fixtures + expectedIssueCount := 16 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -377,7 +377,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 8) + assert.Len(t, apiIssues, 9) query.Del("since") query.Del("before") @@ -393,15 +393,15 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count")) - assert.Len(t, apiIssues, 17) + assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) + assert.Len(t, apiIssues, 18) query.Add("limit", "5") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 5) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -430,7 +430,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 6) + assert.Len(t, apiIssues, 7) query = url.Values{"owner": {"user3"}} // organization link.RawQuery = query.Encode() @@ -450,7 +450,7 @@ func TestSearchIssues(t *testing.T) { func TestSearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() - expectedIssueCount := 15 // from the fixtures + expectedIssueCount := 16 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/web_src/js/components/ContextPopup.vue b/web_src/js/components/ContextPopup.vue index 07c73ff5cf152..3244034782d67 100644 --- a/web_src/js/components/ContextPopup.vue +++ b/web_src/js/components/ContextPopup.vue @@ -26,25 +26,10 @@
    -
    +
    {{range $i, $file := .Diff.Files}} {{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}} @@ -116,7 +116,7 @@ {{end}} {{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}} {{$.locale.Tr "repo.unescape_control_characters"}} - + {{$.locale.Tr "repo.escape_control_characters"}} {{end}} {{if and (not $file.IsSubmodule) (not $.PageIsWiki)}} {{if $file.IsDeleted}} @@ -136,7 +136,7 @@
  • -
    +
    {{if or $file.IsIncomplete $file.IsBin}}
    {{if $file.IsIncomplete}} @@ -187,7 +187,7 @@
    {{if not $.Repository.IsArchived}} -
    +
    -
    {{.Content}}
    -
    +
    {{.Content}}
    +
    {{$reactions := .Reactions.GroupByType}} {{if $reactions}} diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 16749bacbf063..c7538a7969638 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -88,7 +88,7 @@ {{end}} {{end}}
    -