Skip to content

Commit

Permalink
feat: add /callhome cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Jul 26, 2018
1 parent 7640ffe commit 4b493f1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
19 changes: 19 additions & 0 deletions src/in-house-bot/commands/callhome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import parse from 'yargs-parser'
import { ICommand, IDeploymentConf } from '../types'

export const command:ICommand = {
name: 'callhome',
description: `call home to Tradle. This ensures you're registered for updates`,
adminOnly: true,
examples: [
'/callhome',
],
exec: async ({ commander, req, ctx, args }) => {
const { deployment, logger } = commander
if (!deployment) {
throw new Error('"deployment" plugin not configured. Please add to plugins in bot.json')
}

await deployment.callHomeToTradle()
}
}
28 changes: 16 additions & 12 deletions src/in-house-bot/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ type CallHomeOpts = {
deploymentUUID?: string
}

type CallHomeToOpts = {
identity?: IIdentity
org?: IOrganization
targetApiUrl?: string
deploymentUUID?: string
}

// interface IUpdateChildDeploymentOpts {
// apiUrl?: string
// deploymentUUID?: string
Expand Down Expand Up @@ -482,12 +489,7 @@ export class Deployment {
tasks.push(reportToParent)
}

const reportToTradle = this.callHomeTo({
identity,
org,
targetApiUrl: TRADLE.API_BASE_URL,
})
.catch(err => {
const reportToTradle = this.callHomeToTradle({ identity, org }).catch(err => {
this.logger.debug('failed to call home to tradle', {
error: err.stack
})
Expand All @@ -499,12 +501,14 @@ export class Deployment {
await Promise.all(tasks)
}

public callHomeTo = async ({ targetApiUrl, identity, org, deploymentUUID }: {
targetApiUrl: string
identity?: IIdentity
org?: IOrganization
deploymentUUID?: string
}) => {
public callHomeToTradle = async (opts:CallHomeToOpts={}) => {
return await this.callHomeTo({
targetApiUrl: TRADLE.API_BASE_URL,
...opts,
})
}

public callHomeTo = async ({ targetApiUrl, identity, org, deploymentUUID }: CallHomeToOpts) => {
if (this.bot.env.IS_OFFLINE) return {}

if (!org) org = this.org
Expand Down

0 comments on commit 4b493f1

Please sign in to comment.