Skip to content

Commit cedeff6

Browse files
committed
feat: handle different exit codes in pre receive
1 parent 9ae58e8 commit cedeff6

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,31 @@ const exec = async (req, action, hookFilePath = './hooks/pre-receive.sh') => {
3737
const stderrTrimmed = stderr ? stderr.trim() : '';
3838
const stdoutTrimmed = stdout ? stdout.trim() : '';
3939

40-
if (status !== 0) {
40+
step.log(`Hook exited with status ${status}`);
41+
42+
if (status === 1) {
43+
step.log('Push requires manual approval.');
44+
action.addStep(step);
45+
return action;
46+
} else if (status === 2) {
4147
step.error = true;
48+
step.log('Push rejected by pre-receive hook.');
4249
step.log(`Hook stderr: ${stderrTrimmed}`);
43-
step.setError(stdoutTrimmed);
50+
step.setError(stdoutTrimmed || 'Pre-receive hook rejected the push.');
51+
action.addStep(step);
52+
return action;
53+
} else if (status === 0) {
54+
step.log('Push automatically approved by pre-receive hook.');
55+
action.addStep(step);
56+
action.setAllowAutoApprover();
57+
return action;
58+
} else {
59+
step.error = true;
60+
step.log(`Unexpected hook status: ${status}`);
61+
step.setError(stdoutTrimmed || 'Unknown pre-receive hook error.');
4462
action.addStep(step);
4563
return action;
4664
}
47-
48-
step.log('Pre-receive hook executed successfully');
49-
action.addStep(step);
50-
return action;
5165
} catch (error) {
5266
step.error = true;
5367
step.setError(`Hook execution error: ${error.message}`);

0 commit comments

Comments
 (0)