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

Bump handlebars from 4.0.11 to 4.5.3 #41

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 7 additions & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"devDependencies": {
"dotenv-webpack": "^1.7.0",
"netlify-lambda": "^1.4.5"
}
}
50 changes: 50 additions & 0 deletions functions/src/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { camelizeKeys, decamelizeKeys } = require('humps')
const fetch = require('./helpers/fetch')

const MEETUP_EVENTS_API =
'https://api.meetup.com/hannoverjs/events?page=3&status=upcoming'

exports.handler = async (_event, _context, callback) => {
const meetupEvents = await fetch(MEETUP_EVENTS_API, {
Authorization: `Bearer ${process.env.MEETUP_TOKEN}`
})

const events = meetupEvents.map(event => {
const {
time,
updated,
venue: {
name,
lat,
lon,
address_1: street,
city,
country,
localizedCountryName
},
link: meetupUrl,
howToFindUs
} = camelizeKeys(event)

return decamelizeKeys({
date: new Date(time),
updatedAt: new Date(updated),
meetupUrl,
venue: {
name,
lat,
lon,
street,
city,
country,
localizedCountryName,
howToFindUs
}
})
})

callback(null, {
statusCode: 200,
body: JSON.stringify(events)
})
}
20 changes: 20 additions & 0 deletions functions/src/helpers/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const got = require('got')

const USER_AGENT = 'https://github.com/hannoverjs/hannoverjs-api'

async function fetch(url, opts) {
const gotOpts = Object.assign({ json: true }, opts)

gotOpts.headers = Object.assign(
{
'User-Agent': USER_AGENT
},
gotOpts.headers
)

const { body } = await got(url, gotOpts)

return body
}

module.exports = fetch
29 changes: 29 additions & 0 deletions functions/src/helpers/twitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fetch = require('./fetch')

const TWITTER_API_BASE_URL = 'https://api.twitter.com'

async function twitter(endpoint) {
const { access_token } = JSON.parse(
await fetch(`${TWITTER_API_BASE_URL}/oauth2/token`, {
method: 'POST',
headers: {
Authorization: `Basic ${Buffer.from(
`${process.env.TWITTER_CONSUMER_KEY}:${
process.env.TWITTER_CONSUMER_SECRET
}`
).toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: 'grant_type=client_credentials',
json: false
})
)

return fetch(`${TWITTER_API_BASE_URL}/1.1/${endpoint}`, {
headers: {
Authorization: `Bearer ${access_token}`
}
})
}

module.exports = twitter
43 changes: 43 additions & 0 deletions functions/src/organizers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const twitter = require('./helpers/twitter')

async function getOrganizers(twitterUsernames) {
const organizers = await twitter(
`users/lookup.json?screen_name=${twitterUsernames.join(',')}`
)

/* eslint-disable camelcase */
return organizers.map(
({
name,
description,
profile_image_url,
profile_image_url_https,
screen_name
}) => ({
name,
description,
twitter: {
profile_image_url: profile_image_url.replace('_normal', ''),
profile_image_url_https: profile_image_url_https.replace('_normal', ''),
screen_name
}
})
/* eslint-enable camelcase */
)
}

exports.handler = async (_event, _context, callback) => {
const organizers = await getOrganizers([
'cburgdorf',
'PascalPrecht',
'JanPantel',
'RobinThrift',
'timche_',
'maxrimue'
])

callback(null, {
statusCode: 200,
body: JSON.stringify(organizers)
})
}
97 changes: 97 additions & 0 deletions functions/src/talks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
const { camelizeKeys, decamelizeKeys } = require('humps')
const fetch = require('./helpers/fetch')

const GITHUB_ISSUES_API =
'https://api.github.com/repos/HannoverJS/talks/issues?state=open&labels=Upcoming%20Talk'

const talkRegExp = /^#{5} (.+)(?:\s+#{6} (.+))?(?:\s+#{6} \[(.+)]\((.+)\))?\s+([\s\S]+)\s*$/

function extractTalk(body) {
const talk = body.match(talkRegExp)

if (!talk) {
return null
}

const [
name = null,
occupation = null,
socialName = null,
socialUrl = null,
description = null
] = talk

return {
name,
occupation,
socialName,
socialUrl,
description
}
}

exports.handler = async (_event, _context, callback) => {
const issues = await fetch(GITHUB_ISSUES_API)

const talks = camelizeKeys(issues)
.filter(
({ milestone }) =>
Boolean(milestone) &&
new Date(milestone.dueOn).valueOf() > new Date().valueOf()
)
.reduce(
(
acc,
{
title,
body,
user: { avatarUrl },
milestone: { dueOn },
updatedAt,
labels
}
) => {
const date = new Date(dueOn)
date.setDate(date.getDate() - 1)
date.setHours(19)

const talk = extractTalk(body)

if (!talk) {
return acc
}

const { name, occupation, socialName, socialUrl, description } = talk

const lightningTalkLabelName = 'Lightning Talk'
const isLightningTalk = labels.some(
label => label.name === lightningTalkLabelName
)

return [
...acc,
decamelizeKeys({
title,
description,
date,
updatedAt,
isLightningTalk,
labels: labels.filter(obj => obj.name !== lightningTalkLabelName),
speaker: {
name,
avatarUrl,
occupation,
socialName,
socialUrl
}
})
]
},
[]
)

callback(null, {
statusCode: 200,
body: JSON.stringify(talks)
})
}
10 changes: 10 additions & 0 deletions functions/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Dotenv = require('dotenv-webpack')

// `react-scripts` installs `webpack` v3 on root of `node_modules
// and `netlify-lambda` installs `webpack` v4 in it's own folder.
// `dotenv-webpack` needs to require `webpack` v4, so `netlify-lambda`
// can use this config, but since v3 is installed on root, it doesn't work,
// so this is a little workaround to ensure it's using v4.
module.exports = {
plugins: [new Dotenv()]
}
Loading