0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-20 14:48:30 +02:00

Merge branch 'main' of https://github.com/go-gitea/gitea into workflow-webhook-api

This commit is contained in:
Christopher Homberger 2025-03-21 22:14:24 +01:00
commit 500a9bf852
6 changed files with 57 additions and 55 deletions

View File

@ -12,6 +12,9 @@ insert_final_newline = true
[*.{go,tmpl,html}] [*.{go,tmpl,html}]
indent_style = tab indent_style = tab
[go.*]
indent_style = tab
[templates/custom/*.tmpl] [templates/custom/*.tmpl]
insert_final_newline = false insert_final_newline = false

View File

@ -191,7 +191,8 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
return err return err
} else if !typesniffer.DetectContentType(fileContents).IsText() { } else if !typesniffer.DetectContentType(fileContents).IsText() {
// FIXME: UTF-16 files will probably fail here // 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 { if _, err = batchReader.Discard(1); err != nil {

View File

@ -7,9 +7,9 @@ import (
"context" "context"
"fmt" "fmt"
"net/url" "net/url"
"time"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
) )
@ -82,29 +82,32 @@ type HookProcReceiveRefResult struct {
HeadBranch string 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 // HookPreReceive check whether the provided commits are allowed
func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) ResponseExtra { 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 := newInternalRequestAPIForHooks(ctx, "pre-receive", ownerName, repoName, opts)
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
_, extra := requestJSONResp(req, &ResponseText{}) _, extra := requestJSONResp(req, &ResponseText{})
return extra return extra
} }
// HookPostReceive updates services and users // HookPostReceive updates services and users
func HookPostReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookPostReceiveResult, ResponseExtra) { 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 := newInternalRequestAPIForHooks(ctx, "post-receive", ownerName, repoName, opts)
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
return requestJSONResp(req, &HookPostReceiveResult{}) return requestJSONResp(req, &HookPostReceiveResult{})
} }
// HookProcReceive proc-receive hook // HookProcReceive proc-receive hook
func HookProcReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookProcReceiveResult, ResponseExtra) { 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 := newInternalRequestAPIForHooks(ctx, "proc-receive", ownerName, repoName, opts)
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
return requestJSONResp(req, &HookProcReceiveResult{}) return requestJSONResp(req, &HookProcReceiveResult{})
} }

View File

@ -249,7 +249,7 @@ func AuthorizeOAuth(ctx *context.Context) {
}, form.RedirectURI) }, form.RedirectURI)
return return
} }
if err := ctx.Session.Set("CodeChallengeMethod", form.CodeChallenge); err != nil { if err := ctx.Session.Set("CodeChallenge", form.CodeChallenge); err != nil {
handleAuthorizeError(ctx, AuthorizeError{ handleAuthorizeError(ctx, AuthorizeError{
ErrorCode: ErrorCodeServerError, ErrorCode: ErrorCodeServerError,
ErrorDescription: "cannot set code challenge", ErrorDescription: "cannot set code challenge",

View File

@ -1,35 +1,33 @@
{{template "base/head" .}} {{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content ui one column stackable tw-text-center page grid oauth2-authorize-application-box"> <div role="main" aria-label="{{.Title}}" class="page-content oauth2-authorize-application-box">
<div class="column seven wide"> <div class="ui container tw-max-w-[500px]">
<div class="ui middle centered raised segments"> <h3 class="ui top attached header">
<h3 class="ui top attached header"> {{ctx.Locale.Tr "auth.authorize_title" .Application.Name}}
{{ctx.Locale.Tr "auth.authorize_title" .Application.Name}} </h3>
</h3> <div class="ui attached segment">
<div class="ui attached segment"> {{template "base/alert" .}}
{{template "base/alert" .}} <p>
<p> {{if not .AdditionalScopes}}
{{if not .AdditionalScopes}} <b>{{ctx.Locale.Tr "auth.authorize_application_description"}}</b><br>
<b>{{ctx.Locale.Tr "auth.authorize_application_description"}}</b><br> {{end}}
{{end}} {{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}<br>
{{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}<br> {{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "<b>%s</b>" .Scope)}}
{{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "<b>%s</b>" .Scope)}} </p>
</p> </div>
</div> <div class="ui attached segment">
<div class="ui attached segment"> <p>{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}</p>
<p>{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}</p> </div>
</div> <div class="ui attached segment tw-text-center">
<div class="ui attached segment"> <form method="post" action="{{AppSubUrl}}/login/oauth/grant">
<form method="post" action="{{AppSubUrl}}/login/oauth/grant"> {{.CsrfTokenHtml}}
{{.CsrfTokenHtml}} <input type="hidden" name="client_id" value="{{.Application.ClientID}}">
<input type="hidden" name="client_id" value="{{.Application.ClientID}}"> <input type="hidden" name="state" value="{{.State}}">
<input type="hidden" name="state" value="{{.State}}"> <input type="hidden" name="scope" value="{{.Scope}}">
<input type="hidden" name="scope" value="{{.Scope}}"> <input type="hidden" name="nonce" value="{{.Nonce}}">
<input type="hidden" name="nonce" value="{{.Nonce}}"> <input type="hidden" name="redirect_uri" value="{{.RedirectURI}}">
<input type="hidden" name="redirect_uri" value="{{.RedirectURI}}"> <button type="submit" id="authorize-app" name="granted" value="true" class="ui red inline button">{{ctx.Locale.Tr "auth.authorize_application"}}</button>
<button type="submit" id="authorize-app" name="granted" value="true" class="ui red inline button">{{ctx.Locale.Tr "auth.authorize_application"}}</button> <button type="submit" name="granted" value="false" class="ui basic primary inline button">{{ctx.Locale.Tr "cancel"}}</button>
<button type="submit" name="granted" value="false" class="ui basic primary inline button">{{ctx.Locale.Tr "cancel"}}</button> </form>
</form>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,15 +1,12 @@
{{template "base/head" .}} {{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content ui one column stackable tw-text-center page grid oauth2-authorize-application-box {{if .IsRepo}}repository{{end}}"> <div role="main" aria-label="{{.Title}}" class="page-content oauth2-authorize-application-box">
{{if .IsRepo}}{{template "repo/header" .}}{{end}} <div class="ui container tw-max-w-[500px]">
<div class="column seven wide"> <h1 class="ui top attached header">
<div class="ui middle centered raised segments"> {{ctx.Locale.Tr "auth.authorization_failed"}}
<h1 class="ui top attached header"> </h1>
{{ctx.Locale.Tr "auth.authorization_failed"}} <h3 class="ui attached segment">{{.Error.ErrorDescription}}</h3>
</h1> <div class="ui attached segment">
<h3 class="ui attached segment">{{.Error.ErrorDescription}}</h3> <p>{{ctx.Locale.Tr "auth.authorization_failed_desc"}}</p>
<div class="ui attached segment">
<p>{{ctx.Locale.Tr "auth.authorization_failed_desc"}}</p>
</div>
</div> </div>
</div> </div>
</div> </div>