Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Bring everything up to speed with new deps and node 20 #80

Open
wants to merge 2 commits into
base: dep-bumps
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
"typescript": true,
"node": true
}
}
}
114 changes: 57 additions & 57 deletions __tests__/cronJobTest/labelPr.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nock from 'nock'
import {setupServer} from 'msw/node'
import {rest} from 'msw'

import {handleCronJobs} from '../../src/cronJobs/handleCronJob'
import * as utils from '../testUtils'
Expand All @@ -9,11 +10,35 @@ import labelFileContents from '../fixtures/labels/labelFileContentsResp.json'
import prListFiles from '../fixtures/pullReq/pullReqListFiles.json'
import prListTestFiles from '../fixtures/pullReq/pullReqListTestFiles.json'

nock.disableNetConnect()
const server = setupServer(
// /repos/Codertocat/Hello-World/pulls?page={1,2}
rest.get(
`${utils.api}/repos/Codertocat/Hello-World/pulls`,
(req, res, ctx) => {
const page = req.url.searchParams.get('page')

if (page == '1') {
return res(ctx.status(200), ctx.json(listPullReqs))
} else {
return res(ctx.status(200), ctx.json([]))
}
}
),
rest.get(
`${utils.api}/repos/Codertocat/Hello-World/contents/.github%2Flabels.yaml`,
utils.mockResponse(200, labelFileContents)
)
)
beforeAll(() =>
server.listen({
onUnhandledRequest: 'warn'
})
)
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe('cronLabelPr', () => {
beforeEach(() => {
nock.cleanAll()
utils.setupActionsEnv('/area')
})

Expand All @@ -24,35 +49,22 @@ describe('cronLabelPr', () => {
// Instead, we use it to gain the repo owner and url
const context = new utils.mockContext(pullReqOpenedEvent)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?page=1')
.reply(200, listPullReqs)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?page=2')
.reply(200, [])

let parsedBody = undefined
const scope = nock(utils.api)
.post('/repos/Codertocat/Hello-World/issues/2/labels', body => {
parsedBody = body
return body
})
.reply(200)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/contents/.github/labels.yaml')
.reply(200, labelFileContents)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls/2/files')
.reply(200, prListFiles)

await handleCronJobs(context)
expect(parsedBody).toEqual({
const observeReq = new utils.observeRequest()
server.use(
rest.post(
`${utils.api}/repos/Codertocat/Hello-World/issues/2/labels`,
utils.mockResponse(200, null, observeReq)
),
rest.get(
`${utils.api}/repos/Codertocat/Hello-World/pulls/2/files`,
utils.mockResponse(200, prListFiles)
)
)

await expect(handleCronJobs(context)).resolves.not.toThrow()
expect(observeReq.body()).toEqual({
labels: ['source']
})
expect(scope.isDone()).toBe(true)
})

it('labels the PR with the test label from glob', async () => {
Expand All @@ -62,34 +74,22 @@ describe('cronLabelPr', () => {
// Instead, we use it to gain the repo owner and url
const context = new utils.mockContext(pullReqOpenedEvent)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?page=1')
.reply(200, listPullReqs)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?page=2')
.reply(200, [])

let parsedBody = undefined
const scope = nock(utils.api)
.post('/repos/Codertocat/Hello-World/issues/2/labels', body => {
parsedBody = body
return body
})
.reply(200)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/contents/.github/labels.yaml')
.reply(200, labelFileContents)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls/2/files')
.reply(200, prListTestFiles)

await handleCronJobs(context)
expect(parsedBody).toEqual({
const observeReq = new utils.observeRequest()
server.use(
rest.post(
`${utils.api}/repos/Codertocat/Hello-World/issues/2/labels`,
utils.mockResponse(200, null, observeReq)
),

rest.get(
`${utils.api}/repos/Codertocat/Hello-World/pulls/2/files`,
utils.mockResponse(200, prListTestFiles)
)
)

await expect(handleCronJobs(context)).resolves.not.toThrow()
expect(observeReq.body()).toEqual({
labels: ['tests']
})
expect(scope.isDone()).toBe(true)
})
})
136 changes: 59 additions & 77 deletions __tests__/cronJobTest/lgtm.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import nock from 'nock'
import {setupServer} from 'msw/node'
import {rest} from 'msw'

import {handleCronJobs} from '../../src/cronJobs/handleCronJob'
import * as utils from '../testUtils'

import pullReqOpenedEvent from '../fixtures/pullReq/pullReqOpenedEvent.json'
import listPullReqs from '../fixtures/pullReq/pullReqListPulls.json'

nock.disableNetConnect()

describe('cronLgtm', () => {
beforeEach(() => {
nock.cleanAll()
const server = setupServer(
// /repos/Codertocat/Hello-World/pulls?state=open&page={1,2}
rest.get(
`${utils.api}/repos/Codertocat/Hello-World/pulls`,
(req, res, ctx) => {
const page = req.url.searchParams.get('page')

if (page == '1') {
return res(ctx.status(200), ctx.json(listPullReqs))
} else {
return res(ctx.status(200), ctx.json([]))
}
}
)
)
beforeAll(() =>
server.listen({
onUnhandledRequest: 'warn'
})
)
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe('cronLgtm', () => {
it('merges the PR if the lgtm label is present', async () => {
utils.setupJobsEnv('lgtm')

Expand All @@ -22,27 +40,18 @@ describe('cronLgtm', () => {

listPullReqs[0].labels[0].name = 'lgtm'

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=1')
.reply(200, listPullReqs)
const observeReq = new utils.observeRequest()
server.use(
rest.put(
`${utils.api}/repos/Codertocat/Hello-World/pulls/2/merge`,
utils.mockResponse(200, null, observeReq)
)
)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=2')
.reply(200, [])

let parsedBody = undefined
nock(utils.api)
.put('/repos/Codertocat/Hello-World/pulls/2/merge', body => {
parsedBody = body
return body
})
.reply(200)

await handleCronJobs(context)
expect(parsedBody).toEqual({
await expect(handleCronJobs(context)).resolves.not.toThrow()
expect(observeReq.body()).toEqual({
merge_method: 'merge'
})
expect(nock.isDone()).toBe(true)
})

it('merges the PR with squash configured', async () => {
Expand All @@ -55,27 +64,18 @@ describe('cronLgtm', () => {

listPullReqs[0].labels[0].name = 'lgtm'

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=1')
.reply(200, listPullReqs)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=2')
.reply(200, [])
const observeReq = new utils.observeRequest()
server.use(
rest.put(
`${utils.api}/repos/Codertocat/Hello-World/pulls/2/merge`,
utils.mockResponse(200, null, observeReq)
)
)

let parsedBody = undefined
nock(utils.api)
.put('/repos/Codertocat/Hello-World/pulls/2/merge', body => {
parsedBody = body
return body
})
.reply(200)

await handleCronJobs(context)
expect(parsedBody).toEqual({
await expect(handleCronJobs(context)).resolves.not.toThrow()
expect(observeReq.body()).toEqual({
merge_method: 'squash'
})
expect(nock.isDone()).toBe(true)
})

it('merges the PR with rebase configured', async () => {
Expand All @@ -88,27 +88,18 @@ describe('cronLgtm', () => {

listPullReqs[0].labels[0].name = 'lgtm'

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=1')
.reply(200, listPullReqs)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=2')
.reply(200, [])

let parsedBody = undefined
nock(utils.api)
.put('/repos/Codertocat/Hello-World/pulls/2/merge', body => {
parsedBody = body
return body
})
.reply(200)
const observeReq = new utils.observeRequest()
server.use(
rest.put(
`${utils.api}/repos/Codertocat/Hello-World/pulls/2/merge`,
utils.mockResponse(200, null, observeReq)
)
)

await handleCronJobs(context)
expect(parsedBody).toEqual({
await expect(handleCronJobs(context)).resolves.not.toThrow()
expect(observeReq.body()).toEqual({
merge_method: 'rebase'
})
expect(nock.isDone()).toBe(true)
})

it('wont merge the PR if the hold label is present', async () => {
Expand All @@ -120,24 +111,15 @@ describe('cronLgtm', () => {

listPullReqs[0].labels[0].name = 'lgtm'
listPullReqs[0].labels.push({
"id": 1,
"node_id": "123",
"url": "https://api.github.com/repos/octocat/Hello-World/labels/hold",
"name": "hold",
"description": "looks good to me",
"color": "f29513",
"default": true
id: 1,
node_id: '123',
url: 'https://api.github.com/repos/octocat/Hello-World/labels/hold',
name: 'hold',
description: 'looks good to me',
color: 'f29513',
default: true
})

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=1')
.reply(200, listPullReqs)

nock(utils.api)
.get('/repos/Codertocat/Hello-World/pulls?state=open&page=2')
.reply(200, [])

await handleCronJobs(context)
expect(nock.isDone()).toBe(true)
await expect(handleCronJobs(context)).resolves.not.toThrow()
})
})
Loading
Loading