@@ -9,6 +9,7 @@ const sanitizeInput = (_req, action) => {
9
9
10
10
const exec = async ( req , action , hookFilePath = './hooks/pre-receive.sh' ) => {
11
11
const step = new Step ( 'executeExternalPreReceiveHook' ) ;
12
+ let stderrTrimmed = '' ;
12
13
13
14
try {
14
15
const resolvedPath = path . resolve ( hookFilePath ) ;
@@ -34,37 +35,33 @@ const exec = async (req, action, hookFilePath = './hooks/pre-receive.sh') => {
34
35
35
36
const { stdout, stderr, status } = hookProcess ;
36
37
37
- const stderrTrimmed = stderr ? stderr . trim ( ) : '' ;
38
+ stderrTrimmed = stderr ? stderr . trim ( ) : '' ;
38
39
const stdoutTrimmed = stdout ? stdout . trim ( ) : '' ;
39
40
40
41
step . log ( `Hook exited with status ${ status } ` ) ;
41
42
42
- if ( status === 1 ) {
43
- step . log ( 'Push requires manual approval .' ) ;
43
+ if ( status === 0 ) {
44
+ step . log ( 'Push automatically approved by pre-receive hook .' ) ;
44
45
action . addStep ( step ) ;
45
- return action ;
46
- } else if ( status === 2 ) {
47
- step . error = true ;
48
- step . log ( 'Push rejected by pre-receive hook.' ) ;
49
- step . log ( `Hook stderr: ${ stderrTrimmed } ` ) ;
50
- step . setError ( stdoutTrimmed || 'Pre-receive hook rejected the push.' ) ;
46
+ action . setAutoApproval ( ) ;
47
+ } else if ( status === 1 ) {
48
+ step . log ( 'Push automatically rejected by pre-receive hook.' ) ;
51
49
action . addStep ( step ) ;
52
- return action ;
53
- } else if ( status === 0 ) {
54
- step . log ( 'Push automatically approved by pre-receive hook .' ) ;
50
+ action . setAutoRejection ( ) ;
51
+ } else if ( status === 2 ) {
52
+ step . log ( 'Push requires manual approval .' ) ;
55
53
action . addStep ( step ) ;
56
- action . setAllowAutoApprover ( ) ;
57
- return action ;
58
54
} else {
59
55
step . error = true ;
60
56
step . log ( `Unexpected hook status: ${ status } ` ) ;
61
57
step . setError ( stdoutTrimmed || 'Unknown pre-receive hook error.' ) ;
62
58
action . addStep ( step ) ;
63
- return action ;
64
59
}
60
+ return action ;
65
61
} catch ( error ) {
66
62
step . error = true ;
67
- step . setError ( `Hook execution error: ${ error . message } ` ) ;
63
+ step . log ( 'Push failed, pre-receive hook returned an error.' ) ;
64
+ step . setError ( `Hook execution error: ${ stderrTrimmed || error . message } ` ) ;
68
65
action . addStep ( step ) ;
69
66
return action ;
70
67
}
0 commit comments