Skip to content

Commit 8cc6812

Browse files
committed
Use git.timeout/DEFAULT for requests made to the internal hook api
1 parent 5407382 commit 8cc6812

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

modules/private/hook.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ type HookProcReceiveRefResult struct {
8686
func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) ResponseExtra {
8787
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
8888
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
89-
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
89+
90+
timeout := getHookRequestTimeout(opts)
91+
req.SetReadWriteTimeout(timeout)
92+
9093
_, extra := requestJSONResp(req, &ResponseText{})
9194
return extra
9295
}
@@ -95,16 +98,21 @@ func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOp
9598
func HookPostReceive(ctx context.Context, ownerName, repoName string, opts HookOptions) (*HookPostReceiveResult, ResponseExtra) {
9699
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/post-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
97100
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
98-
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
101+
102+
timeout := getHookRequestTimeout(opts)
103+
req.SetReadWriteTimeout(timeout)
104+
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) {
104110
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/proc-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName))
105-
106111
req := newInternalRequestAPI(ctx, reqURL, "POST", opts)
107-
req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second)
112+
113+
timeout := getHookRequestTimeout(opts)
114+
req.SetReadWriteTimeout(timeout)
115+
108116
return requestJSONResp(req, &HookProcReceiveResult{})
109117
}
110118

@@ -127,3 +135,8 @@ func SSHLog(ctx context.Context, isErr bool, msg string) error {
127135
_, extra := requestJSONResp(req, &ResponseText{})
128136
return extra.Error
129137
}
138+
139+
// Gets the timeout (seconds) for the requests made to the internal hook api
140+
func getHookRequestTimeout(opts HookOptions) time.Duration {
141+
return time.Duration(setting.Git.Timeout.Default) * time.Second
142+
}

0 commit comments

Comments
 (0)