Skip to content

Commit ecca8d6

Browse files
committed
feat: add getMissingData action for fast-forward refs
1 parent 484bbc0 commit ecca8d6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Action, Step } from '../../actions';
2+
import { validateUser } from './checkUserPushPermission';
3+
import simpleGit from 'simple-git';
4+
5+
const exec = async (req: any, action: Action): Promise<Action> => {
6+
const step = new Step('getMissingData');
7+
8+
try {
9+
if (!action.commitData) {
10+
action.commitData = [];
11+
}
12+
13+
if (action.commitData.length === 0) {
14+
console.log(`commitData not found, fetching missing commits from git...`);
15+
const path = `${action.proxyGitPath}/${action.repoName}`;
16+
const git = simpleGit(path);
17+
const log = await git.log({ from: action.commitFrom, to: action.commitTo });
18+
19+
action.commitData = log.all.toReversed().map((entry, i, array) => {
20+
const parent = i === 0 ? action.commitFrom : array[i - 1].hash;
21+
const timestamp = Math.floor(new Date(entry.date).getTime() / 1000).toString();
22+
return {
23+
message: entry.message || '',
24+
committer: entry.author_name || '',
25+
tree: entry.hash || '',
26+
parent: parent || '0'.repeat(40),
27+
author: entry.author_name || '',
28+
authorEmail: entry.author_email || '',
29+
commitTimestamp: timestamp,
30+
}
31+
});
32+
console.log(`Updated commitData:`, { commitData: action.commitData });
33+
34+
if (action.commitFrom === '0000000000000000000000000000000000000000') {
35+
action.commitFrom = action.commitData[action.commitData.length - 1].parent;
36+
}
37+
const user = action.commitData[action.commitData.length - 1].committer;
38+
action.user = user;
39+
40+
return await validateUser(user, action, step);
41+
}
42+
} catch (e: any) {
43+
step.setError(e.toString('utf-8'));
44+
} finally {
45+
action.addStep(step);
46+
}
47+
return action;
48+
};
49+
50+
exec.displayName = 'getMissingData.exec';
51+
52+
export { exec };

0 commit comments

Comments
 (0)