Skip to content

Commit 3ecd5fb

Browse files
committed
refactor: getMissingData control flow
1 parent 6b21c1c commit 3ecd5fb

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

src/proxy/processors/push-action/checkUserPushPermission.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ const exec = async (req: any, action: Action): Promise<Action> => {
77
const user = action.user;
88

99
if (!user) {
10-
step.log('Action has no user set. This may be due to a fast-forward ref update. Deferring to getMissingData action.');
11-
action.addStep(step);
10+
console.log('Action has no user set. This may be due to a fast-forward ref update. Deferring to getMissingData action.');
1211
return action;
1312
}
1413

src/proxy/processors/push-action/getMissingData.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,40 @@ import { EMPTY_COMMIT_HASH } from '../constants';
77
const exec = async (req: any, action: Action): Promise<Action> => {
88
const step = new Step('getMissingData');
99

10-
try {
11-
if (!action.commitData) {
12-
action.commitData = [];
13-
}
10+
if (action.commitData && action.commitData.length > 0) {
11+
console.log('getMissingData', action);
12+
return action;
13+
}
1414

15-
if (action.commitData.length === 0) {
16-
console.log(`commitData not found, fetching missing commits from git...`);
17-
const path = `${action.proxyGitPath}/${action.repoName}`;
18-
const git = simpleGit(path);
19-
const log = await git.log({ from: action.commitFrom, to: action.commitTo });
20-
21-
action.commitData = log.all.toReversed().map((entry, i, array) => {
22-
const parent = i === 0 ? action.commitFrom : array[i - 1].hash;
23-
const timestamp = Math.floor(new Date(entry.date).getTime() / 1000).toString();
24-
return {
25-
message: entry.message || '',
26-
committer: entry.author_name || '',
27-
tree: entry.hash || '',
28-
parent: parent || '0'.repeat(40),
29-
author: entry.author_name || '',
30-
authorEmail: entry.author_email || '',
31-
commitTimestamp: timestamp,
32-
}
33-
});
34-
console.log(`Updated commitData:`, { commitData: action.commitData });
15+
console.log(`commitData not found, fetching missing commits from git...`);
3516

36-
if (action.commitFrom === EMPTY_COMMIT_HASH) {
37-
action.commitFrom = action.commitData[action.commitData.length - 1].parent;
17+
try {
18+
const path = `${action.proxyGitPath}/${action.repoName}`;
19+
const git = simpleGit(path);
20+
const log = await git.log({ from: action.commitFrom, to: action.commitTo });
21+
22+
action.commitData = log.all.toReversed().map((entry, i, array) => {
23+
const parent = i === 0 ? action.commitFrom : array[i - 1].hash;
24+
const timestamp = Math.floor(new Date(entry.date).getTime() / 1000).toString();
25+
return {
26+
message: entry.message || '',
27+
committer: entry.author_name || '',
28+
tree: entry.hash || '',
29+
parent: parent || '0'.repeat(40),
30+
author: entry.author_name || '',
31+
authorEmail: entry.author_email || '',
32+
commitTimestamp: timestamp,
3833
}
39-
const user = action.commitData[action.commitData.length - 1].committer;
40-
action.user = user;
34+
});
35+
console.log(`Updated commitData:`, { commitData: action.commitData });
4136

42-
return await validateUser(user, action, step);
37+
if (action.commitFrom === EMPTY_COMMIT_HASH) {
38+
action.commitFrom = action.commitData[action.commitData.length - 1].parent;
4339
}
40+
const user = action.commitData[action.commitData.length - 1].committer;
41+
action.user = user;
42+
43+
return await validateUser(user, action, step);
4444
} catch (e: any) {
4545
step.setError(e.toString('utf-8'));
4646
} finally {

0 commit comments

Comments
 (0)