Skip to content

Commit 50a1761

Browse files
authored
Merge pull request #1189 from jescalada/985-optimize-pullRemote-for-large-repos
feat: push speed optimizations
2 parents c29b56c + be57ca4 commit 50a1761

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ const isEmailAllowed = (email: string): boolean => {
3030
};
3131

3232
const exec = async (req: any, action: Action): Promise<Action> => {
33-
console.log({ req, action });
34-
3533
const step = new Step('checkAuthorEmails');
3634

3735
const uniqueAuthorEmails = [

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ const isMessageAllowed = (commitMessage: string): boolean => {
5151

5252
// Execute if the repo is approved
5353
const exec = async (req: any, action: Action): Promise<Action> => {
54-
console.log({ req, action });
55-
5654
const step = new Step('checkCommitMessages');
5755

5856
const uniqueCommitMessages = [...new Set(action.commitData?.map((commit) => commit.message))];

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ const exec = async (req: any, action: Action): Promise<Action> => {
99
const step = new Step('pullRemote');
1010

1111
try {
12-
action.proxyGitPath = `${dir}/${action.timestamp}`;
13-
14-
step.log(`Creating folder ${action.proxyGitPath}`);
12+
action.proxyGitPath = `${dir}/${action.id}`;
1513

1614
if (!fs.existsSync(dir)) {
1715
fs.mkdirSync(dir);
1816
}
1917

2018
if (!fs.existsSync(action.proxyGitPath)) {
19+
step.log(`Creating folder ${action.proxyGitPath}`);
2120
fs.mkdirSync(action.proxyGitPath, 0o755);
2221
}
2322

@@ -33,15 +32,12 @@ const exec = async (req: any, action: Action): Promise<Action> => {
3332
fs,
3433
http: gitHttpClient,
3534
url: action.url,
36-
onAuth: () => ({
37-
username,
38-
password,
39-
}),
4035
dir: `${action.proxyGitPath}/${action.repoName}`,
36+
onAuth: () => ({ username, password }),
37+
singleBranch: true,
38+
depth: 1,
4139
});
4240

43-
console.log('Clone Success: ', action.url);
44-
4541
step.log(`Completed ${cmd}`);
4642
step.setContent(`Completed ${cmd}`);
4743
} catch (e: any) {

src/proxy/routes/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ const getRouter = async () => {
216216
proxyReqOptDecorator: proxyReqOptDecorator,
217217
proxyReqBodyDecorator: proxyReqBodyDecorator,
218218
proxyErrorHandler: proxyErrorHandler,
219-
}),
219+
stream: true,
220+
} as any),
220221
);
221222
});
222223

@@ -229,7 +230,8 @@ const getRouter = async () => {
229230
proxyReqOptDecorator: proxyReqOptDecorator,
230231
proxyReqBodyDecorator: proxyReqBodyDecorator,
231232
proxyErrorHandler: proxyErrorHandler,
232-
});
233+
stream: true,
234+
} as any);
233235

234236
console.log('proxy keys registered: ', JSON.stringify(proxyKeys));
235237

src/service/routes/push.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ router.post('/:id/reject', async (req, res) => {
7878
});
7979

8080
router.post('/:id/authorise', async (req, res) => {
81-
console.log({ req });
82-
8381
const questions = req.body.params?.attestation;
8482
console.log({ questions });
8583

test/processors/clearBareClone.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ const { Action } = require('../../src/proxy/actions/Action');
66
chai.should();
77

88
const expect = chai.expect;
9+
10+
const actionId = '123__456';
911
const timestamp = Date.now();
1012

1113
describe('clear bare and local clones', async () => {
1214
it('pull remote generates a local .remote folder', async () => {
13-
const action = new Action('123', 'type', 'get', timestamp, 'finos/git-proxy.git');
15+
const action = new Action(actionId, 'type', 'get', timestamp, 'finos/git-proxy.git');
1416
action.url = 'https://github.com/finos/git-proxy.git';
1517

1618
const authorization = `Basic ${Buffer.from('JamieSlome:test').toString('base64')}`;
@@ -24,14 +26,14 @@ describe('clear bare and local clones', async () => {
2426
action,
2527
);
2628

27-
expect(fs.existsSync(`./.remote/${timestamp}`)).to.be.true;
29+
expect(fs.existsSync(`./.remote/${actionId}`)).to.be.true;
2830
}).timeout(20000);
2931

3032
it('clear bare clone function purges .remote folder and specific clone folder', async () => {
31-
const action = new Action('123', 'type', 'get', timestamp, 'finos/git-proxy.git');
33+
const action = new Action(actionId, 'type', 'get', timestamp, 'finos/git-proxy.git');
3234
await clearBareClone(null, action);
3335
expect(fs.existsSync(`./.remote`)).to.throw;
34-
expect(fs.existsSync(`./.remote/${timestamp}`)).to.throw;
36+
expect(fs.existsSync(`./.remote/${actionId}`)).to.throw;
3537
});
3638

3739
afterEach(() => {

0 commit comments

Comments
 (0)