-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(addons-v5): move addons:destroy to CLI & upgrade to oclif (#…
…2602) * wip: working through tests. Found an issue with the codemod * tests working * wip * fix: delete OG files * wip on unit tests * fix: change command to have a required arg and allow variable args * fix: unit tests passing * chore: delete unused files that were migrated. * chore: clean up. Remove unused waitForAddonDeprovisioning * refactor: migrate to core & TS. wip * fix: unit tests passing * fix: tests passing * Delete unused files * add alias. cleanup * wip: converting resolve.unit.test. 'does not memoize errors' test is hanging and can't find a way to catch the error. * wip: attempt to change test to account for @heroku-cli/command's APIClient now retrying on two_factor 403 * fix: test 500 instead of 403 that is handled by APIClient retry * chore: clean up.
- Loading branch information
Showing
11 changed files
with
795 additions
and
271 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
155 changes: 0 additions & 155 deletions
155
packages/addons-v5/test/unit/commands/addons/destroy.unit.test.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
|
||
import color from '@heroku-cli/color' | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {Args} from '@oclif/core' | ||
import * as Heroku from '@heroku-cli/schema' | ||
import notify from '../../lib/notify' | ||
import confirmApp from '../../lib/apps/confirm-app' | ||
import destroyAddon from '../../lib/addons/destroy_addon' | ||
import {resolveAddon} from '../../lib/addons/resolve' | ||
import {groupBy} from 'lodash' | ||
|
||
export default class Destroy extends Command { | ||
static topic = 'addons' | ||
static description = 'permanently destroy an add-on resource' | ||
static strict = false | ||
static examples = ['addons:destroy [ADDON]... [flags]'] | ||
static aliases = ['addons:remove'] | ||
static flags = { | ||
force: flags.boolean({char: 'f', description: 'allow destruction even if connected to other apps'}), | ||
confirm: flags.string({char: 'c'}), | ||
wait: flags.boolean({description: 'watch add-on destruction status and exit when complete'}), | ||
app: flags.app(), | ||
} | ||
|
||
static args = { | ||
addonName: Args.string({required: true}), | ||
} | ||
|
||
public async run(): Promise<void> { | ||
const {flags, argv} = await this.parse(Destroy) | ||
const {app, wait, confirm} = flags | ||
const force = flags.force || process.env.HEROKU_FORCE === '1' | ||
|
||
const addons = await Promise.all(argv.map(name => resolveAddon(this.heroku, app, name))) | ||
for (const addon of addons) { | ||
// prevent deletion of add-on when context.app is set but the addon is attached to a different app | ||
const addonApp = addon.app.name | ||
if (app && addonApp !== app) { | ||
throw new Error(`${color.yellow(addon.name)} is on ${color.magenta(addonApp)} not ${color.magenta(app)}`) | ||
} | ||
} | ||
|
||
for (const addonApps of Object.entries(groupBy<Heroku.AddOn>(addons, 'app.name'))) { | ||
const currentAddons = addonApps[1] | ||
const appName = addonApps[0] | ||
await confirmApp(appName, confirm) | ||
for (const addon of currentAddons) { | ||
try { | ||
await destroyAddon(this.heroku, addon, force, wait) | ||
if (wait) { | ||
notify(`heroku addons:destroy ${addon.name}`, 'Add-on successfully deprovisioned') | ||
} | ||
} catch (error) { | ||
if (wait) { | ||
notify(`heroku addons:destroy ${addon.name}`, 'Add-on failed to deprovision', false) | ||
} | ||
|
||
throw error | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.