Skip to content

Commit b228db5

Browse files
committed
Style: Lint fixes
1 parent d4d0d2e commit b228db5

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

scripts/delete-hooks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fetch = require('node-fetch')
22
const { ghAuthHeaders, getPublicRepos } = require('../utils')
33

4-
async function main() {
4+
async function main () {
55
const hookUrl = 'https://git.mihir.ch/webhook/push'
66
const repos = await getPublicRepos()
77
let count = 0

setup.js renamed to scripts/setup.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
require('dotenv').config()
2-
const path = require('path')
32
const { mkdir } = require('fs/promises')
4-
const config = require('./config.json')
3+
const config = require('../config.json')
54
const {
65
getPublicRepos,
76
createMetaList,
87
cloneToPath,
98
updateDescription,
109
createWebhook
11-
} = require('./utils')
10+
} = require('../utils')
1211

13-
async function createRepositoriesPath() {
12+
async function createRepositoriesPath () {
1413
console.log('[INFO]', 'Creating repositories\' directory if it does not exist')
1514
await mkdir(config.repositoriesPath, { recursive: true })
1615
}
@@ -33,16 +32,16 @@ async function main () {
3332
.then(repos => repos.map(async repo => {
3433
const progress = () => `[${++progressCount}/${totalProgressRequired}]`
3534

36-
console.log(`[INFO] %s Cloning %s`, progress(), repo.name)
35+
console.log('[INFO] %s Cloning %s', progress(), repo.name)
3736
const localPath = await cloneToPath(repo)
3837

39-
console.log(`[INFO] %s Adding description for %s`, progress(), repo.name)
40-
await updateDescription(localPath, repo.description)
38+
console.log('[INFO] %s Adding description for %s', progress(), repo.name)
39+
await updateDescription(localPath, repo)
4140

42-
console.log(`[INFO] %s Creating webhook for %s`, progress(), repo.name)
43-
await createWebhook(repo.hookUrl)
41+
console.log('[INFO] %s Creating webhook for %s', progress(), repo.name)
42+
await createWebhook(repo)
4443

45-
console.log(`[INFO] %s Done %s`, progress(), repo.name)
44+
console.log('[INFO] %s Done %s', progress(), repo.name)
4645
}))
4746
.catch(err => {
4847
console.error('[ERR] An error occured:')

scripts/sync.js

Whitespace-only changes.

utils.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,64 @@ const ghAuthHeaders = {
1010
Authorization: `token ${process.env.GH_TOKEN}`
1111
}
1212

13-
function filterAndProcessRepos(repos) {
13+
function filterAndProcessRepos (repos) {
1414
return repos
1515
.filter(repo => !repo.fork)
16-
.map(({full_name, description, ssh_url, hooks_url}) => ({
17-
name: full_name,
16+
.map(({
1817
description,
19-
hookUrl: hooks_url,
20-
cloneUrl: ssh_url
21-
}))
18+
full_name: name,
19+
ssh_url: cloneUrl,
20+
hooks_url: hookUrl
21+
}) => ({ name, description, hookUrl, cloneUrl }))
2222
}
2323

24-
function getPublicRepoParams() {
24+
function getPublicRepoParams () {
2525
const searchParams = new URLSearchParams()
2626
for (const [key, value] of Object.entries(config.githubRepoListParams)) {
2727
searchParams.set(key, value)
2828
}
2929
return searchParams
3030
}
3131

32-
async function getPublicRepos() {
32+
async function getPublicRepos () {
3333
const searchParams = getPublicRepoParams()
3434
const response = await fetch(`${GH_API_BASE}/user/repos?${searchParams}`, { headers: ghAuthHeaders })
3535
const json = await response.json()
3636
return filterAndProcessRepos(json)
3737
}
3838

39-
async function createMetaList(repos) {
39+
async function createMetaList (repos) {
4040
console.log('[INFO]', 'Creating list of cloned directories')
4141
const list = JSON.stringify(repos.map(repo => repo.name))
4242
const filePath = path.join(config.repositoriesPath, 'repositories.json')
4343
await writeFile(filePath, list, 'utf-8')
4444
return repos
4545
}
4646

47-
async function cloneToPath(repo, log = false) {
48-
if (log) console.log(`[INFO] Cloning %s`, repo.name)
47+
async function cloneToPath (repo, log = false) {
48+
if (log) console.log('[INFO] Cloning %s', repo.name)
4949
const remotePath = repo.cloneUrl
5050
const localPath = path.join(config.repositoriesPath, repo.name)
5151
await git.clone(remotePath, localPath)
5252
return localPath
5353
}
5454

55-
async function updateDescription(localPath, description, log = false) {
56-
if (log) console.log(`[INFO] Adding description for %s`, repo.name)
55+
async function updateDescription (localPath, repo, log = false) {
56+
if (log) console.log('[INFO] Adding description for %s', repo.name)
5757
const descriptionFilePath = path.join(localPath, '.git', 'description')
58-
await writeFile(descriptionFilePath, description || '', 'utf-8')
58+
await writeFile(descriptionFilePath, repo.description || '', 'utf-8')
5959
}
6060

61-
async function createWebhook(webhookUrl, log = false) {
62-
if (log) console.log(`[INFO] Creating webhook for %s`, repo.name)
61+
async function createWebhook (repo, log = false) {
62+
if (log) console.log('[INFO] Creating webhook for %s', repo.name)
6363
const requestBody = {
6464
config: {
6565
url: config.webhookBase + '/push',
6666
content_type: 'json',
6767
secret: process.env.WEBHOOK_SECRET
6868
}
6969
}
70-
await fetch(webhookUrl, {
70+
await fetch(repo.hookUrl, {
7171
method: 'POST',
7272
headers: {
7373
'Content-Type': 'application/json',

webhook-server.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function createComparisonSignature (body = '') {
1111
return `sha1=${signature}`
1212
}
1313

14-
function compareSignatures (receivedSignature = '', selfSignature) {
14+
function compareSignatures (selfSignature, receivedSignature = '') {
1515
const source = Buffer.from(receivedSignature)
1616
const comparison = Buffer.from(selfSignature)
1717
return receivedSignature.length === selfSignature.length &&
@@ -22,13 +22,13 @@ function verifyPayload (req, res, next) {
2222
const { headers, body } = req
2323
const receivedSignature = headers['x-hub-signature']
2424
const selfSignature = createComparisonSignature(body)
25-
if (!compareSignatures(receivedSignature, selfSignature)) {
25+
if (!compareSignatures(selfSignature, receivedSignature)) {
2626
return res.writeHead(401).end('Signature mismatch!')
2727
}
2828
next()
2929
}
3030

31-
async function pull(repo) {
31+
async function pull (repo) {
3232
const localPath = `${config.repositoriesPath}/${repo}`
3333
await git.cwd(localPath).pull('origin', 'master')
3434
}

0 commit comments

Comments
 (0)