Skip to content

Commit

Permalink
refactor(botonic-cli): getBots returns all bots using internally the …
Browse files Browse the repository at this point in the history
…getMoreBots function
  • Loading branch information
Iru89 committed Aug 26, 2024
1 parent b852566 commit e0e6ce4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 8 additions & 2 deletions packages/botonic-cli/src/botonic-api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,16 @@ export class BotonicAPIService {
}

async getBots(): AxiosPromise<BotsList> {
return this.apiGet({ apiVersion: 'v2', path: 'bots/' })
const botsResponse = await this.apiGet({ apiVersion: 'v2', path: 'bots/' })

Check warning on line 282 in packages/botonic-cli/src/botonic-api-service.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-cli/src/botonic-api-service.ts#L282

Added line #L282 was not covered by tests

if (botsResponse.data.next) {
this.getMoreBots(botsResponse.data.results, botsResponse.data.next)

Check warning on line 285 in packages/botonic-cli/src/botonic-api-service.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-cli/src/botonic-api-service.ts#L285

Added line #L285 was not covered by tests
}

return botsResponse

Check warning on line 288 in packages/botonic-cli/src/botonic-api-service.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-cli/src/botonic-api-service.ts#L288

Added line #L288 was not covered by tests
}

async getMoreBots(bots: BotListItem[], nextBots?: string) {
private async getMoreBots(bots: BotListItem[], nextBots?: string) {
if (!nextBots) {
return bots

Check warning on line 293 in packages/botonic-cli/src/botonic-api-service.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-cli/src/botonic-api-service.ts#L293

Added line #L293 was not covered by tests
}
Expand Down
14 changes: 4 additions & 10 deletions packages/botonic-cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ Deploying to AWS...

async deployBotFromFlag(botName: string): Promise<void | undefined> {
const resp = await this.botonicApiService.getBots()
const nextBots = resp.data.next
const bots = resp.data.results
if (nextBots) {
await this.botonicApiService.getMoreBots(bots, nextBots)
}

const bot = bots.filter(b => b.name === botName)[0]
if (bot === undefined && !botName) {
console.log(colors.red(`Bot ${botName} doesn't exist.`))
Expand Down Expand Up @@ -189,9 +186,8 @@ Deploying to AWS...
return this.newBotFlow()
else {
const resp = await this.botonicApiService.getBots()
const nextBots = resp.data.next
const bots = resp.data.results
if (nextBots) await this.botonicApiService.getMoreBots(bots, nextBots)

// Show the current bot in credentials at top of the list
const firstId = this.botonicApiService.bot.id
bots.sort((x, y) => (x.id === firstId ? -1 : y.id === firstId ? 1 : 0))
Expand Down Expand Up @@ -247,10 +243,8 @@ Deploying to AWS...

async getAvailableBots(): Promise<any> {
const resp = await this.botonicApiService.getBots()
const nextBots = resp.data.next
const bots = resp.data.results
if (nextBots) await this.botonicApiService.getMoreBots(bots, nextBots)
return bots

return resp.data.results

Check warning on line 247 in packages/botonic-cli/src/commands/deploy.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-cli/src/commands/deploy.ts#L247

Added line #L247 was not covered by tests
}

async newBotFlow(): Promise<void> {
Expand Down

0 comments on commit e0e6ce4

Please sign in to comment.