Skip to content

Commit

Permalink
Merge pull request #30 from bradgarropy/owner
Browse files Browse the repository at this point in the history
🤓 owner
  • Loading branch information
bradgarropy committed Jan 2, 2020
2 parents 2bb5b8b + 0c35e2a commit 98295d3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "labman",
"version": "0.5.0",
"version": "0.6.0",
"description": "👨🏼‍🔬 github label manager cli",
"keywords": [
"github",
Expand Down
6 changes: 5 additions & 1 deletion src/cli/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const conf = require("conf")
const {repoAutocomplete} = require("../utils")
const {
errorTokenNotFound,
errorInvalidToken,
Expand Down Expand Up @@ -28,7 +29,6 @@ const builder = {
}

const handler = async argv => {
const {source, destination, labels, clobber} = argv
const token = config.get("token")

// validate token
Expand All @@ -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
Expand All @@ -62,6 +65,7 @@ const handler = async argv => {
}

createOctokit(token)
const {labels, clobber} = argv

// delete existing labels
if (clobber) {
Expand Down
13 changes: 1 addition & 12 deletions src/github/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
16 changes: 15 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const conf = require("conf")

const repoPath = object => {
const {owner, repo} = object
const path = `${owner}/${repo}`
Expand All @@ -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}

0 comments on commit 98295d3

Please sign in to comment.