Skip to content

Commit

Permalink
fix build issues related to octokit upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Feb 3, 2021
1 parent 00ea355 commit 5d29f1e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
18 changes: 11 additions & 7 deletions packages/core/src/auto.ts
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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}>`);

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/git.ts
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/log-parse.ts
Expand Up @@ -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 */
Expand Down
19 changes: 13 additions & 6 deletions packages/core/src/release.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion plugins/all-contributors/src/index.ts
Expand Up @@ -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<string, Set<string>> = {};

if (!body) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/pr-body-labels/src/index.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 5d29f1e

Please sign in to comment.