Skip to content

Commit 1233039

Browse files
committed
fix: run pre-hook in repository folder
1 parent 1422dc5 commit 1233039

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/proxy/chain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const proc = require('./processors');
22

33
const pushActionChain = [
4-
proc.push.preReceive,
54
proc.push.parsePush,
5+
proc.push.preReceive,
66
proc.push.checkRepoInAuthorisedList,
77
proc.push.checkCommitMessages,
88
proc.push.checkAuthorEmails,

src/proxy/processors/push-action/preReceive.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const path = require('path');
33
const Step = require('../../actions').Step;
44
const { spawnSync } = require('child_process');
55

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`;
88
};
99

1010
const exec = async (req, action, hookFilePath = './hooks/pre-receive.sh') => {
@@ -17,33 +17,32 @@ const exec = async (req, action, hookFilePath = './hooks/pre-receive.sh') => {
1717
throw new Error(`Hook file not found: ${resolvedPath}`);
1818
}
1919

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}`);
2123

2224
const sanitizedInput = sanitizeInput(req, action);
2325

2426
const hookProcess = spawnSync(resolvedPath, [], {
25-
input: JSON.stringify(sanitizedInput),
27+
input: sanitizedInput,
2628
encoding: 'utf-8',
29+
cwd: repoPath,
2730
});
2831

2932
const { stdout, stderr, status } = hookProcess;
3033

3134
if (status !== 0) {
32-
console.error(`Pre-receive hook failed with exit code ${status}`);
3335
step.error = true;
3436
step.log(`Hook stderr: ${stderr.trim()}`);
3537
step.setError(stdout.trim());
3638
action.addStep(step);
3739
return action;
3840
}
3941

40-
console.log('Pre-receive hook executed successfully');
41-
console.log(`Hook stdout: ${stdout.trim()}`);
4242
step.log('Pre-receive hook executed successfully');
4343
action.addStep(step);
4444
return action;
4545
} catch (error) {
46-
console.error('Error during pre-receive hook execution:', error);
4746
step.error = true;
4847
step.setError(`Hook execution error: ${error.message}`);
4948
action.addStep(step);

0 commit comments

Comments
 (0)