@@ -3,8 +3,8 @@ const path = require('path');
3
3
const Step = require ( '../../actions' ) . Step ;
4
4
const { spawnSync } = require ( 'child_process' ) ;
5
5
6
- const sanitizeInput = ( req , action ) => {
7
- return `${ action . oldCommit } ${ action . newCommit } ${ action . ref } \n` ;
6
+ const sanitizeInput = ( _req , action ) => {
7
+ return `${ action . commitFrom } ${ action . commitTo } ${ action . branch } \n` ;
8
8
} ;
9
9
10
10
const exec = async ( req , action , hookFilePath = './hooks/pre-receive.sh' ) => {
@@ -17,33 +17,32 @@ const exec = async (req, action, hookFilePath = './hooks/pre-receive.sh') => {
17
17
throw new Error ( `Hook file not found: ${ resolvedPath } ` ) ;
18
18
}
19
19
20
- console . log ( `Executing pre-receive hook from: ${ resolvedPath } ` ) ;
20
+ const repoPath = `${ action . proxyGitPath } /${ action . repoName } ` ;
21
+
22
+ step . log ( `Executing pre-receive hook from: ${ resolvedPath } ` ) ;
21
23
22
24
const sanitizedInput = sanitizeInput ( req , action ) ;
23
25
24
26
const hookProcess = spawnSync ( resolvedPath , [ ] , {
25
- input : JSON . stringify ( sanitizedInput ) ,
27
+ input : sanitizedInput ,
26
28
encoding : 'utf-8' ,
29
+ cwd : repoPath ,
27
30
} ) ;
28
31
29
32
const { stdout, stderr, status } = hookProcess ;
30
33
31
34
if ( status !== 0 ) {
32
- console . error ( `Pre-receive hook failed with exit code ${ status } ` ) ;
33
35
step . error = true ;
34
36
step . log ( `Hook stderr: ${ stderr . trim ( ) } ` ) ;
35
37
step . setError ( stdout . trim ( ) ) ;
36
38
action . addStep ( step ) ;
37
39
return action ;
38
40
}
39
41
40
- console . log ( 'Pre-receive hook executed successfully' ) ;
41
- console . log ( `Hook stdout: ${ stdout . trim ( ) } ` ) ;
42
42
step . log ( 'Pre-receive hook executed successfully' ) ;
43
43
action . addStep ( step ) ;
44
44
return action ;
45
45
} catch ( error ) {
46
- console . error ( 'Error during pre-receive hook execution:' , error ) ;
47
46
step . error = true ;
48
47
step . setError ( `Hook execution error: ${ error . message } ` ) ;
49
48
action . addStep ( step ) ;
0 commit comments