diff --git a/package.json b/package.json index ff0a31c..a493451 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "labman", - "version": "0.5.0", + "version": "0.6.0", "description": "👨🏼‍🔬 github label manager cli", "keywords": [ "github", diff --git a/src/cli/default.js b/src/cli/default.js index 4b90d64..2a2055a 100644 --- a/src/cli/default.js +++ b/src/cli/default.js @@ -1,4 +1,5 @@ const conf = require("conf") +const {repoAutocomplete} = require("../utils") const { errorTokenNotFound, errorInvalidToken, @@ -28,7 +29,6 @@ const builder = { } const handler = async argv => { - const {source, destination, labels, clobber} = argv const token = config.get("token") // validate token @@ -45,6 +45,9 @@ const handler = async argv => { return } + const source = repoAutocomplete(argv.source) + const destination = repoAutocomplete(argv.destination) + const isValidSource = await validRepo(source) // validate source @@ -62,6 +65,7 @@ const handler = async argv => { } createOctokit(token) + const {labels, clobber} = argv // delete existing labels if (clobber) { diff --git a/src/github/labels.js b/src/github/labels.js index 22c4821..66b8927 100644 --- a/src/github/labels.js +++ b/src/github/labels.js @@ -54,18 +54,7 @@ const createLabels = async (labels, repo) => { await octokit.issues.createLabel(parameters) console.log(` ${chalk.bold.greenBright("+")} ${name}`) } catch (error) { - const {status} = error - - switch (status) { - case 404: - errorRepoNotFound(repo) - process.exit() - break - - case 422: - errorLabelExists(name) - break - } + errorLabelExists(name) } }) } diff --git a/src/utils.js b/src/utils.js index 71343ec..96eb113 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,3 +1,5 @@ +const conf = require("conf") + const repoPath = object => { const {owner, repo} = object const path = `${owner}/${repo}` @@ -16,4 +18,16 @@ const repoObject = string => { return object } -module.exports = {repoPath, repoObject} +const repoAutocomplete = repo => { + if (repo.includes("/")) { + return repo + } + + const config = new conf() + const owner = config.get("username") + + const autocompleted = `${owner}/${repo}` + return autocompleted +} + +module.exports = {repoPath, repoObject, repoAutocomplete}