Przeglądaj źródła

Merge branch 'feat/growi-bot' into feat/create-modal-after-typing-growi-register

zahmis 5 lat temu
rodzic
commit
52eb5db628

+ 1 - 0
.github/workflows/ci-slackbot-proxy.yml

@@ -7,6 +7,7 @@ on:
       - tmp/**
       - tmp/**
     paths:
     paths:
       - .github/workflows/ci-slackbot-proxy.yml
       - .github/workflows/ci-slackbot-proxy.yml
+      - packages/slack/*
       - packages/slackbot-proxy/*
       - packages/slackbot-proxy/*
       - package.json
       - package.json
       - yarn.lock
       - yarn.lock

+ 1 - 1
packages/slack/.eslintignore

@@ -1,2 +1,2 @@
-/dist/**
+/lib/**
 /node_modules/**
 /node_modules/**

+ 1 - 1
packages/slack/.gitignore

@@ -1 +1 @@
-/dist/
+/lib/

+ 2 - 2
packages/slack/package.json

@@ -2,8 +2,8 @@
   "name": "@growi/slack",
   "name": "@growi/slack",
   "version": "0.9.0-RC",
   "version": "0.9.0-RC",
   "license": "MIT",
   "license": "MIT",
-  "main": "dist/index.js",
-  "files": ["dist"],
+  "main": "lib/index.js",
+  "files": ["lib"],
   "scripts": {
   "scripts": {
     "build": "yarn tsc",
     "build": "yarn tsc",
     "tsc": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
     "tsc": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",

+ 1 - 1
packages/slack/tsconfig.build.json

@@ -1,7 +1,7 @@
 {
 {
   "extends": "./tsconfig.json",
   "extends": "./tsconfig.json",
   "compilerOptions": {
   "compilerOptions": {
-    "outDir": "dist",
+    "outDir": "lib",
     "declaration": true,
     "declaration": true,
     "noResolve": false,
     "noResolve": false,
     "preserveConstEnums": true,
     "preserveConstEnums": true,

+ 3 - 3
packages/slack/tsconfig.json

@@ -20,10 +20,10 @@
 
 
     /* Module Resolution Options */
     /* Module Resolution Options */
     "moduleResolution": "node",
     "moduleResolution": "node",
-    "baseUrl": ".",
+    "baseUrl": "src",
     "paths": {
     "paths": {
-      "~/*": ["src/*"],
-      "^/*": ["./*"],
+      "~/*": ["./*"],
+      "^/*": ["../*"],
     },
     },
     "typeRoots": [
     "typeRoots": [
       "../../node_modules/@types",
       "../../node_modules/@types",

+ 46 - 20
packages/slackbot-proxy/src/controllers/slack.ts

@@ -3,7 +3,10 @@ import {
 } from '@tsed/common';
 } from '@tsed/common';
 import { parse } from '@growi/slack/src/utils/slash-command-parser';
 import { parse } from '@growi/slack/src/utils/slash-command-parser';
 import { Installation } from '~/entities/installation';
 import { Installation } from '~/entities/installation';
+import { Order } from '~/entities/order';
+
 import { InstallationRepository } from '~/repositories/installation';
 import { InstallationRepository } from '~/repositories/installation';
+import { OrderRepository } from '~/repositories/order';
 import { InstallerService } from '~/services/InstallerService';
 import { InstallerService } from '~/services/InstallerService';
 import { RegisterService } from '~/services/RegisterService';
 import { RegisterService } from '~/services/RegisterService';
 
 
@@ -18,30 +21,32 @@ export class SlackCtrl {
   installationRepository: InstallationRepository;
   installationRepository: InstallationRepository;
 
 
   @Inject()
   @Inject()
-  registerService: RegisterService
+  orderRepository: OrderRepository;
 
 
+  @Inject()
+  registerService: RegisterService;
 
 
-   growiCommandsMappings = {
-     register: async(body:{[key:string]:string}):Promise<void> => this.registerService.execSlashCommand(body),
-   };
+  growiCommandsMappings = {
+    register: async(body:{[key:string]:string}):Promise<void> => this.registerService.execSlashCommand(body),
+  };
 
 
   @Get('/testsave')
   @Get('/testsave')
-   testsave(): void {
-     const installation = new Installation();
-     installation.data = {
-       team: undefined,
-       enterprise: undefined,
-       user: {
-         id: '',
-         token: undefined,
-         scopes: undefined,
-       },
-     };
-
-     // const installationRepository = getRepository(Installation);
-
-     this.installationRepository.save(installation);
-   }
+  testsave(): void {
+    const installation = new Installation();
+    installation.data = {
+      team: undefined,
+      enterprise: undefined,
+      user: {
+        id: '',
+        token: undefined,
+        scopes: undefined,
+      },
+    };
+
+    // const installationRepository = getRepository(Installation);
+
+    this.installationRepository.save(installation);
+  }
 
 
 
 
   @Get('/install')
   @Get('/install')
@@ -74,6 +79,27 @@ export class SlackCtrl {
     await executeGrowiCommand(body);
     await executeGrowiCommand(body);
     res.send();
     res.send();
 
 
+    const installation = await this.installationRepository.findByID('1');
+    if (installation == null) {
+      throw new Error('installation is reqiured');
+    }
+
+    // Find the latest order by installationId
+    let order = await this.orderRepository.findOne({
+      installation: installation.id,
+    }, {
+      order: {
+        createdAt: 'DESC',
+      },
+    });
+
+    if (order == null || order.isExpired()) {
+      order = await this.orderRepository.save({ installation: installation.id });
+    }
+
+    console.log('body', body);
+    console.log('order', order);
+
     return 'This action will be handled by bolt service.';
     return 'This action will be handled by bolt service.';
   }
   }
 
 

+ 2 - 1
packages/slackbot-proxy/src/entities/installation.ts

@@ -2,10 +2,11 @@ import {
   Required,
   Required,
 } from '@tsed/schema';
 } from '@tsed/schema';
 import {
 import {
-  Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn,
+  Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn, OneToMany,
 } from 'typeorm';
 } from 'typeorm';
 
 
 import { Installation as SlackInstallation } from '@slack/oauth';
 import { Installation as SlackInstallation } from '@slack/oauth';
+import { Order } from './order';
 
 
 @Entity()
 @Entity()
 export class Installation {
 export class Installation {

+ 38 - 0
packages/slackbot-proxy/src/entities/order.ts

@@ -0,0 +1,38 @@
+import {
+  Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn, ManyToOne,
+} from 'typeorm';
+import { Installation } from './installation';
+
+@Entity()
+export class Order {
+
+  @PrimaryGeneratedColumn()
+  readonly id: number;
+
+  @CreateDateColumn()
+  readonly createdAt: Date;
+
+  @UpdateDateColumn()
+  readonly updatedAt: Date;
+
+  @ManyToOne(() => Installation)
+  readonly installation: number;
+
+  @Column({ nullable: true, default: false })
+  isCompleted?: boolean;
+
+  @Column({ nullable: true })
+  growiUrl?: string;
+
+  @Column({ nullable: true })
+  growiAccessToken?: string;
+
+  @Column({ nullable: true })
+  proxyAccessToken?: string;
+
+  isExpired():boolean {
+    // TODO GW-5555 implement this
+    return false;
+  }
+
+}

+ 10 - 0
packages/slackbot-proxy/src/repositories/order.ts

@@ -0,0 +1,10 @@
+import {
+  Repository, EntityRepository,
+} from 'typeorm';
+
+import { Order } from '~/entities/order';
+
+@EntityRepository(Order)
+export class OrderRepository extends Repository<Order> {
+
+}

+ 6 - 6
packages/slackbot-proxy/src/services/RecieveService.ts

@@ -1,15 +1,15 @@
 import { Service } from '@tsed/di';
 import { Service } from '@tsed/di';
-// import { parse } from '@growi/slack/src/utils/slash-command-parser';
+import { parse } from '@growi/slack/lib/utils/slash-command-parser';
 
 
 @Service()
 @Service()
 export class ReceiveService {
 export class ReceiveService {
 
 
   receiveContentsFromSlack(body:{[key:string]:string}) : string {
   receiveContentsFromSlack(body:{[key:string]:string}) : string {
-    // const parseBody = parse(body);
-    // if (parseBody.growiCommandType === 'register') {
-    //   console.log('register action occured');
-    //   return 'register action occurd';
-    // }
+    const parseBody = parse(body);
+    if (parseBody.growiCommandType === 'register') {
+      console.log('register action occured');
+      return 'register action occurd';
+    }
     return 'return receiveContentsFromSlack';
     return 'return receiveContentsFromSlack';
   }
   }