Skip to content

Commit

Permalink
feat: support checkName if exist same name bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Leizhenpeng committed Jan 15, 2024
1 parent ca7ab16 commit a412c55
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
3 changes: 1 addition & 2 deletions botops.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "botops demo",
"desc": "test demo description",
"desc": "some description",
"avatar": "https://avatars.githubusercontent.com/u/145313435?s=200&v=4",
"platform": "feishu",
"feishuConfig": {
"appId": "cli_a52fa4f22d",
"events": [
"im.message.message_read_v1",
"im.message.receive_v1"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@inquirer/confirm": "^2.0.15",
"@inquirer/select": "^1.3.1",
"ajv": "^8.12.0",
"botops-feishu": "^0.0.3",
"botops-feishu": "^0.0.4",
"clipboardy": "^4.0.0",
"conf": "^12.0.0",
"fast-glob": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/feishuapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "botops-feishu",
"type": "module",
"version": "0.0.3",
"version": "0.0.4",
"packageManager": "[email protected]",
"description": "botops feishu auto deploy module",
"author": "River <[email protected]>",
Expand Down
9 changes: 9 additions & 0 deletions packages/feishuapi/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ export class OpenApp {
async getEventInfo(appId: string) {
return this.eventManager.getEventInfo(appId)
}

// 检测有没有同名的机器人,如果有返回appId
async checkAppName(aBot: string) {
const appList = await this.getAppList()
const bot = appList.find(app => app.name === aBot)
if (bot)
return bot.appID
return ''
}
}

class BotManager {
Expand Down
7 changes: 7 additions & 0 deletions packages/feishuapi/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ describe('app', async () => {
console.log(JSON.stringify(result))
expect(result).not.toBeUndefined()
})

// 检测有没有同名的机器人,如果有返回appId
it('should check app name', async () => {
const result = await app.checkAppName('a 222')
console.log(JSON.stringify(result))
expect(result).not.toBeUndefined()
})
})

describe('scoop', async () => {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Argv } from 'yargs'
import clipboard from 'clipboardy'
import Listr from 'listr'
import ora from 'ora'
import confirm from '@inquirer/confirm'
import { changeArgvToString, greenIt, redIt } from './utils'
import { DeployConfig } from './manifest'
import { FeishuConfigManager } from './config'
Expand Down Expand Up @@ -52,9 +53,19 @@ export async function handler(argv: any) {
await appBuilder.init()

let appId = ''

if (aDeployConfig.ifFirstDeploy) {
// 检测是否有重名的机器人
const oldAppId = await appBuilder.checkAppName(aDeployConfig.botName)
if (oldAppId) {
const answer = await confirm({ message: 'Detected a bot with the same name, do you want to overwrite it?' })
if (answer) {
greenIt(`即将覆盖飞书机器人 ${aDeployConfig.botName}(${oldAppId})`)
appId = oldAppId
}
}
appId = await appBuilder.newApp(aDeployConfig.botBaseInfo)
greenIt(`飞书机器人 ${aDeployConfig.botName}(${appId}) 初始化成功`)
greenIt(`新的飞书机器人 ${aDeployConfig.botName}(${appId}) 初始化成功`)
}
else {
appId = aDeployConfig.appId as string
Expand Down

0 comments on commit a412c55

Please sign in to comment.