Skip to content

Commit 2bf3959

Browse files
committed
skip: merge (70bf0ef) [skip release]
2 parents c2a57ad + 70bf0ef commit 2bf3959

11 files changed

Lines changed: 410 additions & 2883 deletions

File tree

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The ID of your GitHub App
2+
APP_ID=
3+
WEBHOOK_SECRET=development
4+
5+
# Use `trace` to get verbose logging or `info` to show less
6+
LOG_LEVEL=debug
7+
8+
# Go to https://smee.io/new set this to the URL that you are redirected to.
9+
WEBHOOK_PROXY_URL=

.github/workflows/auto-approve.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
persist-credentials: false
3636
token: ${{ steps.get-workflow-access-token.outputs.token }}
3737

38-
- name: Auto-approve PR
39-
uses: ./
40-
with:
41-
github-token: ${{ steps.get-workflow-access-token.outputs.token }}
42-
config-path: .github/auto-approve.yml
38+
# - name: Auto-approve PR
39+
# uses: ./
40+
# with:
41+
# github-token: ${{ steps.get-workflow-access-token.outputs.token }}
42+
# config-path: .github/auto-approve.yml

.github/workflows/main.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
run: pnpm lint
3939
- name: Run tests
4040
run: pnpm test
41+
- name: Build
42+
run: pnpm build
4143

4244
release:
4345
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pnpm run build
126126
pnpm test
127127
128128
# Type checking
129-
pnpm run typecheck
129+
pnpm run check-types
130130
131131
# Linting
132132
pnpm run lint

dist/index.js

Lines changed: 151 additions & 904 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
"main": "dist/index.js",
1111
"scripts": {
1212
"bootstrap": "pnpm install --prefer-offline --loglevel warn",
13-
"build": "NODE_ENV=production tsup",
13+
"build": "pnpm check-types && NODE_ENV=production tsup",
14+
"start": "pnpm build && probot run dist/index.js",
1415
"fix": "eslint --fix",
1516
"lint": "eslint",
1617
"dev": "tsup --watch",
1718
"test": "vitest run",
1819
"test:watch": "vitest",
19-
"typecheck": "tsc --noEmit"
20+
"check-types": "tsc --noEmit"
2021
},
2122
"prettier": "@bfra.me/prettier-config/120-proof",
2223
"dependencies": {
23-
"@probot/adapter-github-actions": "4.0.3",
24-
"probot": "13.4.7"
24+
"@probot/adapter-github-actions": "5.0.1",
25+
"probot": "14.0.2"
2526
},
2627
"devDependencies": {
2728
"@bfra.me/eslint-config": "0.35.2",

pnpm-lock.yaml

Lines changed: 176 additions & 1909 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {CheckRunEvent, PullRequestEvent, PullRequestReviewEvent} from '@octokit/webhooks-types'
1+
import type {CheckRunCompletedEvent, PullRequestEvent, PullRequestReviewEvent} from '@octokit/webhooks-types'
22
import type {Context, Probot} from 'probot'
33
import process from 'node:process'
44
import {loadConfig} from './config.js'
@@ -14,7 +14,7 @@ async function isValidBot(context: Context<'pull_request' | 'pull_request_review
1414
const config = await loadConfig(context)
1515
const senderLogin = context.payload.sender?.login
1616

17-
if (!senderLogin) {
17+
if (senderLogin == null || senderLogin.trim() === '') {
1818
context.log.warn('No sender login found in payload')
1919
return false
2020
}
@@ -72,7 +72,7 @@ async function haveChecksPassed(
7272
return false
7373
}
7474

75-
const {data: checkRuns} = await context.octokit.checks.listForRef({
75+
const {data: checkRuns} = await context.octokit.rest.checks.listForRef({
7676
owner,
7777
repo,
7878
ref,
@@ -139,7 +139,7 @@ async function hasExcludedLabels(context: Context<'pull_request' | 'pull_request
139139
return false
140140
}
141141

142-
const {data: prData} = await context.octokit.pulls.get({
142+
const {data: prData} = await context.octokit.rest.pulls.get({
143143
...context.repo(),
144144
pull_number: prNumber,
145145
})
@@ -163,7 +163,6 @@ async function hasExcludedLabels(context: Context<'pull_request' | 'pull_request
163163
function isOurBot(context: Context, login: string): boolean {
164164
try {
165165
// Get the current bot login - using environment variable instead of payload
166-
// @ts-expect-error process.env.APP_LOGIN is not defined in the Node.js types
167166
const appLogin = process.env.APP_LOGIN ?? ''
168167
return appLogin ? login === appLogin : false
169168
} catch (error) {
@@ -189,7 +188,7 @@ async function approvePR(
189188
return false
190189
}
191190

192-
await context.octokit.pulls.createReview({
191+
await context.octokit.rest.pulls.createReview({
193192
...context.repo(),
194193
pull_number: prNumber,
195194
event: APPROVE,
@@ -246,7 +245,7 @@ export default (app: Probot): void => {
246245

247246
// Handle check runs that complete
248247
app.on('check_run.completed', async context => {
249-
const checkRunEvent = context.payload as CheckRunEvent
248+
const checkRunEvent = context.payload as CheckRunCompletedEvent
250249
const pullRequests = checkRunEvent.check_run.pull_requests
251250

252251
if (pullRequests.length === 0) {
@@ -256,17 +255,17 @@ export default (app: Probot): void => {
256255
for (const pr of pullRequests) {
257256
try {
258257
// Get the full PR data
259-
const {data: pullRequest} = await context.octokit.pulls.get({
258+
const {data: pullRequest} = await context.octokit.rest.pulls.get({
260259
...context.repo(),
261260
pull_number: pr.number,
262261
})
263262

264263
// Create a PR context with the PR data - this is a workaround to reuse the auth
265264
const prContext = Object.create(context) as Context<'pull_request'>
266265
prContext.payload = {
267-
...context.payload,
266+
...prContext.payload,
268267
pull_request: pullRequest,
269-
} as unknown as PullRequestEvent
268+
} as typeof prContext.payload
270269

271270
// Auto-approve if from valid bot and has approval trigger
272271
if ((await isValidBot(prContext)) && (await hasApprovalTrigger(prContext))) {

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {run} from '@probot/adapter-github-actions'
33
import app from './app.js'
44

55
// Set the INPUT_GITHUB_TOKEN environment variable to the GitHub token passed as an input
6-
// @ts-expect-error INPUT_GITHUB_TOKEN is not defined in the Node.js types
76
process.env.INPUT_GITHUB_TOKEN ??= process.env.GITHUB_TOKEN ?? process.env['INPUT_GITHUB-TOKEN']
87

98
await run(app)

test/auto-approval.test.ts

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ describe('Auto-approval bot', () => {
7979
excludeLabels: [],
8080
}),
8181
octokit: {
82-
checks: {
83-
listForRef: vi.fn().mockResolvedValue({
84-
data: {
85-
check_runs: [{name: 'test-check', status: 'completed', conclusion: 'success'}],
86-
},
87-
}),
88-
},
89-
pulls: {
90-
createReview: vi.fn().mockResolvedValue({}),
82+
rest: {
83+
checks: {
84+
listForRef: vi.fn().mockResolvedValue({
85+
data: {
86+
check_runs: [{name: 'test-check', status: 'completed', conclusion: 'success'}],
87+
},
88+
}),
89+
},
90+
pulls: {
91+
createReview: vi.fn().mockResolvedValue({}),
92+
},
9193
},
9294
},
9395
}
@@ -96,7 +98,7 @@ describe('Auto-approval bot', () => {
9698
await openPrHandler(context)
9799

98100
// Verify the approval call was made
99-
expect(context.octokit.pulls.createReview).toHaveBeenCalledWith({
101+
expect(context.octokit.rest.pulls.createReview).toHaveBeenCalledWith({
100102
owner: 'test-owner',
101103
repo: 'test-repo',
102104
pull_number: 1,
@@ -139,15 +141,17 @@ describe('Auto-approval bot', () => {
139141
excludeLabels: ['do-not-merge'],
140142
}),
141143
octokit: {
142-
checks: {
143-
listForRef: vi.fn().mockResolvedValue({
144-
data: {
145-
check_runs: [{name: 'test-check', status: 'completed', conclusion: 'success'}],
146-
},
147-
}),
148-
},
149-
pulls: {
150-
createReview: vi.fn().mockResolvedValue({}),
144+
rest: {
145+
checks: {
146+
listForRef: vi.fn().mockResolvedValue({
147+
data: {
148+
check_runs: [{name: 'test-check', status: 'completed', conclusion: 'success'}],
149+
},
150+
}),
151+
},
152+
pulls: {
153+
createReview: vi.fn().mockResolvedValue({}),
154+
},
151155
},
152156
},
153157
}
@@ -156,7 +160,7 @@ describe('Auto-approval bot', () => {
156160
await openPrHandler(context)
157161

158162
// Verify the approval call was NOT made
159-
expect(context.octokit.pulls.createReview).not.toHaveBeenCalled()
163+
expect(context.octokit.rest.pulls.createReview).not.toHaveBeenCalled()
160164
})
161165

162166
it('only checks specific required checks when configured', async () => {
@@ -193,18 +197,20 @@ describe('Auto-approval bot', () => {
193197
excludeLabels: [],
194198
}),
195199
octokit: {
196-
checks: {
197-
listForRef: vi.fn().mockResolvedValue({
198-
data: {
199-
check_runs: [
200-
{name: 'required-check', status: 'completed', conclusion: 'success'},
201-
{name: 'other-check', status: 'completed', conclusion: 'failure'},
202-
],
203-
},
204-
}),
205-
},
206-
pulls: {
207-
createReview: vi.fn().mockResolvedValue({}),
200+
rest: {
201+
checks: {
202+
listForRef: vi.fn().mockResolvedValue({
203+
data: {
204+
check_runs: [
205+
{name: 'required-check', status: 'completed', conclusion: 'success'},
206+
{name: 'other-check', status: 'completed', conclusion: 'failure'},
207+
],
208+
},
209+
}),
210+
},
211+
pulls: {
212+
createReview: vi.fn().mockResolvedValue({}),
213+
},
208214
},
209215
},
210216
}
@@ -213,7 +219,7 @@ describe('Auto-approval bot', () => {
213219
await openPrHandler(context)
214220

215221
// Verify the approval call was made
216-
expect(context.octokit.pulls.createReview).toHaveBeenCalledWith({
222+
expect(context.octokit.rest.pulls.createReview).toHaveBeenCalledWith({
217223
owner: 'test-owner',
218224
repo: 'test-repo',
219225
pull_number: 1,
@@ -258,15 +264,17 @@ describe('Auto-approval bot', () => {
258264
excludeLabels: [],
259265
}),
260266
octokit: {
261-
checks: {
262-
listForRef: vi.fn().mockResolvedValue({
263-
data: {
264-
check_runs: [{name: 'test-check', status: 'completed', conclusion: 'success'}],
265-
},
266-
}),
267-
},
268-
pulls: {
269-
createReview: vi.fn().mockResolvedValue({}),
267+
rest: {
268+
checks: {
269+
listForRef: vi.fn().mockResolvedValue({
270+
data: {
271+
check_runs: [{name: 'test-check', status: 'completed', conclusion: 'success'}],
272+
},
273+
}),
274+
},
275+
pulls: {
276+
createReview: vi.fn().mockResolvedValue({}),
277+
},
270278
},
271279
},
272280
}
@@ -275,7 +283,7 @@ describe('Auto-approval bot', () => {
275283
await reviewDismissedHandler(context)
276284

277285
// Verify the approval call was made
278-
expect(context.octokit.pulls.createReview).toHaveBeenCalledWith({
286+
expect(context.octokit.rest.pulls.createReview).toHaveBeenCalledWith({
279287
owner: 'test-owner',
280288
repo: 'test-repo',
281289
pull_number: 1,

0 commit comments

Comments
 (0)