From 279473f467f6af558293c2147a08241f8b934eea Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Mar 2025 20:50:39 +0800 Subject: [PATCH 1/4] Fix oauth2 auth and UI (#33961) --- routers/web/auth/oauth2_provider.go | 2 +- templates/user/auth/grant.tmpl | 60 ++++++++++++++-------------- templates/user/auth/grant_error.tmpl | 19 ++++----- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/routers/web/auth/oauth2_provider.go b/routers/web/auth/oauth2_provider.go index 00b5b2db52..ff571fbf2c 100644 --- a/routers/web/auth/oauth2_provider.go +++ b/routers/web/auth/oauth2_provider.go @@ -249,7 +249,7 @@ func AuthorizeOAuth(ctx *context.Context) { }, form.RedirectURI) return } - if err := ctx.Session.Set("CodeChallengeMethod", form.CodeChallenge); err != nil { + if err := ctx.Session.Set("CodeChallenge", form.CodeChallenge); err != nil { handleAuthorizeError(ctx, AuthorizeError{ ErrorCode: ErrorCodeServerError, ErrorDescription: "cannot set code challenge", diff --git a/templates/user/auth/grant.tmpl b/templates/user/auth/grant.tmpl index 7a6f156e36..e56241b0f8 100644 --- a/templates/user/auth/grant.tmpl +++ b/templates/user/auth/grant.tmpl @@ -1,35 +1,33 @@ {{template "base/head" .}} -
-
-
-

- {{ctx.Locale.Tr "auth.authorize_title" .Application.Name}} -

-
- {{template "base/alert" .}} -

- {{if not .AdditionalScopes}} - {{ctx.Locale.Tr "auth.authorize_application_description"}}
- {{end}} - {{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}
- {{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "%s" .Scope)}} -

-
-
-

{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}

-
-
-
- {{.CsrfTokenHtml}} - - - - - - - -
-
+
+
+

+ {{ctx.Locale.Tr "auth.authorize_title" .Application.Name}} +

+
+ {{template "base/alert" .}} +

+ {{if not .AdditionalScopes}} + {{ctx.Locale.Tr "auth.authorize_application_description"}}
+ {{end}} + {{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}
+ {{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "%s" .Scope)}} +

+
+
+

{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}

+
+
+
+ {{.CsrfTokenHtml}} + + + + + + + +
diff --git a/templates/user/auth/grant_error.tmpl b/templates/user/auth/grant_error.tmpl index e37c4f6544..7a4521d331 100644 --- a/templates/user/auth/grant_error.tmpl +++ b/templates/user/auth/grant_error.tmpl @@ -1,15 +1,12 @@ {{template "base/head" .}} -
- {{if .IsRepo}}{{template "repo/header" .}}{{end}} -
-
-

- {{ctx.Locale.Tr "auth.authorization_failed"}} -

-

{{.Error.ErrorDescription}}

-
-

{{ctx.Locale.Tr "auth.authorization_failed_desc"}}

-
+
+
+

+ {{ctx.Locale.Tr "auth.authorization_failed"}} +

+

{{.Error.ErrorDescription}}

+
+

{{ctx.Locale.Tr "auth.authorization_failed_desc"}}

From b956cee06f462c4f34a7911351b7c878ce890725 Mon Sep 17 00:00:00 2001 From: charles <30816317+charles7668@users.noreply.github.com> Date: Sat, 22 Mar 2025 03:00:02 +0800 Subject: [PATCH 2/4] Fix file name could not be searched if the file was not a text file when using the Bleve indexer (#33959) Close #33828 --------- Co-authored-by: wxiaoguang --- modules/indexer/code/bleve/bleve.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go index e1a381f992..130ee78a4b 100644 --- a/modules/indexer/code/bleve/bleve.go +++ b/modules/indexer/code/bleve/bleve.go @@ -191,7 +191,8 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro return err } else if !typesniffer.DetectContentType(fileContents).IsText() { // FIXME: UTF-16 files will probably fail here - return nil + // Even if the file is not recognized as a "text file", we could still put its name into the indexers to make the filename become searchable, while leave the content to empty. + fileContents = nil } if _, err = batchReader.Discard(1); err != nil { From b5d2e31d6d7d96e1884f1aaed43ca7b74cc591db Mon Sep 17 00:00:00 2001 From: Kai Leonhardt <8343141+Mik4sa@users.noreply.github.com> Date: Fri, 21 Mar 2025 20:52:14 +0100 Subject: [PATCH 3/4] Drop timeout for requests made to the internal hook api (#33947) This change targets https://github.com/go-gitea/gitea/issues/32663 We drop the hardcoded timeout of 60 seconds for requests to the internal hook api. With this change the timeout is completly removed. --------- Co-authored-by: wxiaoguang --- modules/private/hook.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/private/hook.go b/modules/private/hook.go index 87d6549f9c..215996b9b9 100644 --- a/modules/private/hook.go +++ b/modules/private/hook.go @@ -7,9 +7,9 @@ import ( "context" "fmt" "net/url" - "time" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" ) @@ -82,29 +82,32 @@ type HookProcReceiveRefResult struct { HeadBranch string } +func newInternalRequestAPIForHooks(ctx context.Context, hookName, ownerName, repoName string, opts HookOptions) *httplib.Request { + reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/%s/%s/%s", hookName, url.PathEscape(ownerName), url.PathEscape(repoName)) + req := newInternalRequestAPI(ctx, reqURL, "POST", opts) + // This "timeout" applies to http.Client's timeout: A Timeout of zero means no timeout. + // This "timeout" was previously set to `time.Duration(60+len(opts.OldCommitIDs))` seconds, but it caused unnecessary timeout failures. + // It should be good enough to remove the client side timeout, only respect the "ctx" and server side timeout. + req.SetReadWriteTimeout(0) + return req +} + // HookPreReceive check whether the provided commits are allowed func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) ResponseExtra { - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName)) - req := newInternalRequestAPI(ctx, reqURL, "POST", opts) - req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second) + req := newInternalRequestAPIForHooks(ctx, "pre-receive", ownerName, repoName, opts) _, extra := requestJSONResp(req, &ResponseText{}) return extra } // HookPostReceive updates services and users func HookPostReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookPostReceiveResult, ResponseExtra) { - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/post-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName)) - req := newInternalRequestAPI(ctx, reqURL, "POST", opts) - req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second) + req := newInternalRequestAPIForHooks(ctx, "post-receive", ownerName, repoName, opts) return requestJSONResp(req, &HookPostReceiveResult{}) } // HookProcReceive proc-receive hook func HookProcReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookProcReceiveResult, ResponseExtra) { - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/proc-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName)) - - req := newInternalRequestAPI(ctx, reqURL, "POST", opts) - req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second) + req := newInternalRequestAPIForHooks(ctx, "proc-receive", ownerName, repoName, opts) return requestJSONResp(req, &HookProcReceiveResult{}) } From d1a755e5b7c676750f3dfad2254e047e2d23c4ac Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 21 Mar 2025 21:48:06 +0100 Subject: [PATCH 4/4] Cover `go.mod` and `go.sum` in `.editorconfig` (#33960) These files were previously set to use spaces for indendation but they are supposed to use tabs, so set this in editorconfig. --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index e23e4cd649..13aa8d50f0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,6 +12,9 @@ insert_final_newline = true [*.{go,tmpl,html}] indent_style = tab +[go.*] +indent_style = tab + [templates/custom/*.tmpl] insert_final_newline = false