Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from Nabeelhassan/master
Browse files Browse the repository at this point in the history
fix(errors): Update deprecated error handling #5
  • Loading branch information
brendon1555 authored Oct 11, 2020
2 parents 3addd89 + 9fac876 commit 05e6710
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/errors": "^1",
"@oclif/plugin-help": "^3",
"@octokit/request": "^5.4.5",
"fs-extra": "^9.0.1",
Expand Down Expand Up @@ -74,4 +75,4 @@
"prepare": "rm -rf lib && tsc -b"
},
"types": "lib/index.d.ts"
}
}
7 changes: 4 additions & 3 deletions src/commands/config/get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Command} from '@oclif/command'
import {configuration} from '../../utils/config'
import { Command } from '@oclif/command'
import { CLIError } from '@oclif/errors'
import { configuration } from '../../utils/config'

export default class ConfigGet extends Command {
static description = 'Outputs your configuration.'
Expand All @@ -8,7 +9,7 @@ export default class ConfigGet extends Command {
try {
this.log(JSON.stringify(await configuration(this)))
} catch (error) {
this.error(error || 'A GHS CLI error has occurred.', {
this.error(new CLIError(error) || 'A GHS CLI error has occurred.', {
exit: 1,
})
}
Expand Down
9 changes: 5 additions & 4 deletions src/commands/config/set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Command, flags} from '@oclif/command'
import { Command, flags } from '@oclif/command'
import { CLIError } from '@oclif/errors'
import cli from 'cli-ux'
import fs from 'fs-extra'
import emoji from 'node-emoji'
Expand Down Expand Up @@ -26,7 +27,7 @@ export default class ConfigSet extends Command {
}

async run() {
const {flags} = this.parse(ConfigSet)
const { flags } = this.parse(ConfigSet)
const config = path.join(this.config.configDir, 'config.json')

try {
Expand All @@ -37,7 +38,7 @@ export default class ConfigSet extends Command {
flags.repo = await cli.prompt('What is the name of the repo?')
flags.personalAccessToken = await cli.prompt(
'What is your GitHub Personal Access Token?',
{type: 'hide'}
{ type: 'hide' }
)
}

Expand All @@ -54,7 +55,7 @@ export default class ConfigSet extends Command {
)
this.exit()
} catch (error) {
this.error(error || 'A GHS CLI error has occurred.', {
this.error(new CLIError(error) || 'A GHS CLI error has occurred.', {
exit: 1,
})
}
Expand Down
20 changes: 10 additions & 10 deletions src/commands/secrets/get.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {Command, flags} from '@oclif/command'
import {request} from '@octokit/request'
import {configuration} from '../../utils/config'
import { Command, flags } from '@oclif/command'
import { CLIError } from '@oclif/errors'
import { request } from '@octokit/request'
import { configuration } from '../../utils/config'

export default class SecretsGet extends Command {
static description = 'Fetch a list os set secrets (cannot read secret values)'

static flags = {
help: flags.help({char: 'h'}),
help: flags.help({ char: 'h' }),
personalAccessToken: flags.string({
char: 't',
description: 'Your GitHub Personal Access Token.',
Expand All @@ -17,20 +18,19 @@ export default class SecretsGet extends Command {
description: 'Organisation the repo belongs to.',
required: false,
}),
repo: flags.string({char: 'r', description: 'Name of the repo.', required: false}),
repo: flags.string({ char: 'r', description: 'Name of the repo.', required: false }),
}

async run() {
const {flags} = this.parse(SecretsGet)
const { flags } = this.parse(SecretsGet)

try {
const conf = await configuration(this)

const requestWithAuth = request.defaults({
headers: {
authorization: `token ${
flags.personalAccessToken ?? conf.personalAccessToken
}`,
authorization: `token ${flags.personalAccessToken ?? conf.personalAccessToken
}`,
},
})
const result = await requestWithAuth(
Expand All @@ -43,7 +43,7 @@ export default class SecretsGet extends Command {

this.log(result.data)
} catch (error) {
this.error(error)
this.error(new CLIError(error))
this.exit(1)
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/commands/secrets/set.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import {Command, flags} from '@oclif/command'
import {request} from '@octokit/request'
import { Command, flags } from '@oclif/command'
import { CLIError } from '@oclif/errors'
import { request } from '@octokit/request'
import cli from 'cli-ux'
import fs from 'fs-extra'
import sodium from 'tweetsodium'
import {configuration} from '../../utils/config'
import { configuration } from '../../utils/config'

export default class SecretsSet extends Command {
static description = 'Update/Create a secret'

static flags = {
help: flags.help({char: 'h'}),
help: flags.help({ char: 'h' }),
personalAccessToken: flags.string({
char: 't',
description: 'Your GitHub Personal Access Token.',
Expand All @@ -20,7 +21,7 @@ export default class SecretsSet extends Command {
description: 'Organisation the repo belongs to.',
required: false,
}),
repo: flags.string({char: 'r', description: 'Name of the repo.', required: false}),
repo: flags.string({ char: 'r', description: 'Name of the repo.', required: false }),
file: flags.string({
char: 'f',
description: 'Location of a file to create a secret from',
Expand All @@ -45,7 +46,7 @@ export default class SecretsSet extends Command {
}

async run() {
const {flags} = this.parse(SecretsSet)
const { flags } = this.parse(SecretsSet)

try {
const conf = await configuration(this)
Expand All @@ -54,11 +55,11 @@ export default class SecretsSet extends Command {
headers: {
authorization: `token ${
flags.personalAccessToken ?? conf.personalAccessToken
}`,
}`,
},
})

const {data: token} = await requestWithAuth(
const { data: token } = await requestWithAuth(
'GET /repos/{owner}/{repo}/actions/secrets/public-key',
{
owner: flags.org ?? conf.org,
Expand Down Expand Up @@ -111,7 +112,7 @@ export default class SecretsSet extends Command {
this.log('unable to update secret')
}
} catch (error) {
this.error(error)
this.error(new CLIError(error))
this.exit(1)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/utils/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import chalk from 'chalk'
import path from 'path'
import fs from 'fs-extra'
import Command from '@oclif/command'
import { Command } from '@oclif/command'
import { CLIError } from '@oclif/errors'

interface Config {
org: string
Expand All @@ -21,7 +22,7 @@ export async function configuration(ctx: Command) {
})
}

const {org, repo, personalAccessToken}: Config = await fs.readJson(config)
const { org, repo, personalAccessToken }: Config = await fs.readJson(config)

if (!org || !repo || !personalAccessToken) {
ctx.warn(
Expand All @@ -39,7 +40,7 @@ export async function configuration(ctx: Command) {
personalAccessToken,
}
} catch (error) {
ctx.error(error || 'A GHS CLI error has occurred.', {
ctx.error(new CLIError(error) || 'A GHS CLI error has occurred.', {
exit: 1,
})
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
qqjs "^0.3.10"
tslib "^1.9.3"

"@oclif/errors@^1.2.1", "@oclif/errors@^1.2.2", "@oclif/errors@^1.3.3":
"@oclif/errors@^1", "@oclif/errors@^1.2.1", "@oclif/errors@^1.2.2", "@oclif/errors@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.3.3.tgz#fb597dfbc58c6b8609dc0b2fdf91a2d487818a82"
integrity sha512-EJR6AIOEkt/NnARNIVAskPDVtdhtO5TTNXmhDrGqMoWVsr0R6DkkLrMyq95BmHvlVWM1nduoq4fQPuCyuF2jaA==
Expand Down

0 comments on commit 05e6710

Please sign in to comment.