Skip to content

Commit

Permalink
Merge branch 'main' into releaser
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSlome authored May 10, 2024
2 parents e371166 + 6ddc713 commit 538a9a4
Show file tree
Hide file tree
Showing 10 changed files with 348 additions and 316 deletions.
195 changes: 98 additions & 97 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finos/git-proxy",
"version": "1.2.0",
"version": "1.2.1",
"description": "Deploy custom push protections and policies on top of Git.",
"scripts": {
"cli": "node ./packages/git-proxy-cli/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/proxy/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const pushActionChain = [
proc.push.pullRemote,
proc.push.writePack,
proc.push.getDiff,
proc.push.clearBareClone,
proc.push.scanDiff,
proc.push.blockForAuth,
];
Expand Down
20 changes: 20 additions & 0 deletions src/proxy/processors/push-action/clearBareClone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Step = require('../../actions').Step;
const fs = require('node:fs');

const exec = async (req, action) => {
const step = new Step('clearBareClone');

// Recursively remove the contents of ./.remote and ignore exceptions
fs.rm('./.remote', { recursive: true, force: true }, (err) => {
if (err) {
throw err;
}
console.log(`.remote is deleted!`);
});

action.addStep(step);
return action;
};

exec.displayName = 'clearBareClone.exec';
exports.exec = exec;
1 change: 1 addition & 0 deletions src/proxy/processors/push-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ exports.checkIfWaitingAuth = require('./checkIfWaitingAuth').exec;
exports.checkCommitMessages = require('./checkCommitMessages').exec;
exports.checkAuthorEmails = require('./checkAuthorEmails').exec;
exports.checkUserPushPermission = require('./checkUserPushPermission').exec;
exports.clearBareClone = require('./clearBareClone').exec;
23 changes: 3 additions & 20 deletions src/proxy/processors/push-action/pullRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,9 @@ const exec = async (req, action) => {

const cmd = `git clone ${action.url} --bare`;

// Retrieve authorization headers
const authorizationHeader = req.headers?.authorization;

// Validate the authorization headers
const authorizationValid =
authorizationHeader &&
typeof authorizationHeader === 'string' &&
authorizationHeader.includes('Basic ');

// Construct clone URL depending on presence of authorization headers
const cloneUrl = authorizationValid
? `https://${Buffer.from(authorizationHeader.split(' ')[1], 'base64')}@${action.url.replace(
/https*:\/\//,
'',
)}`
: action.url;

step.log(`Exectuting ${cmd}${authorizationValid ? ' with credentials' : ''}`);

const response = spawnSync('git', ['clone', cloneUrl, '--bare', '--progress'], {
step.log(`Exectuting ${cmd}`);

const response = spawnSync('git', ['clone', action.url, '--bare', '--progress'], {
cwd: action.proxyGitPath,
encoding: 'utf-8',
});
Expand Down
26 changes: 26 additions & 0 deletions test/testClearBareClone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs');
const chai = require('chai');
const clearBareClone = require('../src/proxy/processors/push-action/clearBareClone').exec;
const pullRemote = require('../src/proxy/processors/push-action/pullRemote').exec;
const { Action } = require('../src/proxy/actions/Action');
chai.should();

const expect = chai.expect;
const timestamp = Date.now();

describe('clear bare and local clones', async () => {
it('pull remote generates a local .remote folder', async () => {
const action = new Action('123', 'type', 'get', timestamp, 'finos/git-proxy');
action.url = 'https://github.com/finos/git-proxy';
await pullRemote({}, action);

expect(fs.existsSync(`./.remote/${timestamp}`)).to.be.true;
});

it('clear bare clone function purges .remote folder and specific clone folder', async () => {
const action = new Action('123', 'type', 'get', timestamp, 'finos/git-proxy');
await clearBareClone(null, action);
expect(fs.existsSync(`./.remote`)).to.throw;
expect(fs.existsSync(`./.remote/${timestamp}`)).to.throw;
});
});
2 changes: 1 addition & 1 deletion website/docs/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ npm install -g @finos/git-proxy-cli
To install a specific version of Git Proxy, append the version to the end of the install command:

```bash
npm install -g @finos/[email protected].0
npm install -g @finos/[email protected].1
```

To install a specific version of the Git Proxy CLI, append the version to the end of the install command:
Expand Down
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
projectName: `${projectName}`,
organizationName: 'FINOS',
customFields: {
version: '1.2.0',
version: '1.2.1',
},
scripts: ['https://buttons.github.io/buttons.js'],
stylesheets: ['https://fonts.googleapis.com/css?family=Overpass:400,400i,700'],
Expand Down
Loading

0 comments on commit 538a9a4

Please sign in to comment.