Skip to content

Commit 4454122

Browse files
authored
Update changesets deps and probot (#56)
1 parent 553f057 commit 4454122

10 files changed

+1216
-1297
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
.next

get-changed-packages.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { parse as parseConfig } from "@changesets/config";
99
import { PreState, NewChangeset } from "@changesets/types";
1010
import parseChangeset from "@changesets/parse";
1111

12-
type Sha = string & { ___sha: string };
13-
1412
export let getChangedPackages = async ({
1513
owner,
1614
repo,
@@ -87,6 +85,7 @@ export let getChangedPackages = async ({
8785
let changedFiles = await changedFilesPromise;
8886

8987
for (let item of tree.data.tree) {
88+
if (!item.path) continue;
9089
if (item.path.endsWith("/package.json")) {
9190
let dirPath = nodePath.dirname(item.path);
9291
potentialWorkspaceDirectories.push(dirPath);

index.ts

+72-75
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-ignore
22
import humanId from "human-id";
3-
import { Application, Context } from "probot";
4-
import Webhooks from "@octokit/webhooks";
3+
import { Probot, Context } from "probot";
4+
import { EmitterWebhookEvent } from "@octokit/webhooks";
55
import { getChangedPackages } from "./get-changed-packages";
66
import {
77
ReleasePlan,
@@ -15,27 +15,23 @@ import { ValidationError } from "@changesets/errors";
1515
const getReleasePlanMessage = (releasePlan: ReleasePlan | null) => {
1616
if (!releasePlan) return "";
1717

18-
const publishableReleases = releasePlan.releases
19-
.filter(
20-
(
21-
x
22-
): x is ComprehensiveRelease & { type: Exclude<VersionType, "none"> } =>
23-
x.type !== "none"
24-
)
18+
const publishableReleases = releasePlan.releases.filter(
19+
(x): x is ComprehensiveRelease & { type: Exclude<VersionType, "none"> } =>
20+
x.type !== "none"
21+
);
2522

2623
let table = markdownTable([
2724
["Name", "Type"],
28-
...publishableReleases
29-
.map((x) => {
30-
return [
31-
x.name,
32-
{
33-
major: "Major",
34-
minor: "Minor",
35-
patch: "Patch",
36-
}[x.type],
37-
];
38-
}),
25+
...publishableReleases.map((x) => {
26+
return [
27+
x.name,
28+
{
29+
major: "Major",
30+
minor: "Minor",
31+
patch: "Patch",
32+
}[x.type],
33+
];
34+
}),
3935
]);
4036

4137
return `<details><summary>This PR includes ${
@@ -101,41 +97,44 @@ ${changedPackages.map((x) => `"${x}": patch`).join("\n")}
10197
${title}
10298
`);
10399

104-
type PRContext = Context<Webhooks.EventPayloads.WebhookPayloadPullRequest>;
100+
type PRContext = EmitterWebhookEvent<
101+
"pull_request.opened" | "pull_request.synchronize"
102+
> &
103+
Omit<Context, keyof EmitterWebhookEvent>;
105104

106105
const getCommentId = (
107106
context: PRContext,
108107
params: { repo: string; owner: string; issue_number: number }
109108
) =>
110-
context.github.issues.listComments(params).then((comments) => {
109+
context.octokit.issues.listComments(params).then((comments) => {
111110
const changesetBotComment = comments.data.find(
112111
// TODO: find what the current user is in some way or something
113112
(comment) =>
114-
comment.user.login === "changeset-bot[bot]" ||
115-
comment.user.login === "changesets-test-bot[bot]"
113+
comment.user?.login === "changeset-bot[bot]" ||
114+
comment.user?.login === "changesets-test-bot[bot]"
116115
);
117116
return changesetBotComment ? changesetBotComment.id : null;
118117
});
119118

120119
const hasChangesetBeenAdded = (
121-
changedFilesPromise: ReturnType<PRContext["github"]["pulls"]["listFiles"]>
120+
changedFilesPromise: ReturnType<PRContext["octokit"]["pulls"]["listFiles"]>
122121
) =>
123122
changedFilesPromise.then((files) =>
124123
files.data.some(
125124
(file) =>
126125
file.status === "added" &&
127126
/^\.changeset\/.+\.md$/.test(file.filename) &&
128-
file.filename !== '.changeset/README.md'
127+
file.filename !== ".changeset/README.md"
129128
)
130129
);
131130

132-
export default (app: Application) => {
131+
export default (app: Probot) => {
133132
app.auth();
134133
app.log("Yay, the app was loaded!");
135134

136135
app.on(
137136
["pull_request.opened", "pull_request.synchronize"],
138-
async (context: PRContext) => {
137+
async (context) => {
139138
if (
140139
context.payload.pull_request.head.ref.startsWith("changeset-release")
141140
) {
@@ -153,52 +152,49 @@ export default (app: Application) => {
153152
};
154153

155154
const latestCommitSha = context.payload.pull_request.head.sha;
156-
let changedFilesPromise = context.github.pulls.listFiles({
155+
let changedFilesPromise = context.octokit.pulls.listFiles({
157156
...repo,
158157
pull_number: number,
159158
});
160159

161-
console.log(context.payload);
162-
163-
const [
164-
commentId,
165-
hasChangeset,
166-
{ changedPackages, releasePlan },
167-
] = await Promise.all([
168-
// we know the comment won't exist on opened events
169-
// ok, well like technically that's wrong
170-
// but reducing time is nice here so that
171-
// deploying this doesn't cost money
172-
context.payload.action === "synchronize"
173-
? getCommentId(context, { ...repo, issue_number: number })
174-
: undefined,
175-
hasChangesetBeenAdded(changedFilesPromise),
176-
getChangedPackages({
177-
repo: context.payload.pull_request.head.repo.name,
178-
owner: context.payload.pull_request.head.repo.owner.login,
179-
ref: context.payload.pull_request.head.ref,
180-
changedFiles: changedFilesPromise.then((x) =>
181-
x.data.map((x) => x.filename)
182-
),
183-
octokit: context.github,
184-
installationToken: (
185-
await (await app.auth()).apps.createInstallationAccessToken({
186-
installation_id: context.payload.installation!.id,
187-
})
188-
).data.token,
189-
}).catch((err) => {
190-
if (err instanceof ValidationError) {
191-
errFromFetchingChangedFiles = `<details><summary>💥 An error occurred when fetching the changed packages and changesets in this PR</summary>\n\n\`\`\`\n${err.message}\n\`\`\`\n\n</details>\n`;
192-
} else {
193-
console.error(err);
194-
captureException(err);
195-
}
196-
return {
197-
changedPackages: ["@fake-scope/fake-pkg"],
198-
releasePlan: null,
199-
};
200-
}),
201-
] as const);
160+
const [commentId, hasChangeset, { changedPackages, releasePlan }] =
161+
await Promise.all([
162+
// we know the comment won't exist on opened events
163+
// ok, well like technically that's wrong
164+
// but reducing time is nice here so that
165+
// deploying this doesn't cost money
166+
context.payload.action === "synchronize"
167+
? getCommentId(context, { ...repo, issue_number: number })
168+
: undefined,
169+
hasChangesetBeenAdded(changedFilesPromise),
170+
getChangedPackages({
171+
repo: context.payload.pull_request.head.repo.name,
172+
owner: context.payload.pull_request.head.repo.owner.login,
173+
ref: context.payload.pull_request.head.ref,
174+
changedFiles: changedFilesPromise.then((x) =>
175+
x.data.map((x) => x.filename)
176+
),
177+
octokit: context.octokit,
178+
installationToken: (
179+
await (
180+
await app.auth()
181+
).apps.createInstallationAccessToken({
182+
installation_id: context.payload.installation!.id,
183+
})
184+
).data.token,
185+
}).catch((err) => {
186+
if (err instanceof ValidationError) {
187+
errFromFetchingChangedFiles = `<details><summary>💥 An error occurred when fetching the changed packages and changesets in this PR</summary>\n\n\`\`\`\n${err.message}\n\`\`\`\n\n</details>\n`;
188+
} else {
189+
console.error(err);
190+
captureException(err);
191+
}
192+
return {
193+
changedPackages: ["@fake-scope/fake-pkg"],
194+
releasePlan: null,
195+
};
196+
}),
197+
] as const);
202198

203199
let addChangesetUrl = `${
204200
context.payload.pull_request.head.repo.html_url
@@ -214,7 +210,6 @@ export default (app: Application) => {
214210

215211
let prComment = {
216212
...repo,
217-
comment_id: commentId,
218213
issue_number: number,
219214
body:
220215
(hasChangeset
@@ -226,11 +221,13 @@ export default (app: Application) => {
226221
)) + errFromFetchingChangedFiles,
227222
};
228223

229-
if (prComment.comment_id != null) {
230-
// @ts-ignore
231-
return context.github.issues.updateComment(prComment);
224+
if (commentId != null) {
225+
return context.octokit.issues.updateComment({
226+
...prComment,
227+
comment_id: commentId,
228+
});
232229
}
233-
return context.github.issues.createComment(prComment);
230+
return context.octokit.issues.createComment(prComment);
234231
} catch (err) {
235232
console.error(err);
236233
throw err;

next-env.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

now.js

-16
This file was deleted.

now.json

-12
This file was deleted.

package.json

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@
66
"repository": "https://github.com/changesets/bot",
77
"homepage": "https://github.com/apps/changeset-bot",
88
"dependencies": {
9-
"@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",
9+
"@changesets/assemble-release-plan": "^5.1.3",
10+
"@changesets/config": "^2.0.0",
11+
"@changesets/parse": "^0.3.13",
12+
"@changesets/types": "^5.0.0",
13+
"@manypkg/get-packages": "^1.1.3",
1414
"@types/bunyan": "^1.8.6",
1515
"@types/express": "^4.17.2",
1616
"@types/ioredis": "^4.14.8",
1717
"@types/js-yaml": "^3.12.2",
1818
"@types/markdown-table": "^2.0.0",
1919
"@types/micromatch": "^4.0.1",
2020
"@types/node-fetch": "^2.5.5",
21+
"@types/react": "^18.0.14",
22+
"@types/react-dom": "^18.0.5",
2123
"human-id": "^1.0.2",
2224
"js-yaml": "^3.14.0",
2325
"markdown-table": "^2.0.0",
26+
"next": "^12.1.6",
2427
"node-fetch": "^2.6.1",
2528
"path": "^0.12.7",
26-
"probot": "^10.9.3",
27-
"typescript": "^4.0.3"
29+
"probot": "^12.2.4",
30+
"react": "^18.2.0",
31+
"react-dom": "^18.2.0",
32+
"typescript": "^4.7.4"
2833
},
2934
"devDependencies": {
3035
"jest": "^24.1.0",

pages/api/webhook.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createNodeMiddleware, createProbot } from "probot";
2+
import app from "../../index";
3+
4+
// requires:
5+
// - APP_ID
6+
// - PRIVATE_KEY
7+
// - WEBHOOK_SECRET
8+
const probot = createProbot();
9+
10+
export default createNodeMiddleware(app, {
11+
probot,
12+
webhooksPath: "/api/webhook",
13+
});

0 commit comments

Comments
 (0)