Skip to content

Commit ec93428

Browse files
committed
Update deps and setup to log to Sentry on changed package fetching
1 parent 557a83f commit ec93428

File tree

4 files changed

+1518
-333
lines changed

4 files changed

+1518
-333
lines changed

get-changed-packages.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nodePath from "path";
22
import micromatch from "micromatch";
3-
import { Octokit } from "probot";
3+
import { ProbotOctokit } from "probot";
44
import fetch from "node-fetch";
55
import { safeLoad } from "js-yaml";
66
import { Packages, Tool } from "@manypkg/get-packages";
@@ -23,7 +23,7 @@ export let getChangedPackages = async ({
2323
repo: string;
2424
ref: string;
2525
changedFiles: string[] | Promise<string[]>;
26-
octokit: Octokit;
26+
octokit: InstanceType<typeof ProbotOctokit>;
2727
installationToken: string;
2828
}) => {
2929
let hasErrored = false;
@@ -82,7 +82,6 @@ export let getChangedPackages = async ({
8282

8383
let preStatePromise: Promise<PreState> | undefined;
8484
let changesetPromises: Promise<NewChangeset>[] = [];
85-
let itemsByDirPath = new Map<string, { path: string; sha: Sha }>();
8685
let potentialWorkspaceDirectories: string[] = [];
8786
let isPnpm = false;
8887
let changedFiles = await changedFilesPromise;
@@ -91,7 +90,6 @@ export let getChangedPackages = async ({
9190
if (item.path.endsWith("/package.json")) {
9291
let dirPath = nodePath.dirname(item.path);
9392
potentialWorkspaceDirectories.push(dirPath);
94-
itemsByDirPath.set(dirPath, item);
9593
} else if (item.path === "pnpm-workspace.yaml") {
9694
isPnpm = true;
9795
} else if (item.path === ".changeset/pre.json") {

index.ts

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
// @ts-ignore
22
import humanId from "human-id";
3-
import { Application, Context, Octokit } from "probot";
3+
import { Application, Context } from "probot";
44
import Webhooks from "@octokit/webhooks";
55
import { getChangedPackages } from "./get-changed-packages";
6-
import { ReleasePlan, ComprehensiveRelease, VersionType } from "@changesets/types";
6+
import {
7+
ReleasePlan,
8+
ComprehensiveRelease,
9+
VersionType,
10+
} from "@changesets/types";
711
import markdownTable from "markdown-table";
12+
import { captureException } from "@sentry/node";
813

914
const getReleasePlanMessage = (releasePlan: ReleasePlan | null) => {
1015
if (!releasePlan) return "";
1116

1217
let table = markdownTable([
1318
["Name", "Type"],
1419
...releasePlan.releases
15-
.filter((x): x is ComprehensiveRelease & { type: Exclude<VersionType, 'none'>} => x.type !== 'none')
16-
.map(x => {
20+
.filter(
21+
(
22+
x
23+
): x is ComprehensiveRelease & { type: Exclude<VersionType, "none"> } =>
24+
x.type !== "none"
25+
)
26+
.map((x) => {
1727
return [
1828
x.name,
1929
{
2030
major: "Major",
2131
minor: "Minor",
22-
patch: "Patch"
23-
}[x.type]
32+
patch: "Patch",
33+
}[x.type],
2434
];
25-
})
35+
}),
2636
]);
2737

2838
return `<details><summary>This PR includes ${
@@ -82,37 +92,36 @@ Not sure what this means? [Click here to learn what changesets are](https://git
8292

8393
const getNewChangesetTemplate = (changedPackages: string[], title: string) =>
8494
encodeURIComponent(`---
85-
${changedPackages.map(x => `"${x}": patch`).join("\n")}
95+
${changedPackages.map((x) => `"${x}": patch`).join("\n")}
8696
---
8797
8898
${title}
8999
`);
90100

91-
type PRContext = Context<Webhooks.WebhookPayloadPullRequest>;
101+
type PRContext = Context<Webhooks.EventPayloads.WebhookPayloadPullRequest>;
92102

93103
const getCommentId = (
94104
context: PRContext,
95105
params: { repo: string; owner: string; issue_number: number }
96106
) =>
97-
context.github.issues.listComments(params).then(comments => {
107+
context.github.issues.listComments(params).then((comments) => {
98108
const changesetBotComment = comments.data.find(
99109
// TODO: find what the current user is in some way or something
100-
comment =>
110+
(comment) =>
101111
comment.user.login === "changeset-bot[bot]" ||
102112
comment.user.login === "changesets-test-bot[bot]"
103113
);
104114
return changesetBotComment ? changesetBotComment.id : null;
105115
});
106116

107117
const getChangesetId = (
108-
changedFilesPromise: Promise<
109-
Octokit.Response<Octokit.PullsListFilesResponse>
110-
>,
118+
changedFilesPromise: ReturnType<PRContext["github"]["pulls"]["listFiles"]>,
111119
params: { repo: string; owner: string; pull_number: number }
112120
) =>
113-
changedFilesPromise.then(files =>
121+
changedFilesPromise.then((files) =>
114122
files.data.some(
115-
file => file.filename.startsWith(".changeset") && file.status === "added"
123+
(file) =>
124+
file.filename.startsWith(".changeset") && file.status === "added"
116125
)
117126
);
118127

@@ -121,7 +130,7 @@ async function fetchJsonFile(context: PRContext, path: string) {
121130
owner: context.payload.pull_request.head.repo.owner.login,
122131
repo: context.payload.pull_request.head.repo.name,
123132
path,
124-
ref: context.payload.pull_request.head.ref
133+
ref: context.payload.pull_request.head.ref,
125134
});
126135
// @ts-ignore
127136
let buffer = Buffer.from(output.data.content, "base64");
@@ -148,22 +157,21 @@ export default (app: Application) => {
148157

149158
let repo = {
150159
repo: context.payload.repository.name,
151-
owner: context.payload.repository.owner.login
160+
owner: context.payload.repository.owner.login,
152161
};
153162

154163
const latestCommitSha = context.payload.pull_request.head.sha;
155-
156164
let changedFilesPromise = context.github.pulls.listFiles({
157165
...repo,
158-
pull_number: number
166+
pull_number: number,
159167
});
160168

161169
console.log(context.payload);
162170

163171
const [
164172
commentId,
165173
hasChangeset,
166-
{ changedPackages, releasePlan }
174+
{ changedPackages, releasePlan },
167175
] = await Promise.all([
168176
// we know the comment won't exist on opened events
169177
// ok, well like technically that's wrong
@@ -177,20 +185,23 @@ export default (app: Application) => {
177185
repo: context.payload.pull_request.head.repo.name,
178186
owner: context.payload.pull_request.head.repo.owner.login,
179187
ref: context.payload.pull_request.head.ref,
180-
changedFiles: changedFilesPromise.then(x =>
181-
x.data.map(x => x.filename)
188+
changedFiles: changedFilesPromise.then((x) =>
189+
x.data.map((x) => x.filename)
182190
),
183191
octokit: context.github,
184-
installationToken: await app.app.getInstallationAccessToken({
185-
installationId: (context.payload as any).installation.id
186-
})
187-
}).catch(err => {
192+
installationToken: (
193+
await (await app.auth()).apps.createInstallationAccessToken({
194+
installation_id: context.payload.installation!.id,
195+
})
196+
).data.token,
197+
}).catch((err) => {
188198
console.error(err);
199+
captureException(err);
189200
return {
190201
changedPackages: ["@fake-scope/fake-pkg"],
191-
releasePlan: null
202+
releasePlan: null,
192203
};
193-
})
204+
}),
194205
] as const);
195206

196207
let addChangesetUrl = `${
@@ -199,7 +210,7 @@ export default (app: Application) => {
199210
context.payload.pull_request.head.ref
200211
}?filename=.changeset/${humanId({
201212
separator: "-",
202-
capitalize: false
213+
capitalize: false,
203214
})}.md&value=${getNewChangesetTemplate(
204215
changedPackages,
205216
context.payload.pull_request.title
@@ -211,7 +222,7 @@ export default (app: Application) => {
211222
issue_number: number,
212223
body: hasChangeset
213224
? getApproveMessage(latestCommitSha, addChangesetUrl, releasePlan)
214-
: getAbsentMessage(latestCommitSha, addChangesetUrl, releasePlan)
225+
: getAbsentMessage(latestCommitSha, addChangesetUrl, releasePlan),
215226
};
216227

217228
if (prComment.comment_id != null) {

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"homepage": "https://github.com/apps/changeset-bot",
88
"dependencies": {
99
"@changesets/assemble-release-plan": "^4.0.0",
10-
"@changesets/config": "^1.3.0",
11-
"@changesets/parse": "^0.3.6",
12-
"@changesets/types": "^3.1.1",
13-
"@manypkg/get-packages": "^1.1.0",
10+
"@changesets/config": "^1.4.0",
11+
"@changesets/parse": "^0.3.7",
12+
"@changesets/types": "^3.2.0",
13+
"@manypkg/get-packages": "^1.1.1",
1414
"@types/bunyan": "^1.8.6",
1515
"@types/express": "^4.17.2",
1616
"@types/ioredis": "^4.14.8",
@@ -19,12 +19,12 @@
1919
"@types/micromatch": "^4.0.1",
2020
"@types/node-fetch": "^2.5.5",
2121
"human-id": "^1.0.2",
22-
"js-yaml": "^3.13.1",
22+
"js-yaml": "^3.14.0",
2323
"markdown-table": "^2.0.0",
2424
"node-fetch": "^2.6.0",
2525
"path": "^0.12.7",
26-
"probot": "^9.5.0",
27-
"typescript": "^3.8.3"
26+
"probot": "^10.9.3",
27+
"typescript": "^4.0.3"
2828
},
2929
"devDependencies": {
3030
"jest": "^24.1.0",

0 commit comments

Comments
 (0)