Skip to content

Commit ac1a3ed

Browse files
committed
Show config parsing errors in bot comment
1 parent beeb2fc commit ac1a3ed

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

index.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from "@changesets/types";
1111
import markdownTable from "markdown-table";
1212
import { captureException } from "@sentry/node";
13+
import { ValidationError } from "@changesets/errors";
1314

1415
const getReleasePlanMessage = (releasePlan: ReleasePlan | null) => {
1516
if (!releasePlan) return "";
@@ -125,33 +126,21 @@ const getChangesetId = (
125126
)
126127
);
127128

128-
async function fetchJsonFile(context: PRContext, path: string) {
129-
let output = await context.github.repos.getContents({
130-
owner: context.payload.pull_request.head.repo.owner.login,
131-
repo: context.payload.pull_request.head.repo.name,
132-
path,
133-
ref: context.payload.pull_request.head.ref,
134-
});
135-
// @ts-ignore
136-
let buffer = Buffer.from(output.data.content, "base64");
137-
return JSON.parse(buffer.toString("utf8"));
138-
}
139-
140129
export default (app: Application) => {
141130
app.auth();
142131
app.log("Yay, the app was loaded!");
143132

144133
app.on(
145134
["pull_request.opened", "pull_request.synchronize"],
146-
// @ts-ignore
147135
async (context: PRContext) => {
148-
context;
149136
if (
150137
context.payload.pull_request.head.ref.startsWith("changeset-release")
151138
) {
152139
return;
153140
}
154141

142+
let errFromFetchingChangedFiles = "";
143+
155144
try {
156145
let number = context.payload.number;
157146

@@ -195,8 +184,12 @@ export default (app: Application) => {
195184
})
196185
).data.token,
197186
}).catch((err) => {
198-
console.error(err);
199-
captureException(err);
187+
if (err instanceof ValidationError) {
188+
errFromFetchingChangedFiles = `<details><summary>💥 An error occurred when fetching the changed packages in this PR</summary>\n\n\`\`\`\n${err.message}\`\`\`\n\n</details>\n`;
189+
} else {
190+
console.error(err);
191+
captureException(err);
192+
}
200193
return {
201194
changedPackages: ["@fake-scope/fake-pkg"],
202195
releasePlan: null,
@@ -220,9 +213,14 @@ export default (app: Application) => {
220213
...repo,
221214
comment_id: commentId,
222215
issue_number: number,
223-
body: hasChangeset
224-
? getApproveMessage(latestCommitSha, addChangesetUrl, releasePlan)
225-
: getAbsentMessage(latestCommitSha, addChangesetUrl, releasePlan),
216+
body:
217+
(hasChangeset
218+
? getApproveMessage(latestCommitSha, addChangesetUrl, releasePlan)
219+
: getAbsentMessage(
220+
latestCommitSha,
221+
addChangesetUrl,
222+
releasePlan
223+
)) + errFromFetchingChangedFiles,
226224
};
227225

228226
if (prComment.comment_id != null) {

0 commit comments

Comments
 (0)