5
0
Fork 0
mirror of https://github.com/pre-commit/action.git synced 2025-11-09 03:26:56 +00:00

Fixed bug pushing to private repositories.

This commit is contained in:
Tonye Jack 2021-06-01 15:42:54 -04:00
parent d0b0a000b5
commit 9df90cc07e

View file

@ -28,8 +28,8 @@ function hashFile(filePath) {
return hashString(fs.readFileSync(filePath).toString());
}
function addToken(url, token) {
return url.replace(/^https:\/\//, `https://x-access-token:${token}@`);
function addToken(token, repository) {
return `https://${token}@github.com/${repository}`;
}
async function main() {
@ -44,6 +44,7 @@ async function main() {
'--color=always',
...tr.argStringToArray(core.getInput('extra_args')),
];
const repository = `${github.context.repo.owner}/${github.context.repo.repo}`;
const token = core.getInput('token');
const pr = github.context.payload.pull_request;
const push = !!token && !!pr;
@ -77,7 +78,7 @@ async function main() {
await exec.exec('git', ['checkout', 'HEAD', '-b', branch]);
await exec.exec('git', ['commit', '-am', 'pre-commit fixes']);
const url = addToken(pr.head.repo.clone_url, token);
const url = addToken(repository, token);
await exec.exec('git', ['push', url, 'HEAD']);
});
}