Skip to content

Commit

Permalink
fix local path
Browse files Browse the repository at this point in the history
  • Loading branch information
swznd committed Apr 20, 2020
1 parent 49ff191 commit eccf44d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const micromatch = require('micromatch');
const user = core.getInput('user');
const password = core.getInput('password');
const privateKey = core.getInput('private_key');
const localPath = core.getInput('local_path');
const remotePath = (core.getInput('remote_path') || '').trim('/');
const localPath = trimChar((core.getInput('local_path') || ''), '/').trim();
const remotePath = trimChar((core.getInput('remote_path') || ''), '/').trim();
const ignore = (core.getInput('ignore') || '').split(',').filter(Boolean);
const remoteRev = core.getInput('remote_revision');
const payload = github.context.payload;
Expand Down Expand Up @@ -69,18 +69,25 @@ const micromatch = require('micromatch');

console.log('Comparing', `${start}..${end}`);

const modified = await git('diff', '--name-only', '--diff-filter=AM', '-M100%', start, end);
const modified = await git('diff', '--name-only', '--diff-filter=AMR', '-M100%', start, end);
const deleted = await git('diff-tree', '--name-only', '--diff-filter=D', '-t', start, end);

const filterFile = file => {
if (file === '') return false;
if (['', './', '.'].indexOf(localPath) !== -1 && !file.startsWith(localPath)) return false;
if (['', './', '.'].indexOf(localPath) === -1 && !file.startsWith(localPath)) return false;
if (ignore.length && micromatch.isMatch(file, ignore)) return false;
return true;
}

const filteredModified = modified.split("\n").filter(filterFile);
const filteredDeleted = deleted.split("\n").filter(filterFile);
const replacePath = file => {
if (localPath == '') return file;

const start = new RegExp('^' + localPath + '/');
return file.replace(start, '');
}

const filteredModified = modified.split("\n").filter(filterFile).map(replacePath);
const filteredDeleted = deleted.split("\n").filter(filterFile).map(replacePath);

if (filteredModified.length === 0 && filteredDeleted.length === 0) {
console.log('No Changes');
Expand Down Expand Up @@ -157,4 +164,13 @@ const micromatch = require('micromatch');
}
});
}

// https://stackoverflow.com/a/32516190
function trimChar(s, c) {
if (c === "]") c = "\\]";
if (c === "\\") c = "\\\\";
return s.replace(new RegExp(
"^[" + c + "]+|[" + c + "]+$", "g"
), "");
}
})();

0 comments on commit eccf44d

Please sign in to comment.