Skip to content

Commit

Permalink
Added addons:downgrade alias
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Feb 22, 2024
1 parent 9c3f2d6 commit ffa43ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 301 deletions.
296 changes: 0 additions & 296 deletions packages/addons-v5/test/unit/lib/resolve.unit.test.js

This file was deleted.

8 changes: 6 additions & 2 deletions packages/cli/src/commands/addons/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {HTTP} from 'http-call'
import {HerokuAPIError} from '@heroku-cli/command/lib/api-client'

export default class Upgrade extends Command {
static aliases = ['addons:downgrade'];
static topic = 'addons'
static description = 'change add-on plan'
static help = 'See available plans with `heroku addons:plans SERVICE`.\n\nNote that `heroku addons:upgrade` and `heroku addons:downgrade` are the same.\nEither one can be used to change an add-on plan up or down.\n\nhttps://devcenter.heroku.com/articles/managing-add-ons'
static examples = ['Upgrade an add-on by service name:\n$ heroku addons:upgrade heroku-redis:premium-2\n\nUpgrade a specific add-on:\n$ heroku addons:upgrade swimming-briskly-123 heroku-redis:premium-2']
static flags = {
app: flags.app(),
}
Expand Down Expand Up @@ -48,7 +50,7 @@ export default class Upgrade extends Command {
try {
const patchResult: HTTP<Required<AddOn & {
provision_message: string
}>> = await this.heroku.patch(`/apps/${app}/addons/${addonName}`,
}>> = await this.heroku.patch(`/apps/${appName}/addons/${addonName}`,
{
body: {plan: {name: updatedPlanName}},
headers: {
Expand All @@ -70,6 +72,8 @@ ${plans.map(plan => plan.name).join('\n')}\n\nSee more plan information with ${c
${color.cyan('https://devcenter.heroku.com/articles/managing-add-ons')}`)
}

throw error
}
}

Expand All @@ -81,7 +85,7 @@ ${color.cyan('https://devcenter.heroku.com/articles/managing-add-ons')}`)

protected getAddonPartsFromArgs(args: { addon: string, plan: string | undefined }): { plan: string, addon: string } {
let {addon, plan} = args
// called with just one argument in the form of `heroku addons:upgrade heroku-redis:hobby`

if (!plan && addon.includes(':')) {
([addon, plan] = addon.split(':'))
}
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/lib/addons/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const appAddon = async function (heroku: APIClient, app: string, id: stri
return singularize('addon', options.namespace)(response?.body)
}

const handleNotFound = function (err: {statusCode: number, body?:{resource: string}}, resource: string) {
const handleNotFound = function (err: { statusCode: number, body?: { resource: string } }, resource: string) {
if (err.statusCode === 404 && err.body && err.body.resource === resource) {
return true
}
Expand Down Expand Up @@ -116,7 +116,7 @@ export const attachmentResolver = async (heroku: APIClient, app: string | undefi
if (attachment) {
return attachment
}
} catch {}
} catch {}

// if no attachment, look up an add-on that matches the id
// If we were passed an add-on slug, there still could be an attachment
Expand All @@ -138,10 +138,11 @@ export const attachmentResolver = async (heroku: APIClient, app: string | undefi
// -----------------------------------------------------

const addonResolverMap = new Map<string, ReturnType<typeof addonResolver>>()

export async function resolveAddon(...args: Parameters<typeof addonResolver>): ReturnType<typeof addonResolver> {
const [, app, id, options] = args
const key = `${app}|${id}|${options?.addon_service ?? ''}`
const promise:ReturnType<typeof addonResolver> = addonResolverMap.get(key) || addonResolver(...args)
const promise: ReturnType<typeof addonResolver> = addonResolverMap.get(key) || addonResolver(...args)
try {
await promise
addonResolverMap.has(key) || addonResolverMap.set(key, promise)
Expand Down

0 comments on commit ffa43ec

Please sign in to comment.