Skip to content

Commit

Permalink
fix: don't fail if the commit doesn't have an attached user
Browse files Browse the repository at this point in the history
  • Loading branch information
fpicalausa committed Jun 2, 2022
1 parent ec8f7db commit 95af702
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
13 changes: 9 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31317,12 +31317,13 @@ class TaggedCommitComments {
this.headers = headers;
}
static formatCommentMessage(messageTemplate, branch, config, repo) {
const username = branch.username || "(Unknown user)";
return messageTemplate
.replace(/[{]branchName[}]/g, branch.branchName)
.replace(/[{]branchUrl[}]/g, `https://github.com/${encodeURIComponent(repo.owner)}/${encodeURIComponent(repo.repo)}/tree/${encodeURIComponent(branch.branchName)}`)
.replace(/[{]repoOwner[}]/g, repo.owner)
.replace(/[{]repoName[}]/g, repo.repo)
.replace(/[{]author[}]/g, branch.username)
.replace(/[{]author[}]/g, username)
.replace(/[{]daysBeforeBranchStale[}]/g, String(config.daysBeforeBranchStale))
.replace(/[{]daysBeforeBranchDelete[}]/g, String(config.daysBeforeBranchDelete));
}
Expand Down Expand Up @@ -31555,7 +31556,9 @@ function readBranches(octokit, headers, repo, organization) {
const { repository: { refs: { edges, pageInfo }, }, } = yield __await(octokit.graphql(organization ? GRAPHQL_QUERY_WITH_ORG : GRAPHQL_QUERY, params));
for (let i = 0; i < edges.length; ++i) {
const ref = edges[i];
const { node: { branchName, prefix, refUpdateRule, target: { oid, author: { date, user: { login, organization }, }, }, }, } = ref;
const { node: { branchName, prefix, refUpdateRule, target: { oid, author: { date, user }, }, }, } = ref;
const login = user ? user.login : null;
const organization = user ? user.organization.id : null;
yield yield __await({
date: Date.parse(date),
branchName,
Expand Down Expand Up @@ -31633,7 +31636,7 @@ const date_fns_1 = __nccwpck_require__(3314);
function processBranch(plan, branch, commitComments, params) {
return __awaiter(this, void 0, void 0, function* () {
console.log("-> branch was last updated by " +
branch.username +
(branch.username || "(unknown user)") +
" on " +
(0, formatISO_1.default)(branch.date));
if (plan.action === "skip") {
Expand Down Expand Up @@ -31693,7 +31696,9 @@ function planBranchAction(now, branch, filters, commitComments, params) {
if (params.protectedOrganizationName && branch.belongsToOrganization) {
return skip(`author ${branch.username} belongs to protected organization ${params.protectedOrganizationName}`);
}
if (filters.authorsRegex && filters.authorsRegex.test(branch.username)) {
if (filters.authorsRegex &&
branch.username &&
filters.authorsRegex.test(branch.username)) {
return skip(`author ${branch.username} is exempted`);
}
if (filters.branchRegex && filters.branchRegex.test(branch.branchName)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export declare type Branch = {
branchName: string;
prefix: string;
commitId: string;
username: string;
username: string | null;
isProtected: boolean;
};
export declare type Repo = {
Expand Down
3 changes: 2 additions & 1 deletion src/commitComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class TaggedCommitComments {
config: Pick<Params, "daysBeforeBranchStale" | "daysBeforeBranchDelete">,
repo: Repo
) {
const username = branch.username || "(Unknown user)";
return messageTemplate
.replace(/[{]branchName[}]/g, branch.branchName)
.replace(
Expand All @@ -46,7 +47,7 @@ export class TaggedCommitComments {
)
.replace(/[{]repoOwner[}]/g, repo.owner)
.replace(/[{]repoName[}]/g, repo.repo)
.replace(/[{]author[}]/g, branch.username)
.replace(/[{]author[}]/g, username)
.replace(
/[{]daysBeforeBranchStale[}]/g,
String(config.daysBeforeBranchStale)
Expand Down
7 changes: 3 additions & 4 deletions src/readBranches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,13 @@ export async function* readBranches(
refUpdateRule,
target: {
oid,
author: {
date,
user: { login, organization },
},
author: { date, user },
},
},
} = ref;

const login = user ? user.login : null;
const organization = user ? user.organization.id : null;
yield {
date: Date.parse(date),
branchName,
Expand Down
8 changes: 6 additions & 2 deletions src/removeStaleBranches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function processBranch(
) {
console.log(
"-> branch was last updated by " +
branch.username +
(branch.username || "(unknown user)") +
" on " +
formatISO(branch.date)
);
Expand Down Expand Up @@ -126,7 +126,11 @@ async function planBranchAction(
);
}

if (filters.authorsRegex && filters.authorsRegex.test(branch.username)) {
if (
filters.authorsRegex &&
branch.username &&
filters.authorsRegex.test(branch.username)
) {
return skip(`author ${branch.username} is exempted`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type Branch = {
branchName: string;
prefix: string;
commitId: string;
username: string;
username: string | null;
isProtected: boolean;
};

Expand Down

0 comments on commit 95af702

Please sign in to comment.