@@ -86,7 +86,10 @@ type HookProcReceiveRefResult struct {
8686func 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 ()
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
9598func 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 ()
103+ req .SetReadWriteTimeout (timeout )
104+
99105 return requestJSONResp (req , & HookPostReceiveResult {})
100106}
101107
102108// HookProcReceive proc-receive hook
103109func 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 ()
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 () time.Duration {
141+ return time .Duration (setting .Git .Timeout .Default ) * time .Second
142+ }
0 commit comments