Skip to content

Commit f723307

Browse files
committed
refactor: move attempt functions into autoAction.js
1 parent 6b6653e commit f723307

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

src/proxy/actions/autoActions.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const db = require('../../db');
2+
3+
const attemptAutoApproval = async (action) => {
4+
try {
5+
const attestation = {
6+
timestamp: new Date(),
7+
autoApproved: true,
8+
};
9+
await db.authorise(action.id, attestation);
10+
console.log('Push automatically approved by system.');
11+
12+
return true;
13+
} catch (error) {
14+
console.error('Error during auto-approval:', error.message);
15+
return false;
16+
}
17+
};
18+
19+
const attemptAutoRejection = async (action) => {
20+
try {
21+
const attestation = {
22+
timestamp: new Date(),
23+
autoApproved: true,
24+
};
25+
await db.reject(action.id, attestation);
26+
console.log('Push automatically rejected by system.');
27+
28+
return true;
29+
} catch (error) {
30+
console.error('Error during auto-rejection:', error.message);
31+
return false;
32+
}
33+
};
34+
35+
module.exports = {
36+
attemptAutoApproval,
37+
attemptAutoRejection,
38+
};

src/proxy/chain.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const proc = require('./processors');
2-
const db = require('../db');
2+
const { attemptAutoApproval, attemptAutoRejection } = require('./actions/autoActions');
33

44
const pushActionChain = [
55
proc.push.parsePush,
@@ -21,22 +21,6 @@ const pullActionChain = [proc.push.checkRepoInAuthorisedList];
2121

2222
let pluginsInserted = false;
2323

24-
const attemptAutoApproval = async (req, action) => {
25-
try {
26-
const attestation = {
27-
timestamp: new Date(),
28-
autoApproved: true,
29-
};
30-
await db.authorise(action.id, attestation);
31-
console.log('Push automatically approved by system.');
32-
33-
return true;
34-
} catch (error) {
35-
console.error('Error during auto-approval:', error.message);
36-
return false;
37-
}
38-
};
39-
4024
const executeChain = async (req) => {
4125
let action;
4226
try {
@@ -58,7 +42,9 @@ const executeChain = async (req) => {
5842
} finally {
5943
await proc.push.audit(req, action);
6044
if (action.autoApproved) {
61-
attemptAutoApproval(req, action);
45+
attemptAutoApproval(action);
46+
} else if (action.autoRejected) {
47+
attemptAutoRejection(action);
6248
}
6349
}
6450

0 commit comments

Comments
 (0)