Skip to content

Commit 500a9bf

Browse files
committed
Merge branch 'main' of https://github.com/go-gitea/gitea into workflow-webhook-api
2 parents 9b3eb4c + d1a755e commit 500a9bf

File tree

6 files changed

+57
-55
lines changed

6 files changed

+57
-55
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ insert_final_newline = true
1212
[*.{go,tmpl,html}]
1313
indent_style = tab
1414

15+
[go.*]
16+
indent_style = tab
17+
1518
[templates/custom/*.tmpl]
1619
insert_final_newline = false
1720

modules/indexer/code/bleve/bleve.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
191191
return err
192192
} else if !typesniffer.DetectContentType(fileContents).IsText() {
193193
// FIXME: UTF-16 files will probably fail here
194-
return nil
194+
// 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.
195+
fileContents = nil
195196
}
196197

197198
if _, err = batchReader.Discard(1); err != nil {

modules/private/hook.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"context"
88
"fmt"
99
"net/url"
10-
"time"
1110

1211
"code.gitea.io/gitea/modules/git"
12+
"code.gitea.io/gitea/modules/httplib"
1313
"code.gitea.io/gitea/modules/repository"
1414
"code.gitea.io/gitea/modules/setting"
1515
)
@@ -82,29 +82,32 @@ type HookProcReceiveRefResult struct {
8282
HeadBranch string
8383
}
8484

85+
func newInternalRequestAPIForHooks(ctx context.Context, hookName, ownerName, repoName string, opts HookOptions) *httplib.Request {
86+
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/%s/%s/%s", hookName, url.PathEscape(ownerName), url.PathEscape(repoName))
87+
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
88+
// This "timeout" applies to http.Client's timeout: A Timeout of zero means no timeout.
89+
// This "timeout" was previously set to `time.Duration(60+len(opts.OldCommitIDs))` seconds, but it caused unnecessary timeout failures.
90+
// It should be good enough to remove the client side timeout, only respect the "ctx" and server side timeout.
91+
req.SetReadWriteTimeout(0)
92+
return req
93+
}
94+
8595
// HookPreReceive check whether the provided commits are allowed
8696
func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) ResponseExtra {
87-
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
88-
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
89-
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
97+
req := newInternalRequestAPIForHooks(ctx, "pre-receive", ownerName, repoName, opts)
9098
_, extra := requestJSONResp(req, &ResponseText{})
9199
return extra
92100
}
93101

94102
// HookPostReceive updates services and users
95103
func HookPostReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookPostReceiveResult, ResponseExtra) {
96-
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/post-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
97-
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
98-
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
104+
req := newInternalRequestAPIForHooks(ctx, "post-receive", ownerName, repoName, opts)
99105
return requestJSONResp(req, &HookPostReceiveResult{})
100106
}
101107

102108
// HookProcReceive proc-receive hook
103109
func HookProcReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookProcReceiveResult, ResponseExtra) {
104-
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/proc-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
105-
106-
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
107-
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
110+
req := newInternalRequestAPIForHooks(ctx, "proc-receive", ownerName, repoName, opts)
108111
return requestJSONResp(req, &HookProcReceiveResult{})
109112
}
110113

routers/web/auth/oauth2_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func AuthorizeOAuth(ctx *context.Context) {
249249
}, form.RedirectURI)
250250
return
251251
}
252-
if err := ctx.Session.Set("CodeChallengeMethod", form.CodeChallenge); err != nil {
252+
if err := ctx.Session.Set("CodeChallenge", form.CodeChallenge); err != nil {
253253
handleAuthorizeError(ctx, AuthorizeError{
254254
ErrorCode: ErrorCodeServerError,
255255
ErrorDescription: "cannot set code challenge",

templates/user/auth/grant.tmpl

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
{{template "base/head" .}}
2-
<div role="main" aria-label="{{.Title}}" class="page-content ui one column stackable tw-text-center page grid oauth2-authorize-application-box">
3-
<div class="column seven wide">
4-
<div class="ui middle centered raised segments">
5-
<h3 class="ui top attached header">
6-
{{ctx.Locale.Tr "auth.authorize_title" .Application.Name}}
7-
</h3>
8-
<div class="ui attached segment">
9-
{{template "base/alert" .}}
10-
<p>
11-
{{if not .AdditionalScopes}}
12-
<b>{{ctx.Locale.Tr "auth.authorize_application_description"}}</b><br>
13-
{{end}}
14-
{{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}<br>
15-
{{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "<b>%s</b>" .Scope)}}
16-
</p>
17-
</div>
18-
<div class="ui attached segment">
19-
<p>{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}</p>
20-
</div>
21-
<div class="ui attached segment">
22-
<form method="post" action="{{AppSubUrl}}/login/oauth/grant">
23-
{{.CsrfTokenHtml}}
24-
<input type="hidden" name="client_id" value="{{.Application.ClientID}}">
25-
<input type="hidden" name="state" value="{{.State}}">
26-
<input type="hidden" name="scope" value="{{.Scope}}">
27-
<input type="hidden" name="nonce" value="{{.Nonce}}">
28-
<input type="hidden" name="redirect_uri" value="{{.RedirectURI}}">
29-
<button type="submit" id="authorize-app" name="granted" value="true" class="ui red inline button">{{ctx.Locale.Tr "auth.authorize_application"}}</button>
30-
<button type="submit" name="granted" value="false" class="ui basic primary inline button">{{ctx.Locale.Tr "cancel"}}</button>
31-
</form>
32-
</div>
2+
<div role="main" aria-label="{{.Title}}" class="page-content oauth2-authorize-application-box">
3+
<div class="ui container tw-max-w-[500px]">
4+
<h3 class="ui top attached header">
5+
{{ctx.Locale.Tr "auth.authorize_title" .Application.Name}}
6+
</h3>
7+
<div class="ui attached segment">
8+
{{template "base/alert" .}}
9+
<p>
10+
{{if not .AdditionalScopes}}
11+
<b>{{ctx.Locale.Tr "auth.authorize_application_description"}}</b><br>
12+
{{end}}
13+
{{ctx.Locale.Tr "auth.authorize_application_created_by" .ApplicationCreatorLinkHTML}}<br>
14+
{{ctx.Locale.Tr "auth.authorize_application_with_scopes" (HTMLFormat "<b>%s</b>" .Scope)}}
15+
</p>
16+
</div>
17+
<div class="ui attached segment">
18+
<p>{{ctx.Locale.Tr "auth.authorize_redirect_notice" .ApplicationRedirectDomainHTML}}</p>
19+
</div>
20+
<div class="ui attached segment tw-text-center">
21+
<form method="post" action="{{AppSubUrl}}/login/oauth/grant">
22+
{{.CsrfTokenHtml}}
23+
<input type="hidden" name="client_id" value="{{.Application.ClientID}}">
24+
<input type="hidden" name="state" value="{{.State}}">
25+
<input type="hidden" name="scope" value="{{.Scope}}">
26+
<input type="hidden" name="nonce" value="{{.Nonce}}">
27+
<input type="hidden" name="redirect_uri" value="{{.RedirectURI}}">
28+
<button type="submit" id="authorize-app" name="granted" value="true" class="ui red inline button">{{ctx.Locale.Tr "auth.authorize_application"}}</button>
29+
<button type="submit" name="granted" value="false" class="ui basic primary inline button">{{ctx.Locale.Tr "cancel"}}</button>
30+
</form>
3331
</div>
3432
</div>
3533
</div>

templates/user/auth/grant_error.tmpl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{{template "base/head" .}}
2-
<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}}">
3-
{{if .IsRepo}}{{template "repo/header" .}}{{end}}
4-
<div class="column seven wide">
5-
<div class="ui middle centered raised segments">
6-
<h1 class="ui top attached header">
7-
{{ctx.Locale.Tr "auth.authorization_failed"}}
8-
</h1>
9-
<h3 class="ui attached segment">{{.Error.ErrorDescription}}</h3>
10-
<div class="ui attached segment">
11-
<p>{{ctx.Locale.Tr "auth.authorization_failed_desc"}}</p>
12-
</div>
2+
<div role="main" aria-label="{{.Title}}" class="page-content oauth2-authorize-application-box">
3+
<div class="ui container tw-max-w-[500px]">
4+
<h1 class="ui top attached header">
5+
{{ctx.Locale.Tr "auth.authorization_failed"}}
6+
</h1>
7+
<h3 class="ui attached segment">{{.Error.ErrorDescription}}</h3>
8+
<div class="ui attached segment">
9+
<p>{{ctx.Locale.Tr "auth.authorization_failed_desc"}}</p>
1310
</div>
1411
</div>
1512
</div>

0 commit comments

Comments
 (0)