-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): bring back github & blog releases (#267)
- Loading branch information
Showing
16 changed files
with
389 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import messages from '../messages'; | ||
import { sendMessage } from '../telegram/bot-methods'; | ||
|
||
const { MAIN_GROUP_ID } = process.env; | ||
|
||
interface BlogFeed { | ||
actor: { | ||
displayName: string; | ||
}; | ||
permalinkUrl: string; | ||
title: string; | ||
} | ||
|
||
/** | ||
* TODO: for the ngVenezuela blog to work we have to wait until this is | ||
* closed: https://github.com/thepracticaldev/dev.to/issues/3363 | ||
*/ | ||
const handleBlogFeed = async (feeds: BlogFeed[]) => { | ||
if (MAIN_GROUP_ID) { | ||
const promises: Promise<void>[] = []; | ||
|
||
feeds.forEach(feed => { | ||
const promise = sendMessage({ | ||
chatId: Number(MAIN_GROUP_ID), | ||
text: messages.newBlogPost | ||
.replace('#{author}', feed.actor.displayName) | ||
.replace('#{link}', feed.permalinkUrl) | ||
.replace('#{title}', feed.title), | ||
}); | ||
|
||
promises.push(promise); | ||
}); | ||
|
||
await Promise.all(promises); | ||
} | ||
}; | ||
|
||
export default handleBlogFeed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,63 @@ | ||
/** | ||
* About feeds: | ||
* Superfeedr free plan only support up to 10 feeds | ||
* in the free tier: https://superfeedr.com/subscriber#pricing | ||
*/ | ||
|
||
const config = { | ||
whiteListedDomains: [ | ||
"https://github.com", | ||
"https://medium.com", | ||
"https://twitter.com" | ||
'https://github.com', | ||
'https://dev.to', | ||
'https://twitter.com', | ||
], | ||
githubFeeds: [ | ||
{ | ||
name: "angular", | ||
repo: "angular/angular", | ||
name: 'angular', | ||
hasChangelog: true, | ||
feed: 'https://github.com/angular/angular/releases.atom', | ||
}, | ||
{ | ||
name: 'ionic', | ||
hasChangelog: true, | ||
feed: "https://github.com/angular/angular/releases.atom" | ||
feed: 'https://github.com/driftyco/ionic/releases.atom', | ||
}, | ||
{ | ||
name: "ionic", | ||
repo: "driftyco/ionic", | ||
name: 'nativescript', | ||
hasChangelog: true, | ||
feed: "https://github.com/driftyco/ionic/releases.atom" | ||
feed: | ||
'https://github.com/NativeScript/NativeScript/releases.atom', | ||
}, | ||
{ | ||
name: "nativescript", | ||
repo: "NativeScript/NativeScript", | ||
name: 'wengy-ven', | ||
hasChangelog: true, | ||
feed: "https://github.com/NativeScript/NativeScript/releases.atom" | ||
feed: 'https://github.com/ngVenezuela/wengy-ven/releases.atom', | ||
}, | ||
{ | ||
name: "wengy-ven", | ||
repo: "ngVenezuela/wengy-ven", | ||
name: 'ngrx', | ||
hasChangelog: true, | ||
feed: "https://github.com/ngVenezuela/wengy-ven/releases.atom" | ||
} | ||
feed: 'https://github.com/ngrx/platform/releases.atom', | ||
}, | ||
{ | ||
name: 'TypeScript', | ||
hasChangelog: false, | ||
feed: 'https://github.com/Microsoft/TypeScript/releases.atom', | ||
}, | ||
{ | ||
name: 'nx', | ||
hasChangelog: false, | ||
feed: 'https://github.com/nrwl/nx/releases.atom', | ||
}, | ||
], | ||
blogFeeds: [ | ||
{ | ||
name: "Blog oficial de ngvenezuela", | ||
feed: "https://dev.to/feed/ngvenezuela" | ||
} | ||
] | ||
name: 'Blog oficial de ngvenezuela', | ||
feed: 'https://dev.to/feed/ngvenezuela', | ||
}, | ||
{ | ||
name: 'Angular blog', | ||
feed: 'https://blog.angular.io/feed', | ||
}, | ||
], | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import messages from '../messages'; | ||
import { sendMessage } from '../telegram/bot-methods'; | ||
|
||
const { MAIN_GROUP_ID } = process.env; | ||
|
||
interface RepoConfig { | ||
hasChangelog: boolean; | ||
name: string; | ||
feed: string; | ||
} | ||
|
||
const handleGithubFeed = async ( | ||
repoConfig: RepoConfig, | ||
tags: string[], | ||
) => { | ||
if (MAIN_GROUP_ID) { | ||
const promises: Promise<void>[] = []; | ||
|
||
tags.forEach(tag => { | ||
const promise = sendMessage({ | ||
chatId: Number(MAIN_GROUP_ID), | ||
text: messages.githubRelease | ||
.replace('#{name}', repoConfig.name) | ||
.replace('#{version}', tag) | ||
.replace( | ||
'#{url}', | ||
repoConfig.hasChangelog | ||
? `https://github.com/${repoConfig.name}/blob/master/CHANGELOG.md` | ||
: `https://github.com/${repoConfig.name}/releases/tag/${tag}`, | ||
), | ||
}); | ||
|
||
promises.push(promise); | ||
}); | ||
|
||
await Promise.all(promises); | ||
} | ||
}; | ||
|
||
export default handleGithubFeed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NowRequest } from '@vercel/node'; | ||
import { Buffer } from 'buffer'; | ||
|
||
const getRawBody = async (readable: NowRequest): Promise<Buffer> => { | ||
const chunks: any[] = []; | ||
let bytes = 0; | ||
|
||
return new Promise((resolve, reject) => { | ||
readable.on('error', reject); | ||
|
||
readable.on('data', chunk => { | ||
chunks.push(chunk); | ||
bytes += chunk.length; | ||
}); | ||
|
||
readable.on('end', () => { | ||
resolve(Buffer.concat(chunks, bytes)); | ||
}); | ||
}); | ||
}; | ||
|
||
export default getRawBody; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import { NowRequest, NowResponse } from '@vercel/node'; | ||
|
||
import messages from '../_utils/messages'; | ||
import { sendMessage } from '../_utils/telegram/bot-methods'; | ||
import isBasicAuthValid from '../_utils/basic-auth'; | ||
|
||
const { | ||
MAIN_GROUP_ID, | ||
SENTRY_DSN, | ||
NODE_ENV, | ||
PIPEDREAM_USERNAME, | ||
PIPEDREAM_PASSWORD, | ||
} = process.env; | ||
|
||
Sentry.init({ dsn: SENTRY_DSN }); | ||
|
||
// aparently when eslint is run, it always create a long func | ||
// eslint-disable-next-line max-len | ||
const generateRandomBetween = (min: number, max: number) => | ||
Math.floor(Math.random() * (max - min + 1)) + min; | ||
|
||
const getMorningMessage = () => { | ||
const { goodMornings } = messages; | ||
|
||
const now = new Date(); | ||
const weekday = now.getDay(); | ||
|
||
const weekDays: { [index: number]: string } = { | ||
0: 'generic', | ||
1: 'mondays', | ||
2: 'generic', | ||
3: 'generic', | ||
4: 'generic', | ||
5: 'fridays', | ||
6: 'generic', | ||
}; | ||
|
||
const randomIndex = generateRandomBetween( | ||
0, | ||
goodMornings[weekDays[weekday]].length - 1, | ||
); | ||
|
||
return goodMornings[weekDays[weekday]][randomIndex]; | ||
}; | ||
|
||
export default async (request: NowRequest, response: NowResponse) => { | ||
try { | ||
const matchingUsername = PIPEDREAM_USERNAME || ''; | ||
const matchingPassword = PIPEDREAM_PASSWORD || ''; | ||
const authorization = request.headers.authorization || ''; | ||
|
||
if ( | ||
isBasicAuthValid( | ||
authorization, | ||
matchingUsername, | ||
matchingPassword, | ||
) | ||
) { | ||
const text = getMorningMessage(); | ||
|
||
if (MAIN_GROUP_ID) { | ||
await sendMessage({ chatId: Number(MAIN_GROUP_ID), text }); | ||
} | ||
|
||
response.status(200).send('ok'); | ||
} else { | ||
response.status(401).send('Unauthorized'); | ||
} | ||
} catch (error) { | ||
if (NODE_ENV === 'development') { | ||
console.error(error); | ||
} else { | ||
Sentry.captureException(error); | ||
} | ||
|
||
response.status(400).send('not ok'); | ||
} | ||
}; |
Oops, something went wrong.