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

Update 20 Minutes ESLint config #427

Merged
merged 1 commit into from
Oct 1, 2021
Merged
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"root": true,
"extends": "20minutes"
"extends": "@20minutes"
}
4 changes: 2 additions & 2 deletions functions/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function checkExtension(event, context, callback) {
const body = JSON.parse(event.body)

// when creating the webhook
if (body && ('hook' in body)) {
if (body && 'hook' in body) {
try {
const message = validateWebhook(body)

Expand All @@ -32,7 +32,7 @@ export async function checkExtension(event, context, callback) {
return callback(null, response)
}

if (!(body && ('pull_request' in body))) {
if (!(body && 'pull_request' in body)) {
response = {
statusCode: 500,
body: 'Event is not a Pull Request',
Expand Down
7 changes: 2 additions & 5 deletions functions/utils/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function validateWebhook(body, requiredEvent = 'pull_request') {
throw new Error(`This webhook needs the "${requiredEvent}" event. Please tick it.`)
}

if (('organization' in body)) {
if ('organization' in body) {
return `Hello ${body.sender.login}, the webhook is now enabled for the organization ${body.organization.login}, enjoy!`
}

Expand All @@ -31,10 +31,7 @@ export async function updateStatus(githubClient, body, payload) {
try {
await githubClient
.repo(body.repository.full_name)
.statusAsync(
body.pull_request.head.sha,
payload,
)
.statusAsync(body.pull_request.head.sha, payload)

return {
statusCode: 204,
Expand Down
4 changes: 2 additions & 2 deletions functions/weblate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function weblate(event, context, callback) {
const body = JSON.parse(event.body)

// when creating the webhook
if (body && ('hook' in body)) {
if (body && 'hook' in body) {
let response

try {
Expand All @@ -31,7 +31,7 @@ export async function weblate(event, context, callback) {
return callback(null, response)
}

if (!(body && ('pull_request' in body))) {
if (!(body && 'pull_request' in body)) {
return callback(null, {
statusCode: 500,
body: 'Event is not a Pull Request',
Expand Down
5 changes: 1 addition & 4 deletions handler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { checkExtension } from './functions/extension'
import { weblate } from './functions/weblate'

export {
checkExtension,
weblate,
}
export { checkExtension, weblate }
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
"author": "wallabag <hello@wallabag.org>",
"license": "MIT",
"devDependencies": {
"@20minutes/eslint-config": "^1.2.1",
"@babel/core": "^7.15.5",
"@babel/eslint-parser": "^7.15.7",
"@babel/preset-env": "^7.15.6",
"babel-loader": "^8.2.2",
"babel-plugin-source-map-support": "^2.1.3",
"eslint": "^7.32.0",
"eslint-config-20minutes": "^1.1.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.26.1",
"jest": "^27.2.4",
"nock": "^13.1.3",
"prettier": "^2.4.1",
"regenerator-runtime": "^0.13.9",
"serverless-offline": "^8.2.0",
"serverless-webpack": "^5.5.1",
"serverless-webpack": "^5.5.4",
"webpack": "^5.55.1",
"webpack-node-externals": "^3.0.0"
},
Expand Down
35 changes: 12 additions & 23 deletions tests/extension.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ describe('Validating GitHub event', () => {
zen: 'Speak like a human.',
hook_id: 1,
hook: {
events: [
'issue',
'push',
],
events: ['issue', 'push'],
},
repository: {
full_name: '20minutes/serverless-github-check',
Expand All @@ -54,10 +51,7 @@ describe('Validating GitHub event', () => {
zen: 'Speak like a human.',
hook_id: 1,
hook: {
events: [
'pull_request',
'push',
],
events: ['pull_request', 'push'],
},
repository: {
full_name: '20minutes/serverless-github-check',
Expand All @@ -82,10 +76,7 @@ describe('Validating GitHub event', () => {
zen: 'Speak like a human.',
hook_id: 1,
hook: {
events: [
'pull_request',
'push',
],
events: ['pull_request', 'push'],
},
organization: {
login: '20minutes',
Expand All @@ -107,9 +98,7 @@ describe('Validating GitHub event', () => {

describe('Validating extension', () => {
test('fail to retrieve the diff', async () => {
nock('http://git.hub')
.get('/diff')
.reply(404)
nock('http://git.hub').get('/diff').reply(404)

const callback = jest.fn()
const githubEvent = {
Expand Down Expand Up @@ -150,9 +139,7 @@ describe('Validating extension', () => {
}),
})

nock('http://git.hub')
.get('/diff')
.replyWithFile(200, `${__dirname}/fixtures/no_txt.diff`)
nock('http://git.hub').get('/diff').replyWithFile(200, `${__dirname}/fixtures/no_txt.diff`)

const callback = jest.fn()
const githubEvent = {
Expand Down Expand Up @@ -230,7 +217,9 @@ describe('Validating extension', () => {
expect(commit).toBe('ee55a1223ce20c3e7cb776349cb7f8efb7b88511')
expect(payload.state).toBe('success')
expect(payload.context).toBe('Site config - File extension check')
expect(payload.description).toEqual(expect.not.stringContaining('has not a txt extension'))
expect(payload.description).toEqual(
expect.not.stringContaining('has not a txt extension')
)
}),
}
}),
Expand Down Expand Up @@ -273,15 +262,15 @@ describe('Validating extension', () => {
expect(commit).toBe('ee55a1223ce20c3e7cb776349cb7f8efb7b88511')
expect(payload.state).toBe('success')
expect(payload.context).toBe('Site config - File extension check')
expect(payload.description).toEqual(expect.not.stringContaining('has not a txt extension'))
expect(payload.description).toEqual(
expect.not.stringContaining('has not a txt extension')
)
}),
}
}),
})

nock('http://git.hub')
.get('/diff')
.replyWithFile(200, `${__dirname}/fixtures/with_a.txt.diff`)
nock('http://git.hub').get('/diff').replyWithFile(200, `${__dirname}/fixtures/with_a.txt.diff`)

const callback = jest.fn()
const githubEvent = {
Expand Down
15 changes: 3 additions & 12 deletions tests/weblate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ describe('Validating GitHub event', () => {
zen: 'Speak like a human.',
hook_id: 1,
hook: {
events: [
'issue',
'push',
],
events: ['issue', 'push'],
},
repository: {
full_name: '20minutes/serverless-github-check',
Expand All @@ -50,10 +47,7 @@ describe('Validating GitHub event', () => {
zen: 'Speak like a human.',
hook_id: 1,
hook: {
events: [
'pull_request',
'push',
],
events: ['pull_request', 'push'],
},
repository: {
full_name: '20minutes/serverless-github-check',
Expand All @@ -78,10 +72,7 @@ describe('Validating GitHub event', () => {
zen: 'Speak like a human.',
hook_id: 1,
hook: {
events: [
'pull_request',
'push',
],
events: ['pull_request', 'push'],
},
organization: {
login: '20minutes',
Expand Down
Loading