|
9 | 9 | "net/url" |
10 | 10 |
|
11 | 11 | "code.gitea.io/gitea/modules/git" |
| 12 | + "code.gitea.io/gitea/modules/httplib" |
12 | 13 | "code.gitea.io/gitea/modules/repository" |
13 | 14 | "code.gitea.io/gitea/modules/setting" |
14 | 15 | ) |
@@ -81,26 +82,32 @@ type HookProcReceiveRefResult struct { |
81 | 82 | HeadBranch string |
82 | 83 | } |
83 | 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 ever 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 | + |
84 | 95 | // HookPreReceive check whether the provided commits are allowed |
85 | 96 | func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) ResponseExtra { |
86 | | - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName)) |
87 | | - req := newInternalRequestAPI(ctx, reqURL, "POST", opts) |
| 97 | + req := newInternalRequestAPIForHooks(ctx, "pre-receive", ownerName, repoName, opts) |
88 | 98 | _, extra := requestJSONResp(req, &ResponseText{}) |
89 | 99 | return extra |
90 | 100 | } |
91 | 101 |
|
92 | 102 | // HookPostReceive updates services and users |
93 | 103 | func HookPostReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookPostReceiveResult, ResponseExtra) { |
94 | | - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/post-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName)) |
95 | | - req := newInternalRequestAPI(ctx, reqURL, "POST", opts) |
| 104 | + req := newInternalRequestAPIForHooks(ctx, "post-receive", ownerName, repoName, opts) |
96 | 105 | return requestJSONResp(req, &HookPostReceiveResult{}) |
97 | 106 | } |
98 | 107 |
|
99 | 108 | // HookProcReceive proc-receive hook |
100 | 109 | func HookProcReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookProcReceiveResult, ResponseExtra) { |
101 | | - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/proc-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName)) |
102 | | - |
103 | | - req := newInternalRequestAPI(ctx, reqURL, "POST", opts) |
| 110 | + req := newInternalRequestAPIForHooks(ctx, "proc-receive", ownerName, repoName, opts) |
104 | 111 | return requestJSONResp(req, &HookProcReceiveResult{}) |
105 | 112 | } |
106 | 113 |
|
|
0 commit comments