Skip to content

Commit

Permalink
Merge pull request #16 from bradgarropy/colors
Browse files Browse the repository at this point in the history
🎨 colors
  • Loading branch information
bradgarropy authored Dec 21, 2019
2 parents 34895ea + 2de0610 commit 0d183b5
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 38 deletions.
134 changes: 118 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "labman",
"version": "0.2.0",
"version": "0.3.0",
"description": "👨🏼‍🔬 github label manager cli",
"keywords": [
"github",
Expand Down Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"@octokit/rest": "^16.35.2",
"chalk": "^3.0.0",
"conf": "^6.2.0",
"yargs": "^15.0.2"
},
Expand Down
1 change: 0 additions & 1 deletion src/clone.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {getLabels, deleteLabels, createLabels} = require("./github")

const clone = async (source, destination) => {
console.log(source, "->", destination)
const [sourceOwner, sourceRepo] = source.split("/")
const [destinationOwner, destinationRepo] = destination.split("/")

Expand Down
22 changes: 9 additions & 13 deletions src/github.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
const chalk = require("chalk")
const {createOctokit, getOctokit} = require("./octokit")

const getRateLimit = async () => {
const octokit = getOctokit()
const response = await octokit.rateLimit.get()
const {limit, remaining} = response.data.resources.core

console.log(`${remaining}/${limit} remaining`)
}

const validToken = async token => {
const octokit = createOctokit(token)

Expand All @@ -34,12 +27,14 @@ const getLabels = async (owner, repo) => {
}

const deleteLabels = async (labels, owner, repo) => {
console.log(`\nDeleting labels from ${owner}/${repo}`)
console.log(
`\nDeleting labels from ${chalk.cyanBright(`${owner}/${repo}`)}\n`,
)

const octokit = getOctokit()

labels.forEach(label => {
console.log(` - ${label.name}`)
console.log(` ${chalk.bold.redBright("-")} ${label.name}`)

const parameters = {
owner,
Expand All @@ -52,12 +47,14 @@ const deleteLabels = async (labels, owner, repo) => {
}

const createLabels = async (labels, owner, repo) => {
console.log(`\nCreating labels in ${owner}/${repo}`)
console.log(
`\nCreating labels in ${chalk.cyanBright(`${owner}/${repo}`)}\n`,
)

const octokit = getOctokit()

labels.forEach(label => {
console.log(` - ${label.name}`)
console.log(` ${chalk.bold.greenBright("+")} ${label.name}`)

const parameters = {
owner,
Expand All @@ -72,7 +69,6 @@ const createLabels = async (labels, owner, repo) => {
}

module.exports = {
getRateLimit,
validToken,
getLabels,
deleteLabels,
Expand Down
21 changes: 14 additions & 7 deletions src/handlers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const conf = require("conf")
const chalk = require("chalk")
const clone = require("./clone")
const {validToken} = require("./github")
const {createOctokit} = require("./octokit")
Expand All @@ -10,19 +11,19 @@ const loginHandler = async argv => {
const storedToken = config.get("token")

if (!force && storedToken) {
console.log("\nYou are already logged in!")
console.log("\nYou are already logged in!\n")
return
}

const valid = await validToken(token)

if (!valid) {
console.log("Login failed! Please try again.")
console.log(`\n${chalk.redBright("Login failed!")} Please try again.\n`)
return
}

config.set({username, token})
console.log("Login successful!")
console.log(chalk.greenBright("\nLogin successful!\n"))

return
}
Expand All @@ -37,10 +38,12 @@ const cloneHandler = async argv => {

if (!token) {
console.log(
"\nYou are not logged in! Please run the 'login' command.\n",
`\nYou are not logged in, please run the ${chalk.cyanBright(
"login",
)} command.\n`,
)

console.log("labman login <username> <token>\n")
console.log(chalk.cyanBright("labman login <username> <token>\n"))
return
}

Expand All @@ -49,8 +52,12 @@ const cloneHandler = async argv => {
try {
await clone(source, destination)
} catch (error) {
console.log("\nInvalid token! Please run the 'login' command again.\n")
console.log("labman login <username> <token>\n")
console.log(
`\n${chalk.redBright(
"Invalid token!",
)} Please run the ${chalk.cyanBright("login")} command again.\n`,
)
console.log(chalk.cyanBright("labman login <username> <token>\n"))
}
}

Expand Down

0 comments on commit 0d183b5

Please sign in to comment.