Skip to content

Commit e028624

Browse files
committed
feat: add auto rejection
1 parent c104121 commit e028624

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/proxy/actions/Action.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Action {
1515
canceled = false;
1616
rejected = false;
1717
autoApproved = false;
18+
autoRejected = false;
1819
commitFrom;
1920
commitTo;
2021
branch;
@@ -108,10 +109,16 @@ class Action {
108109
/**
109110
*`
110111
*/
111-
setAllowAutoApprover() {
112+
setAutoApproval() {
112113
this.autoApproved = true;
113114
}
114115

116+
/**
117+
*`
118+
*/
119+
setAutoRejection() {
120+
this.autoRejected = true;
121+
}
115122
/**
116123
* @return {bool}
117124
*/

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const sanitizeInput = (_req, action) => {
99

1010
const exec = async (req, action, hookFilePath = './hooks/pre-receive.sh') => {
1111
const step = new Step('executeExternalPreReceiveHook');
12+
let stderrTrimmed = '';
1213

1314
try {
1415
const resolvedPath = path.resolve(hookFilePath);
@@ -34,37 +35,33 @@ const exec = async (req, action, hookFilePath = './hooks/pre-receive.sh') => {
3435

3536
const { stdout, stderr, status } = hookProcess;
3637

37-
const stderrTrimmed = stderr ? stderr.trim() : '';
38+
stderrTrimmed = stderr ? stderr.trim() : '';
3839
const stdoutTrimmed = stdout ? stdout.trim() : '';
3940

4041
step.log(`Hook exited with status ${status}`);
4142

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.');
4445
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.');
5149
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.');
5553
action.addStep(step);
56-
action.setAllowAutoApprover();
57-
return action;
5854
} else {
5955
step.error = true;
6056
step.log(`Unexpected hook status: ${status}`);
6157
step.setError(stdoutTrimmed || 'Unknown pre-receive hook error.');
6258
action.addStep(step);
63-
return action;
6459
}
60+
return action;
6561
} catch (error) {
6662
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}`);
6865
action.addStep(step);
6966
return action;
7067
}

0 commit comments

Comments
 (0)