From 5d29f1ec032631a99de5c233b1c4b2aa974b9cbc Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Wed, 3 Feb 2021 10:00:01 -0800 Subject: [PATCH] fix build issues related to octokit upgrade --- packages/core/src/auto.ts | 18 +++++++++++------- packages/core/src/git.ts | 2 +- packages/core/src/log-parse.ts | 4 ++-- packages/core/src/release.ts | 19 +++++++++++++------ plugins/all-contributors/src/index.ts | 2 +- plugins/pr-body-labels/src/index.ts | 2 +- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/packages/core/src/auto.ts b/packages/core/src/auto.ts index 6fd69efa5c..aa593dc294 100644 --- a/packages/core/src/auto.ts +++ b/packages/core/src/auto.ts @@ -857,14 +857,18 @@ export default class Auto { state: "closed", }); const lastMerged = pulls - .sort( - (a, b) => - new Date(b.merged_at).getTime() - new Date(a.merged_at).getTime() - ) + .sort((a, b) => { + const aDate = a.merged_at ? new Date(a.merged_at).getTime() : 0; + const bDate = b.merged_at ? new Date(b.merged_at).getTime() : 0; + + return bDate - aDate; + }) .find((pull) => pull.merged_at); if (lastMerged) { - labels = lastMerged.labels.map((label) => label.name); + labels = lastMerged.labels + .map((label) => label.name) + .filter((l): l is string => Boolean(l)); } } @@ -2029,8 +2033,8 @@ export default class Auto { const packageAuthor = (await this.hooks.getAuthor.promise()) || {}; const tokenUser = await this.git?.getUser(); - email = email || packageAuthor.email || tokenUser?.email; - name = name || packageAuthor.name || tokenUser?.name; + email = email || packageAuthor.email || tokenUser?.email || undefined; + name = name || packageAuthor.name || tokenUser?.name || undefined; this.logger.verbose.warn(`Using author: ${name} <${email}>`); diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index 9fdfeb3b0d..2a09dc0cd6 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -727,7 +727,7 @@ export default class Git { this.logger.veryVerbose.info("Got PR comments\n", comments); const oldMessage = comments.data.find((comment) => - comment.body.includes(commentIdentifier) + comment.body?.includes(commentIdentifier) ); if (!oldMessage) { diff --git a/packages/core/src/log-parse.ts b/packages/core/src/log-parse.ts index 7a95fe10c0..54d8b63d11 100644 --- a/packages/core/src/log-parse.ts +++ b/packages/core/src/log-parse.ts @@ -3,9 +3,9 @@ import { makeLogParseHooks } from "./utils/make-hooks"; export interface ICommitAuthor { /** Author's name */ - name?: string; + name?: string | null; /** Author's email */ - email?: string; + email?: string | null; /** Author's username */ username?: string; /** The commit this author created */ diff --git a/packages/core/src/release.ts b/packages/core/src/release.ts index 10b01cdf61..d9daf229ea 100644 --- a/packages/core/src/release.ts +++ b/packages/core/src/release.ts @@ -449,7 +449,7 @@ export default class Release { private async getPRsSinceLastRelease() { let lastRelease: { /** Date the last release was published */ - published_at: string; + published_at: string | null; }; try { @@ -507,19 +507,23 @@ export default class Release { return modifiedCommit; } - const labels = info ? info.data.labels.map((l) => l.name) : []; + const labels = info + ? info.data.labels + .map((l) => (typeof l === "string" ? l : l.name)) + .filter((l): l is string => Boolean(l)) + : []; modifiedCommit.labels = [ ...new Set([...labels, ...modifiedCommit.labels]), ]; modifiedCommit.pullRequest.body = info.data.body; modifiedCommit.subject = info.data.title || modifiedCommit.subject; const hasPrOpener = modifiedCommit.authors.some( - (author) => author.username === info.data.user.login + (author) => author.username === info.data.user?.login ); // If we can't find the use who opened the PR in authors attempt // to add that user. - if (!hasPrOpener) { + if (!hasPrOpener && info.data.user) { const user = await this.git.getUserByUsername(info.data.user.login); if (user) { @@ -545,7 +549,10 @@ export default class Release { ); if (!commit.pullRequest && matchPr) { - const labels = matchPr.labels.map((label) => label.name) || []; + const labels = matchPr.labels + .map((label) => label.name) + .filter((l): l is string => Boolean(l)); + commit.labels = [...new Set([...labels, ...commit.labels])]; commit.pullRequest = { number: matchPr.number, @@ -580,7 +587,7 @@ export default class Release { resolvedAuthors = await Promise.all( prCommits.map(async (prCommit) => { if (!prCommit.author) { - return prCommit.commit.author; + return prCommit.commit.author || undefined; } return { diff --git a/plugins/all-contributors/src/index.ts b/plugins/all-contributors/src/index.ts index ed338c296a..e513e19a24 100644 --- a/plugins/all-contributors/src/index.ts +++ b/plugins/all-contributors/src/index.ts @@ -128,7 +128,7 @@ const title = /[#]{0,5}[ ]*[C|c]ontributions/; const contributorLine = /^[-*] @(\S+)\s+[:-]\s+([\S ,]+)$/; /** Find contributions listed in PR bodies */ -function getExtraContributors(body?: string) { +function getExtraContributors(body?: string | null) { const authorContributions: Record> = {}; if (!body) { diff --git a/plugins/pr-body-labels/src/index.ts b/plugins/pr-body-labels/src/index.ts index baa4ae5a62..47b59576a3 100644 --- a/plugins/pr-body-labels/src/index.ts +++ b/plugins/pr-body-labels/src/index.ts @@ -33,7 +33,7 @@ export default class PrBodyLabelsPlugin implements IPlugin { await Promise.all( auto.labels.map(async (label) => { if ( - pr.body.includes(`- [x] \`${label.name}\``) && + pr.body?.includes(`- [x] \`${label.name}\``) && !this.options.disabledLabels.includes(label.name) ) { await auto.git?.addLabelToPr(pr.number, label.name);