Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(apps:update): add ability to use ZENDESK_APP_ID env var during apps:update #254

Merged
merged 8 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion docs/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ EXAMPLES
NOTE: For development purposes, you can specify a domain different from `zendesk.com` for logging in to a different environment. For example, if the environment is hosted on `example.com`, you can run
`zcli login -s zendesk-subdomain -d example.com -i` and you will be logged in to `zendesk-subdomain.example.com`. If the option is not specified, the default `zendesk.com` domain will be used.

NOTE: For CI/CD or unattended login you can set `ZENDESK_SUBDOMAIN`, `ZENDESK_EMAIL` and `ZENDESK_API_TOKEN` environment variables. You don't need to run login command if you have set these environment variables.
NOTE: For CI/CD or unattended login you can set `ZENDESK_APP_ID`, `ZENDESK_SUBDOMAIN`, `ZENDESK_EMAIL` and `ZENDESK_API_TOKEN` environment variables. You don't need to run login command if you have set these environment variables.
You can also set the `ZENDESK_DOMAIN` environment variable for different environments.
13 changes: 7 additions & 6 deletions packages/zcli-apps/src/commands/apps/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { createAppPkg } from '../../lib/package'
import { Manifest, ZcliConfigFileContent } from '../../types'
import { validateAppPath } from '../../lib/appPath'
import { EnvVars } from '../../../../zcli-core/src/lib/env'

export default class Update extends Command {
static description = 'updates an existing private app in the Zendesk products specified in the apps manifest file.'
Expand All @@ -18,19 +19,18 @@

static strict = false

getAppID (appPath: string) {
const allConfigs = getAllConfigs(appPath)
const app_id = allConfigs ? allConfigs.app_id : undefined
getAppID (appConfig: ZcliConfigFileContent) {
const app_id = process.env[EnvVars.APP_ID] || (appConfig ? appConfig.app_id : undefined)
if (!app_id) { throw new CLIError(chalk.red('App ID not found')) }
return app_id
}

async installApp (appConfig: ZcliConfigFileContent, uploadId: number, appPath: string, manifest: Manifest) {
async installApp (appConfig: ZcliConfigFileContent, uploadId: number, appPath: string, manifest: Manifest, appID: string) {
CliUx.ux.action.start('Deploying app')
const { job_id } = await deployApp('PUT', `api/v2/apps/${appConfig.app_id}`, uploadId)
const { job_id } = await deployApp('PUT', `api/v2/apps/${appID}`, uploadId)

try {
const { app_id }: any = await getUploadJobStatus(job_id, appPath)

Check warning on line 33 in packages/zcli-apps/src/commands/apps/update.ts

View workflow job for this annotation

GitHub Actions / build-and-check (ubuntu-latest, 18.x)

Unexpected any. Specify a different type

Check warning on line 33 in packages/zcli-apps/src/commands/apps/update.ts

View workflow job for this annotation

GitHub Actions / build-and-check (macos-latest, 18.x)

Unexpected any. Specify a different type
CliUx.ux.action.stop('Deployed')
if (!manifest.requirementsOnly && manifest.location) {
Object.keys(manifest.location).forEach(async product => {
Expand All @@ -54,6 +54,7 @@

CliUx.ux.action.start('Uploading app')
const appConfig = getAllConfigs(appPath) || {}
const appID = this.getAppID(appConfig)
const manifest = getManifestFile(appPath)
const pkgPath = await createAppPkg(appPath)
const { id: upload_id } = await uploadAppPkg(pkgPath)
Expand All @@ -65,7 +66,7 @@

CliUx.ux.action.stop('Uploaded')
try {
await this.installApp(appConfig, upload_id, appPath, manifest)
await this.installApp(appConfig, upload_id, appPath, manifest, appID)
} catch (error) {
this.error(chalk.red(error))
}
Expand Down
3 changes: 2 additions & 1 deletion packages/zcli-core/src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const EnvVars = {
EMAIL: 'ZENDESK_EMAIL',
PASSWORD: 'ZENDESK_PASSWORD',
API_TOKEN: 'ZENDESK_API_TOKEN',
OAUTH_TOKEN: 'ZENDESK_OAUTH_TOKEN'
OAUTH_TOKEN: 'ZENDESK_OAUTH_TOKEN',
APP_ID: 'ZENDESK_APP_ID'
}

export const varExists = (...args: any[]) => !args.filter(envVar => !process.env[envVar]).length
Loading