Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cspell-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ hamurai
herokai
herokuapp
herokudns
herokulytics
herokumanager
herokussl
histfile
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,21 @@
"dirname": "heroku",
"hooks": {
"command_not_found": [
"./dist/hooks/command_not_found/performance_analytics"
"./dist/hooks/command_not_found/setup-otel-telemetry"
],
"finally": [
"./dist/hooks/finally/sentry"
"./dist/hooks/finally/send-otel-and-sentry-errors"
],
"init": [
"./dist/hooks/init/version",
"./dist/hooks/init/terms-of-service",
"./dist/hooks/init/performance_analytics"
"./dist/hooks/init/setup-otel-telemetry"
],
"postrun": [
"./dist/hooks/postrun/performance_analytics"
"./dist/hooks/postrun/send-otel-telemetry"
],
"prerun": [
"./dist/hooks/prerun/analytics"
"./dist/hooks/prerun/collect-and-send-herokulytics"
],
"preupdate": [
"./dist/hooks/preupdate/check-npm-auth"
Expand Down
18 changes: 10 additions & 8 deletions src/commands/access/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import * as Heroku from '@heroku-cli/schema'
import {color, hux} from '@heroku/heroku-cli-util'
import {ux} from '@oclif/core/ux'
import _ from 'lodash'

import {lazyModuleLoader} from '../../lib/lazy-module-loader.js'
import {getOwner, isTeamApp} from '../../lib/teamUtils.js'

type AdminWithPermissions = Heroku.TeamMember & {
Expand All @@ -28,6 +28,8 @@
static topic = 'access'

public async run(): Promise<void> {
const _ = await lazyModuleLoader.loadLodash()

const {flags} = await this.parse(AccessIndex)
const {app: appName, json} = flags
const {body: app} = await this.heroku.get<Heroku.App>(`/apps/${appName}`)
Expand All @@ -43,8 +45,8 @@
admin.permissions = adminPermissions
return admin
})
collaborators = buildCollaboratorsArray(collaborators, admins)
collaborators = buildCollaboratorsArray(collaborators, admins, _)
} catch (error: any) {

Check warning on line 49 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (!(error instanceof HerokuAPIError && error.http.statusCode === 403))
throw error
}
Expand All @@ -53,11 +55,11 @@
if (json)
printJSON(collaborators)
else
printAccess(app, collaborators)
printAccess(app, collaborators, _)
}
}

function buildCollaboratorsArray(collaboratorsRaw: Heroku.TeamAppCollaborator[], admins: Heroku.TeamMember[]) {
function buildCollaboratorsArray(collaboratorsRaw: Heroku.TeamAppCollaborator[], admins: Heroku.TeamMember[], _: any) {

Check warning on line 62 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const collaboratorsNoAdmins = _.reject(collaboratorsRaw, {role: 'admin'})
return _.union(collaboratorsNoAdmins, admins)
}
Expand All @@ -65,10 +67,10 @@
function buildTableColumns(showPermissions: boolean) {
const baseColumns = {
email: {
get: ({email}: any): string => color.user(email),

Check warning on line 70 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
},
role: {
get: ({role}: any) => color.info(role),

Check warning on line 73 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
},
}

Expand All @@ -82,12 +84,12 @@
return baseColumns
}

function printAccess(app: Heroku.App, collaborators: any[]) {
function printAccess(app: Heroku.App, collaborators: any[], _: any) {

Check warning on line 87 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 87 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const showPermissions = isTeamApp(app.owner?.email)
collaborators = _.chain(collaborators)
.sortBy(c => c.email || c.user.email)
.reject(c => /herokumanager\.com$/.test(c.user.email))
.map(collab => {
.sortBy((c: any) => c.email || c.user.email)

Check warning on line 90 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
.reject((c: any) => /herokumanager\.com$/.test(c.user.email))

Check warning on line 91 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
.map((collab: any) => {

Check warning on line 92 in src/commands/access/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const {email} = collab.user
const {permissions, role} = collab
const data: MemberData = {email, role: role || 'collaborator'}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/apps/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
import * as Heroku from '@heroku-cli/schema'
import {Args, Interfaces, ux} from '@oclif/core'
import fs from 'fs-extra'
import {parse} from 'yaml'

import Git from '../../lib/git/git.js'
import {lazyModuleLoader} from '../../lib/lazy-module-loader.js'

const git = new Git()

Expand Down Expand Up @@ -193,6 +193,7 @@ ${color.command('heroku apps:create --region eu')}`]
static hiddenAliases = ['create']

async readManifest() {
const {parse} = await lazyModuleLoader.loadYaml()
const buffer = await fs.readFile('heroku.yml')
return parse(buffer.toString())
}
Expand Down
8 changes: 5 additions & 3 deletions src/commands/apps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {SpaceCompletion} from '@heroku-cli/command/lib/completions.js'
import * as Heroku from '@heroku-cli/schema'
import {color, hux} from '@heroku/heroku-cli-util'
import {ux} from '@oclif/core/ux'
import _ from 'lodash'

import {lazyModuleLoader} from '../../lib/lazy-module-loader.js'
import {App} from '../../lib/types/app.js'

export default class AppsIndex extends Command {
Expand Down Expand Up @@ -32,6 +32,8 @@ export default class AppsIndex extends Command {
static topic = 'apps'

async run() {
const _ = await lazyModuleLoader.loadLodash()

const {flags} = await this.parse(AppsIndex)

const teamIdentifier = flags.team
Expand Down Expand Up @@ -65,7 +67,7 @@ export default class AppsIndex extends Command {
if (json) {
hux.styledJSON(apps)
} else {
print(apps, user, space, team)
print(apps, user, space, team, _)
}
}
}
Expand All @@ -87,7 +89,7 @@ function listApps(apps: Heroku.App) {
apps.forEach((app: App) => ux.stdout(regionizeAppName(app)))
}

function print(apps: Heroku.App, user: Heroku.Account, space?: string, team?: null | string) {
function print(apps: Heroku.App, user: Heroku.Account, space: string | undefined, team: null | string | undefined, _: any) {
if (apps.length === 0) {
if (space) ux.stdout(`There are no apps in space ${color.space(space)}.`)
else if (team) ux.stdout(`There are no apps in team ${color.team(team)}.`)
Expand Down
174 changes: 87 additions & 87 deletions src/commands/apps/info.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,96 @@
import {color, hux} from '@heroku/heroku-cli-util'
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {color, hux} from '@heroku/heroku-cli-util'
import {Args, ux} from '@oclif/core'
import {filesize} from 'filesize'
import _ from 'lodash'
import * as util from 'util'

import {getGeneration} from '../../lib/apps/generation.js'
import {lazyModuleLoader} from '../../lib/lazy-module-loader.js'

export default class AppsInfo extends Command {
static args = {
app: Args.string({hidden: true}),
}

static description = 'show detailed app information'
static examples = [
color.command('heroku apps:info'),
color.command('heroku apps:info --shell'),
]

static flags = {
app: flags.app(),
extended: flags.boolean({char: 'x', hidden: true}),
json: flags.boolean({char: 'j', description: 'output in json format'}),
remote: flags.remote(),
shell: flags.boolean({char: 's', description: 'output more shell friendly key/value pairs'}),
}

static help = `$ heroku apps:info
=== example
Git URL: https://git.heroku.com/example.git
Repo Size: 5M
...

$ heroku apps:info --shell
git_url=https://git.heroku.com/example.git
repo_size=5000000
...`

static hiddenAliases = ['info']

static topic = 'apps'

async run() {
const _ = await lazyModuleLoader.loadLodash()

const {args, flags} = await this.parse(AppsInfo)

const {countBy, snakeCase} = _
const app = args.app || flags.app
if (!app) throw new Error('No app specified.\nUSAGE: heroku apps:info --app my-app')

const info = await getInfo(app, this, flags.extended)
const addons = info.addons.map((a: Heroku.AddOn) => a.plan?.name).sort()
const collaborators = info.collaborators.map((c: Heroku.Collaborator) => c.user.email)
.filter((c: Heroku.Collaborator) => c !== info.app.owner.email)
.sort()

function shell() {
function print(k: string, v: string) {
ux.stdout(`${_.snakeCase(k)}=${v}`)
}

print('auto_cert_mgmt', info.app.acm)
print('addons', addons)
print('collaborators', collaborators)

if (info.app.archived_at) print('archived_at', formatDate(new Date(info.app.archived_at)))
if (info.app.cron_finished_at) print('cron_finished_at', formatDate(new Date(info.app.cron_finished_at)))
if (info.app.cron_next_run) print('cron_next_run', formatDate(new Date(info.app.cron_next_run)))
if (info.app.database_size) print('database_size', filesize(info.app.database_size, {round: 0, standard: 'jedec'}))
if (info.app.create_status !== 'complete') print('create_status', info.app.create_status)
if (info.pipeline_coupling) print('pipeline', `${info.pipeline_coupling.pipeline.name}:${info.pipeline_coupling.stage}`)

print('git_url', info.app.git_url)
print('web_url', info.app.web_url)
print('repo_size', filesize(info.app.repo_size, {round: 0, standard: 'jedec'}))
if (getGeneration(info.app) !== 'fir') print('slug_size', filesize(info.app.slug_size, {round: 0, standard: 'jedec'}))
print('owner', info.app.owner.email)
print('region', info.app.region.name)
print('dynos', util.inspect(_.countBy(info.dynos, 'type')))
print('stack', info.app.stack.name)
}

if (flags.shell) {
shell()
} else if (flags.json) {
hux.styledJSON(info)
} else {
print(info, addons, collaborators, flags.extended, _)
}
}
}

function formatDate(date: Date) {
return date.toISOString()
Expand Down Expand Up @@ -57,7 +139,7 @@ async function getInfo(app: string, client: Command, extended: boolean) {
return data
}

function print(info: Heroku.App, addons: Heroku.AddOn[], collaborators: Heroku.Collaborator[], extended: boolean) {
function print(info: Heroku.App, addons: Heroku.AddOn[], collaborators: Heroku.Collaborator[], extended: boolean, _: any) {
const data: Heroku.App = {}
data.Addons = addons
data.Collaborators = collaborators
Expand All @@ -78,7 +160,7 @@ function print(info: Heroku.App, addons: Heroku.AddOn[], collaborators: Heroku.C
if (getGeneration(info.app) !== 'fir') data['Slug Size'] = filesize(info.app.slug_size, {round: 0, standard: 'jedec'})
data.Owner = color.user(info.app.owner.email)
data.Region = info.app.region.name
data.Dynos = countBy(info.dynos, 'type')
data.Dynos = _.countBy(info.dynos, 'type')
data.Stack = (function (app) {
let stack = info.app.stack.name
if (app.stack.name !== app.build_stack.name) {
Expand All @@ -98,85 +180,3 @@ function print(info: Heroku.App, addons: Heroku.AddOn[], collaborators: Heroku.C
}
}
}

export default class AppsInfo extends Command {
static args = {
app: Args.string({hidden: true}),
}

static description = 'show detailed app information'
static examples = [
color.command('heroku apps:info'),
color.command('heroku apps:info --shell'),
]

static flags = {
app: flags.app(),
extended: flags.boolean({char: 'x', hidden: true}),
json: flags.boolean({char: 'j', description: 'output in json format'}),
remote: flags.remote(),
shell: flags.boolean({char: 's', description: 'output more shell friendly key/value pairs'}),
}

static help = `$ heroku apps:info
=== example
Git URL: https://git.heroku.com/example.git
Repo Size: 5M
...

$ heroku apps:info --shell
git_url=https://git.heroku.com/example.git
repo_size=5000000
...`

static hiddenAliases = ['info']

static topic = 'apps'

async run() {
const {args, flags} = await this.parse(AppsInfo)

const app = args.app || flags.app
if (!app) throw new Error('No app specified.\nUSAGE: heroku apps:info --app my-app')

const info = await getInfo(app, this, flags.extended)
const addons = info.addons.map((a: Heroku.AddOn) => a.plan?.name).sort()
const collaborators = info.collaborators.map((c: Heroku.Collaborator) => c.user.email)
.filter((c: Heroku.Collaborator) => c !== info.app.owner.email)
.sort()

function shell() {
function print(k: string, v: string) {
ux.stdout(`${snakeCase(k)}=${v}`)
}

print('auto_cert_mgmt', info.app.acm)
print('addons', addons)
print('collaborators', collaborators)

if (info.app.archived_at) print('archived_at', formatDate(new Date(info.app.archived_at)))
if (info.app.cron_finished_at) print('cron_finished_at', formatDate(new Date(info.app.cron_finished_at)))
if (info.app.cron_next_run) print('cron_next_run', formatDate(new Date(info.app.cron_next_run)))
if (info.app.database_size) print('database_size', filesize(info.app.database_size, {round: 0, standard: 'jedec'}))
if (info.app.create_status !== 'complete') print('create_status', info.app.create_status)
if (info.pipeline_coupling) print('pipeline', `${info.pipeline_coupling.pipeline.name}:${info.pipeline_coupling.stage}`)

print('git_url', info.app.git_url)
print('web_url', info.app.web_url)
print('repo_size', filesize(info.app.repo_size, {round: 0, standard: 'jedec'}))
if (getGeneration(info.app) !== 'fir') print('slug_size', filesize(info.app.slug_size, {round: 0, standard: 'jedec'}))
print('owner', info.app.owner.email)
print('region', info.app.region.name)
print('dynos', util.inspect(countBy(info.dynos, 'type')))
print('stack', info.app.stack.name)
}

if (flags.shell) {
shell()
} else if (flags.json) {
hux.styledJSON(info)
} else {
print(info, addons, collaborators, flags.extended)
}
}
}
8 changes: 5 additions & 3 deletions src/commands/apps/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import * as color from '@heroku/heroku-cli-util/color'
import {Args, ux} from '@oclif/core'
import inquirer from 'inquirer'
import tsheredoc from 'tsheredoc'

import {appTransfer} from '../../lib/apps/app-transfer.js'
import {lazyModuleLoader} from '../../lib/lazy-module-loader.js'
import ConfirmCommand from '../../lib/confirmCommand.js'
import {getOwner, isTeamApp, isValidEmail} from '../../lib/teamUtils.js'
import AppsLock from './lock.js'
Expand Down Expand Up @@ -36,7 +36,7 @@ export default class AppsTransfer extends Command {

static topic = 'apps'

getAppsToTransfer(apps: Heroku.App[]) {
getAppsToTransfer(apps: Heroku.App[], inquirer: any) {
return inquirer.prompt([{
choices: apps.map(app => ({
name: `${color.app(app.name ?? '')} (${getOwner(app.owner?.email ?? '')})`, value: {name: app.name, owner: app.owner?.email},
Expand All @@ -49,12 +49,14 @@ export default class AppsTransfer extends Command {
}

public async run() {
const inquirer = await lazyModuleLoader.loadInquirer()

const {args, flags} = await this.parse(AppsTransfer)
const {app, bulk, confirm, locked} = flags
const {recipient} = args
if (bulk) {
const {body: allApps} = await this.heroku.get<Heroku.App[]>('/apps')
const selectedApps = await this.getAppsToTransfer(allApps.sort((a, b) => (a.name ?? '').localeCompare(b.name ?? '')))
const selectedApps = await this.getAppsToTransfer(allApps.sort((a, b) => (a.name ?? '').localeCompare(b.name ?? '')), inquirer)
ux.warn(`Transferring applications to ${color.name(recipient)}...\n`)
for (const app of selectedApps.choices) {
try {
Expand Down
Loading
Loading