@@ -86,7 +86,10 @@ type HookProcReceiveRefResult struct {
86
86
func HookPreReceive (ctx context.Context , ownerName , repoName string , opts HookOptions ) ResponseExtra {
87
87
reqURL := setting .LocalURL + fmt .Sprintf ("api/internal/hook/pre-receive/%s/%s" , url .PathEscape (ownerName ), url .PathEscape (repoName ))
88
88
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
+
90
93
_ , extra := requestJSONResp (req , & ResponseText {})
91
94
return extra
92
95
}
@@ -95,16 +98,21 @@ func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOp
95
98
func HookPostReceive (ctx context.Context , ownerName , repoName string , opts HookOptions ) (* HookPostReceiveResult , ResponseExtra ) {
96
99
reqURL := setting .LocalURL + fmt .Sprintf ("api/internal/hook/post-receive/%s/%s" , url .PathEscape (ownerName ), url .PathEscape (repoName ))
97
100
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
+
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
110
reqURL := setting .LocalURL + fmt .Sprintf ("api/internal/hook/proc-receive/%s/%s" , url .PathEscape (ownerName ), url .PathEscape (repoName ))
105
-
106
111
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
+
108
116
return requestJSONResp (req , & HookProcReceiveResult {})
109
117
}
110
118
@@ -127,3 +135,8 @@ func SSHLog(ctx context.Context, isErr bool, msg string) error {
127
135
_ , extra := requestJSONResp (req , & ResponseText {})
128
136
return extra .Error
129
137
}
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