Replace AWS Lambda adapter with custom function

This commit is contained in:
Maciej Pędzich 2023-07-06 13:08:59 +02:00
parent 22b75f6c3f
commit 123f2b78ee
6 changed files with 54 additions and 20 deletions

View File

@ -1,11 +1,11 @@
import { ApplicationFunction } from 'probot';
import getMetaData from 'metadata-scraper';
import { getPlaylistIdFromUrl } from './getPlaylistIdFromUrl';
import { Probot } from 'probot';
type ReviewEvent = 'REQUEST_CHANGES' | 'COMMENT' | 'APPROVE';
export const appFn: ApplicationFunction = (app) => {
export const appFn = (app: Probot) => {
app.on(
['pull_request.opened', 'pull_request.synchronize'],
async ({ payload, octokit }) => {

View File

@ -0,0 +1,22 @@
import type { Handler, HandlerEvent, HandlerContext } from '@netlify/functions';
import { createProbot } from 'probot';
import { appFn } from '../../appFn';
const privateKey = (process.env.PRIVATE_KEY as string).replace(/\\n/gm, '\n');
const handler: Handler = async (
event: HandlerEvent,
context: HandlerContext
) => {
const probot = createProbot({ overrides: { privateKey } });
await appFn(probot);
return {
statusCode: 200,
body: 'Playlist Entry Validator by Maciej Pędzich'
};
};
export { handler };

View File

@ -1,14 +0,0 @@
import {
createLambdaFunction,
createProbot
} from '@probot/adapter-aws-lambda-serverless';
import { appFn } from '../../../appFn';
const privateKey = (process.env.PRIVATE_KEY as string).replace(/\\n/gm, '\n');
const handler = createLambdaFunction(appFn, {
probot: createProbot({ overrides: { privateKey } })
});
export { handler };

View File

@ -1,4 +0,0 @@
{
"name": "dummy-package-json",
"version": "1.0.0"
}

29
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"@netlify/functions": "github:netlify/functions",
"@probot/adapter-aws-lambda-serverless": "^3.0.3",
"metadata-scraper": "^0.2.60",
"probot": "^12.2.8"
@ -64,6 +65,17 @@
"@jridgewell/sourcemap-codec": "^1.4.10"
}
},
"node_modules/@netlify/functions": {
"version": "1.6.0",
"resolved": "git+ssh://git@github.com/netlify/functions.git#3e1d890892fb6f1975ffaf92a78de68253432602",
"license": "MIT",
"dependencies": {
"is-promise": "^4.0.0"
},
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/@octokit/auth-app": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-4.0.5.tgz",
@ -2286,6 +2298,11 @@
"node": ">=0.10.0"
}
},
"node_modules/is-promise": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="
},
"node_modules/jmespath": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz",
@ -3828,6 +3845,13 @@
"@jridgewell/sourcemap-codec": "^1.4.10"
}
},
"@netlify/functions": {
"version": "git+ssh://git@github.com/netlify/functions.git#3e1d890892fb6f1975ffaf92a78de68253432602",
"from": "@netlify/functions@github:netlify/functions",
"requires": {
"is-promise": "^4.0.0"
}
},
"@octokit/auth-app": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-4.0.5.tgz",
@ -5674,6 +5698,11 @@
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
"integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q=="
},
"is-promise": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="
},
"jmespath": {
"version": "0.15.0",
"resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz",

View File

@ -17,6 +17,7 @@
},
"homepage": "https://github.com/maciejpedzich/mackorone-playlist-pr-bot#readme",
"dependencies": {
"@netlify/functions": "github:netlify/functions",
"@probot/adapter-aws-lambda-serverless": "^3.0.3",
"metadata-scraper": "^0.2.60",
"probot": "^12.2.8"