|
7 | 7 | "context"
|
8 | 8 | "fmt"
|
9 | 9 | "net/url"
|
10 |
| - "time" |
11 | 10 |
|
12 | 11 | "code.gitea.io/gitea/modules/git"
|
| 12 | + "code.gitea.io/gitea/modules/httplib" |
13 | 13 | "code.gitea.io/gitea/modules/repository"
|
14 | 14 | "code.gitea.io/gitea/modules/setting"
|
15 | 15 | )
|
@@ -82,29 +82,32 @@ type HookProcReceiveRefResult struct {
|
82 | 82 | HeadBranch string
|
83 | 83 | }
|
84 | 84 |
|
| 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 | + |
85 | 95 | // HookPreReceive check whether the provided commits are allowed
|
86 | 96 | 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) |
90 | 98 | _, extra := requestJSONResp(req, &ResponseText{})
|
91 | 99 | return extra
|
92 | 100 | }
|
93 | 101 |
|
94 | 102 | // HookPostReceive updates services and users
|
95 | 103 | 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) |
99 | 105 | return requestJSONResp(req, &HookPostReceiveResult{})
|
100 | 106 | }
|
101 | 107 |
|
102 | 108 | // HookProcReceive proc-receive hook
|
103 | 109 | 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) |
108 | 111 | return requestJSONResp(req, &HookProcReceiveResult{})
|
109 | 112 | }
|
110 | 113 |
|
|
0 commit comments