Skip to content

Commit a884b8e

Browse files
committed
Revert "Update deps and setup to log to Sentry on changed package fetching"
This reverts commit ec93428.
1 parent ec93428 commit a884b8e

File tree

4 files changed

+333
-1518
lines changed

4 files changed

+333
-1518
lines changed

get-changed-packages.ts

Lines changed: 4 additions & 2 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 { ProbotOctokit } from "probot";
3+
import { Octokit } 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: InstanceType<typeof ProbotOctokit>;
26+
octokit: Octokit;
2727
installationToken: string;
2828
}) => {
2929
let hasErrored = false;
@@ -82,6 +82,7 @@ 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 }>();
8586
let potentialWorkspaceDirectories: string[] = [];
8687
let isPnpm = false;
8788
let changedFiles = await changedFilesPromise;
@@ -90,6 +91,7 @@ export let getChangedPackages = async ({
9091
if (item.path.endsWith("/package.json")) {
9192
let dirPath = nodePath.dirname(item.path);
9293
potentialWorkspaceDirectories.push(dirPath);
94+
itemsByDirPath.set(dirPath, item);
9395
} else if (item.path === "pnpm-workspace.yaml") {
9496
isPnpm = true;
9597
} else if (item.path === ".changeset/pre.json") {

index.ts

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

149
const getReleasePlanMessage = (releasePlan: ReleasePlan | null) => {
1510
if (!releasePlan) return "";
1611

1712
let table = markdownTable([
1813
["Name", "Type"],
1914
...releasePlan.releases
20-
.filter(
21-
(
22-
x
23-
): x is ComprehensiveRelease & { type: Exclude<VersionType, "none"> } =>
24-
x.type !== "none"
25-
)
26-
.map((x) => {
15+
.filter((x): x is ComprehensiveRelease & { type: Exclude<VersionType, 'none'>} => x.type !== 'none')
16+
.map(x => {
2717
return [
2818
x.name,
2919
{
3020
major: "Major",
3121
minor: "Minor",
32-
patch: "Patch",
33-
}[x.type],
22+
patch: "Patch"
23+
}[x.type]
3424
];
35-
}),
25+
})
3626
]);
3727

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

9383
const getNewChangesetTemplate = (changedPackages: string[], title: string) =>
9484
encodeURIComponent(`---
95-
${changedPackages.map((x) => `"${x}": patch`).join("\n")}
85+
${changedPackages.map(x => `"${x}": patch`).join("\n")}
9686
---
9787
9888
${title}
9989
`);
10090

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

10393
const getCommentId = (
10494
context: PRContext,
10595
params: { repo: string; owner: string; issue_number: number }
10696
) =>
107-
context.github.issues.listComments(params).then((comments) => {
97+
context.github.issues.listComments(params).then(comments => {
10898
const changesetBotComment = comments.data.find(
10999
// TODO: find what the current user is in some way or something
110-
(comment) =>
100+
comment =>
111101
comment.user.login === "changeset-bot[bot]" ||
112102
comment.user.login === "changesets-test-bot[bot]"
113103
);
114104
return changesetBotComment ? changesetBotComment.id : null;
115105
});
116106

117107
const getChangesetId = (
118-
changedFilesPromise: ReturnType<PRContext["github"]["pulls"]["listFiles"]>,
108+
changedFilesPromise: Promise<
109+
Octokit.Response<Octokit.PullsListFilesResponse>
110+
>,
119111
params: { repo: string; owner: string; pull_number: number }
120112
) =>
121-
changedFilesPromise.then((files) =>
113+
changedFilesPromise.then(files =>
122114
files.data.some(
123-
(file) =>
124-
file.filename.startsWith(".changeset") && file.status === "added"
115+
file => file.filename.startsWith(".changeset") && file.status === "added"
125116
)
126117
);
127118

@@ -130,7 +121,7 @@ async function fetchJsonFile(context: PRContext, path: string) {
130121
owner: context.payload.pull_request.head.repo.owner.login,
131122
repo: context.payload.pull_request.head.repo.name,
132123
path,
133-
ref: context.payload.pull_request.head.ref,
124+
ref: context.payload.pull_request.head.ref
134125
});
135126
// @ts-ignore
136127
let buffer = Buffer.from(output.data.content, "base64");
@@ -157,21 +148,22 @@ export default (app: Application) => {
157148

158149
let repo = {
159150
repo: context.payload.repository.name,
160-
owner: context.payload.repository.owner.login,
151+
owner: context.payload.repository.owner.login
161152
};
162153

163154
const latestCommitSha = context.payload.pull_request.head.sha;
155+
164156
let changedFilesPromise = context.github.pulls.listFiles({
165157
...repo,
166-
pull_number: number,
158+
pull_number: number
167159
});
168160

169161
console.log(context.payload);
170162

171163
const [
172164
commentId,
173165
hasChangeset,
174-
{ changedPackages, releasePlan },
166+
{ changedPackages, releasePlan }
175167
] = await Promise.all([
176168
// we know the comment won't exist on opened events
177169
// ok, well like technically that's wrong
@@ -185,23 +177,20 @@ export default (app: Application) => {
185177
repo: context.payload.pull_request.head.repo.name,
186178
owner: context.payload.pull_request.head.repo.owner.login,
187179
ref: context.payload.pull_request.head.ref,
188-
changedFiles: changedFilesPromise.then((x) =>
189-
x.data.map((x) => x.filename)
180+
changedFiles: changedFilesPromise.then(x =>
181+
x.data.map(x => x.filename)
190182
),
191183
octokit: context.github,
192-
installationToken: (
193-
await (await app.auth()).apps.createInstallationAccessToken({
194-
installation_id: context.payload.installation!.id,
195-
})
196-
).data.token,
197-
}).catch((err) => {
184+
installationToken: await app.app.getInstallationAccessToken({
185+
installationId: (context.payload as any).installation.id
186+
})
187+
}).catch(err => {
198188
console.error(err);
199-
captureException(err);
200189
return {
201190
changedPackages: ["@fake-scope/fake-pkg"],
202-
releasePlan: null,
191+
releasePlan: null
203192
};
204-
}),
193+
})
205194
] as const);
206195

207196
let addChangesetUrl = `${
@@ -210,7 +199,7 @@ export default (app: Application) => {
210199
context.payload.pull_request.head.ref
211200
}?filename=.changeset/${humanId({
212201
separator: "-",
213-
capitalize: false,
202+
capitalize: false
214203
})}.md&value=${getNewChangesetTemplate(
215204
changedPackages,
216205
context.payload.pull_request.title
@@ -222,7 +211,7 @@ export default (app: Application) => {
222211
issue_number: number,
223212
body: hasChangeset
224213
? getApproveMessage(latestCommitSha, addChangesetUrl, releasePlan)
225-
: getAbsentMessage(latestCommitSha, addChangesetUrl, releasePlan),
214+
: getAbsentMessage(latestCommitSha, addChangesetUrl, releasePlan)
226215
};
227216

228217
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.4.0",
11-
"@changesets/parse": "^0.3.7",
12-
"@changesets/types": "^3.2.0",
13-
"@manypkg/get-packages": "^1.1.1",
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",
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.14.0",
22+
"js-yaml": "^3.13.1",
2323
"markdown-table": "^2.0.0",
2424
"node-fetch": "^2.6.0",
2525
"path": "^0.12.7",
26-
"probot": "^10.9.3",
27-
"typescript": "^4.0.3"
26+
"probot": "^9.5.0",
27+
"typescript": "^3.8.3"
2828
},
2929
"devDependencies": {
3030
"jest": "^24.1.0",

0 commit comments

Comments
 (0)