Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip branches where author's username cannot be established #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
22 changes: 9 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30342,17 +30342,20 @@ function getCommitCommentsForBranch(commitComments, branch) {
}
function planBranchAction(now, branch, filters, commitComments, params) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
var _a, _b;
if (branch.author &&
params.protectedOrganizationName &&
branch.author.belongsToOrganization) {
return skip(`author ${branch.author.username} belongs to protected organization ${params.protectedOrganizationName}`);
}
if (!((_a = branch.author) === null || _a === void 0 ? void 0 : _a.username) && !params.ignoreUnknownAuthors) {
return skip(`unable to determine username of author for branch ${branch.branchName}`);
}
if (branch.openPrs && params.ignoreBranchesWithOpenPRs) {
return skip(`branch ${branch.branchName} has open PRs`);
}
if (filters.authorsRegex &&
((_a = branch.author) === null || _a === void 0 ? void 0 : _a.username) &&
((_b = branch.author) === null || _b === void 0 ? void 0 : _b.username) &&
filters.authorsRegex.test(branch.author.username)) {
return skip(`author ${branch.author.username} is exempted`);
}
Expand Down Expand Up @@ -30407,7 +30410,6 @@ function logActionRunConfiguration(params, staleCutoff, removeCutoff) {
function removeStaleBranches(octokit, params) {
return __awaiter(this, void 0, void 0, function* () {
var _a, e_1, _b, _c;
var _d;
const headers = params.githubToken
? {
"Content-Type": "application/json",
Expand Down Expand Up @@ -30452,17 +30454,11 @@ function removeStaleBranches(octokit, params) {
skip: "✅",
};
try {
for (var _e = true, _f = __asyncValues((0, readBranches_1.readBranches)(octokit, headers, repo, params.protectedOrganizationName)), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
_c = _g.value;
_e = false;
for (var _d = true, _e = __asyncValues((0, readBranches_1.readBranches)(octokit, headers, repo, params.protectedOrganizationName)), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
_c = _f.value;
_d = false;
const branch = _c;
summary.scanned++;
if (!((_d = branch.author) === null || _d === void 0 ? void 0 : _d.username) && !params.ignoreUnknownAuthors) {
console.error("🛑 Failed to find author associated with branch " +
branch.branchName +
". Use ignore-unknown-authors if this is expected.");
throw new Error("Failed to find author for branch " + branch.branchName);
}
const plan = yield planBranchAction(now.getTime(), branch, filters, commitComments, params);
summary[plan.action]++;
core.startGroup(`${icons[plan.action]} branch ${branch.branchName}`);
Expand All @@ -30484,7 +30480,7 @@ function removeStaleBranches(octokit, params) {
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
}
finally { if (e_1) throw e_1.error; }
}
Expand Down
14 changes: 5 additions & 9 deletions src/removeStaleBranches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ async function planBranchAction(
`author ${branch.author.username} belongs to protected organization ${params.protectedOrganizationName}`
);
}
if (!branch.author?.username && !params.ignoreUnknownAuthors) {
return skip(
`unable to determine username of author for branch ${branch.branchName}`
);
}

if (branch.openPrs && params.ignoreBranchesWithOpenPRs) {
return skip(`branch ${branch.branchName} has open PRs`);
Expand Down Expand Up @@ -281,15 +286,6 @@ export async function removeStaleBranches(
params.protectedOrganizationName
)) {
summary.scanned++;
if (!branch.author?.username && !params.ignoreUnknownAuthors) {
console.error(
"🛑 Failed to find author associated with branch " +
branch.branchName +
". Use ignore-unknown-authors if this is expected."
);
throw new Error("Failed to find author for branch " + branch.branchName);
}

const plan = await planBranchAction(
now.getTime(),
branch,
Expand Down