Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions preview/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ function Cleaner(token, repo, cache_dir, tmp_dir) {
'clone',
'--bare',
'--reference', `${cache_dir}/${repo_name}`,
'--',
repo, local_path])
}

const show_heads = () => {
return exec_git(['show-ref', '--heads'], { cwd: local_path });
}


const heads_to_prs = (heads) => {
return heads
.split('\n')
.reduce((acc, line) => {
const found = line.match(/^.+ refs\/heads\/((.+)_(\d+))$/);
const found = line.match(/^[a-f0-9]+\s+refs\/heads\/((?!-)([a-zA-Z0-9_.-]+)_(\d+))$/);
if (found) {
acc.push({
branch: found[1],
Expand Down Expand Up @@ -77,7 +79,7 @@ function Cleaner(token, repo, cache_dir, tmp_dir) {
const prAge = async function (pr) {
return parseInt(await exec_git(
[
"show", "--pretty=%ad", "--no-notes", "--no-patch", "--date=unix",
"show", "--pretty=%ad", "--no-notes", "--no-patch", "--date=unix","--",
pr.branch
],
{ cwd: local_path }
Expand All @@ -89,6 +91,9 @@ function Cleaner(token, repo, cache_dir, tmp_dir) {
// Just for super double ultra paranoia.
throw "Can't delete master!";
}
if (pr.branch.startsWith('-')) {
throw new Error(`Invalid branch name detected, possible argument injection: ${pr.branch}`);
}
await exec_git(
['push', 'origin', '--delete', pr.branch],
{ cwd: local_path }
Expand Down
Loading