diff --git a/apps/github-app/api/index.js b/apps/github-app/api/index.js new file mode 100644 index 00000000..fd60a3b6 --- /dev/null +++ b/apps/github-app/api/index.js @@ -0,0 +1,11 @@ +const app = require('express')(); +const { v4 } = require('uuid'); +const { createProbot } = require('probot'); +const { appFn, buildRouter } = require('../src/app'); + +const probot = createProbot(); +probot.load(appFn, { + getRouter: (path) => app, +}); + +module.exports = app; diff --git a/apps/github-app/package.json b/apps/github-app/package.json index 59756fe3..bbc75fe2 100644 --- a/apps/github-app/package.json +++ b/apps/github-app/package.json @@ -21,6 +21,7 @@ "axios": "^0.21.1", "body-parser": "^1.20.1", "dotenv": "^16.0.3", + "express": "^4.18.2", "lodash": "^4.17.21", "probot": "^12.3.0", "probot-metadata": "^2.1.0" diff --git a/apps/github-app/src/app.ts b/apps/github-app/src/app.ts index 81ad9bfe..e792072f 100644 --- a/apps/github-app/src/app.ts +++ b/apps/github-app/src/app.ts @@ -207,14 +207,17 @@ function createTailchatClient(tailchatHost = defaultTailchatApiUrl) { return tailchatClient; } -function buildRouter( +export function buildRouter( app: Probot, getRouter: Parameters[1]['getRouter'] ) { if (getRouter) { getRouter('/') - .get('/', (_req, res) => { - res.send('Hello World! Github app server is working!'); + .get('/api', (_req, res) => { + res.send('Hello World! Github app api server is working!'); + }) + .get('/api/message/webhook', (_req, res) => { + res.send('Please use POST method'); }) .post('/message/webhook', bodyParser.json(), (req, res) => { (async () => { diff --git a/apps/github-app/vercel.json b/apps/github-app/vercel.json new file mode 100644 index 00000000..86eef076 --- /dev/null +++ b/apps/github-app/vercel.json @@ -0,0 +1,6 @@ +{ + "rewrites": [ + { "source": "/api/(.*)", "destination": "/api" }, + { "source": "/api/github/webhooks", "destination": "/api/github/webhooks" } + ] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a9c5f6b2..fce8d5f1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -154,6 +154,7 @@ importers: axios: ^0.21.1 body-parser: ^1.20.1 dotenv: ^16.0.3 + express: ^4.18.2 jest: 27.5.1 lodash: ^4.17.21 nock: ^13.0.5 @@ -163,11 +164,12 @@ importers: smee-client: ^1.2.2 ts-jest: 27.1.4 ts-node: ^10.9.1 - typescript: ^4.1.3 + typescript: ^4.8.2 dependencies: axios: 0.21.4 body-parser: 1.20.1 dotenv: 16.0.3 + express: 4.18.2 lodash: 4.17.21 probot: 12.3.0 probot-metadata: 2.1.0_probot@12.3.0 @@ -180,9 +182,9 @@ importers: nock: 13.2.9 nodemon: 2.0.20 smee-client: 1.2.3 - ts-jest: 27.1.4_ycpvkzuynwz3ym5w5cufqamazq - ts-node: 10.9.1_k2dsl7zculo2nmh5s33pladmoa - typescript: 4.8.2 + ts-jest: 27.1.4_n4jzo3ixy42kfaqevs43wjx5ui + ts-node: 10.9.1_4hee3ckhxcse3era5mxqjwg7u4 + typescript: 4.9.5 apps/widget: specifiers: @@ -5547,10 +5549,10 @@ packages: '@types/node': 18.11.18 chalk: 4.1.2 cosmiconfig: 7.1.0 - cosmiconfig-typescript-loader: 2.0.2_awa2wsr5thmg3i7jqycphctjfq + cosmiconfig-typescript-loader: 2.0.2_bdgp3l2zgaopogaavxusmetvge lodash: 4.17.21 resolve-from: 5.0.0 - typescript: 4.9.4 + typescript: 4.9.5 transitivePeerDependencies: - '@swc/core' - '@swc/wasm' @@ -12883,7 +12885,7 @@ packages: resolution: {integrity: sha512-YSLRnAS62iP/vcjHTMbsYtW9RJ7LIMVgp3SwTa8/fV4sE8hjCYQee5LPI4JFbx2oIF5Mw9E1ekkWJu9pHCccrA==} dependencies: '@types/bluebird': 3.5.38 - typescript: 4.9.4 + typescript: 4.9.5 dev: true /@types/ejs/3.1.1: @@ -17826,7 +17828,7 @@ packages: vary: 1.1.2 dev: false - /cosmiconfig-typescript-loader/2.0.2_awa2wsr5thmg3i7jqycphctjfq: + /cosmiconfig-typescript-loader/2.0.2_bdgp3l2zgaopogaavxusmetvge: resolution: {integrity: sha512-KmE+bMjWMXJbkWCeY4FJX/npHuZPNr9XF9q9CIQ/bpFwi1qHfCmSiKarrCcRa0LO4fWjk93pVoeRtJAkTGcYNw==} engines: {node: '>=12', npm: '>=6'} peerDependencies: @@ -17835,8 +17837,8 @@ packages: dependencies: '@types/node': 18.11.18 cosmiconfig: 7.1.0 - ts-node: 10.9.1_awa2wsr5thmg3i7jqycphctjfq - typescript: 4.9.4 + ts-node: 10.9.1_bdgp3l2zgaopogaavxusmetvge + typescript: 4.9.5 transitivePeerDependencies: - '@swc/core' - '@swc/wasm' @@ -24381,7 +24383,7 @@ packages: pretty-format: 27.5.1 slash: 3.0.0 strip-json-comments: 3.1.1 - ts-node: 10.9.1_k2dsl7zculo2nmh5s33pladmoa + ts-node: 10.9.1_4hee3ckhxcse3era5mxqjwg7u4 transitivePeerDependencies: - bufferutil - canvas @@ -36822,7 +36824,7 @@ packages: yargs-parser: 20.2.9 dev: true - /ts-jest/27.1.4_r5n7iohbfbguzk5ispbdybm75m: + /ts-jest/27.1.4_n4jzo3ixy42kfaqevs43wjx5ui: resolution: {integrity: sha512-qjkZlVPWVctAezwsOD1OPzbZ+k7zA5z3oxII4dGdZo5ggX/PL7kvwTM0pXTr10fAtbiVpJaL3bWd502zAhpgSQ==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} hasBin: true @@ -36843,7 +36845,7 @@ packages: esbuild: optional: true dependencies: - '@types/jest': 26.0.24 + '@types/jest': 27.5.2 bs-logger: 0.2.6 fast-json-stable-stringify: 2.1.0 jest: 27.5.1_ts-node@10.9.1 @@ -36852,11 +36854,11 @@ packages: lodash.memoize: 4.1.2 make-error: 1.3.6 semver: 7.3.7 - typescript: 4.7.4 + typescript: 4.9.5 yargs-parser: 20.2.9 dev: true - /ts-jest/27.1.4_ycpvkzuynwz3ym5w5cufqamazq: + /ts-jest/27.1.4_r5n7iohbfbguzk5ispbdybm75m: resolution: {integrity: sha512-qjkZlVPWVctAezwsOD1OPzbZ+k7zA5z3oxII4dGdZo5ggX/PL7kvwTM0pXTr10fAtbiVpJaL3bWd502zAhpgSQ==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} hasBin: true @@ -36877,7 +36879,7 @@ packages: esbuild: optional: true dependencies: - '@types/jest': 27.5.2 + '@types/jest': 26.0.24 bs-logger: 0.2.6 fast-json-stable-stringify: 2.1.0 jest: 27.5.1_ts-node@10.9.1 @@ -36886,7 +36888,7 @@ packages: lodash.memoize: 4.1.2 make-error: 1.3.6 semver: 7.3.7 - typescript: 4.8.2 + typescript: 4.7.4 yargs-parser: 20.2.9 dev: true @@ -36903,6 +36905,37 @@ packages: tweetnacl: 1.0.3 dev: true + /ts-node/10.9.1_4hee3ckhxcse3era5mxqjwg7u4: + resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} + hasBin: true + peerDependencies: + '@swc/core': '>=1.2.50' + '@swc/wasm': '>=1.2.50' + '@types/node': '*' + typescript: '>=2.7' + peerDependenciesMeta: + '@swc/core': + optional: true + '@swc/wasm': + optional: true + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.9 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.3 + '@types/node': 18.7.11 + acorn: 8.8.1 + acorn-walk: 8.2.0 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 4.9.5 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + dev: true + /ts-node/10.9.1_awa2wsr5thmg3i7jqycphctjfq: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true @@ -36932,8 +36965,9 @@ packages: typescript: 4.9.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + dev: false - /ts-node/10.9.1_k2dsl7zculo2nmh5s33pladmoa: + /ts-node/10.9.1_bdgp3l2zgaopogaavxusmetvge: resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -36952,14 +36986,14 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.3 - '@types/node': 18.7.11 + '@types/node': 18.11.18 acorn: 8.8.1 acorn-walk: 8.2.0 arg: 4.1.3 create-require: 1.1.1 diff: 4.0.2 make-error: 1.3.6 - typescript: 4.8.2 + typescript: 4.9.5 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 dev: true