-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from bradgarropy/copy
🧬 copy
- Loading branch information
Showing
11 changed files
with
159 additions
and
119 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const conf = require("conf") | ||
const chalk = require("chalk") | ||
const copy = require("../copy") | ||
const {createOctokit} = require("../octokit") | ||
|
||
const config = new conf() | ||
|
||
const command = "* <source> <destination> [labels...]" | ||
const description = "Copy issue labels from one repo to another" | ||
|
||
const builder = { | ||
clobber: { | ||
alias: "c", | ||
type: "boolean", | ||
default: false, | ||
description: "Clobber destination labels", | ||
}, | ||
} | ||
|
||
const handler = async argv => { | ||
const {source, destination, labels, clobber} = argv | ||
const token = config.get("token") | ||
|
||
if (!token) { | ||
console.log( | ||
`\nYou are not logged in, please run the ${chalk.cyanBright( | ||
"login", | ||
)} command.\n`, | ||
) | ||
|
||
console.log(chalk.cyanBright("labman login <username> <token>\n")) | ||
return | ||
} | ||
|
||
createOctokit(token) | ||
|
||
try { | ||
await copy(source, destination, labels, clobber) | ||
} catch (error) { | ||
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")) | ||
} | ||
} | ||
|
||
module.exports = { | ||
command, | ||
description, | ||
builder, | ||
handler, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
|
||
const yargs = require("yargs") | ||
const {name} = require("../../package.json") | ||
|
||
yargs | ||
.scriptName(name) | ||
.command(require("./login")) | ||
.command(require("./logout")) | ||
.command(require("./default")) | ||
.help() | ||
.alias("help", "h") | ||
.alias("version", "v").argv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const conf = require("conf") | ||
const chalk = require("chalk") | ||
const {validToken} = require("../github") | ||
|
||
const config = new conf() | ||
|
||
const command = "login <username> <token>" | ||
const description = "Persist GitHub credentials" | ||
|
||
const builder = { | ||
force: { | ||
alias: "f", | ||
type: "boolean", | ||
default: false, | ||
description: "Force login", | ||
}, | ||
} | ||
|
||
const handler = async argv => { | ||
const {username, token, force} = argv | ||
const storedToken = config.get("token") | ||
|
||
if (!force && storedToken) { | ||
console.log("\nYou are already logged in!\n") | ||
return | ||
} | ||
|
||
const valid = await validToken(token) | ||
|
||
if (!valid) { | ||
console.log(`\n${chalk.redBright("Login failed!")} Please try again.\n`) | ||
return | ||
} | ||
|
||
config.set({username, token}) | ||
console.log(chalk.greenBright("\nLogin successful!\n")) | ||
|
||
return | ||
} | ||
|
||
module.exports = { | ||
command, | ||
description, | ||
builder, | ||
handler, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const conf = require("conf") | ||
|
||
const config = new conf() | ||
|
||
const command = "logout" | ||
const description = "Remove GitHub credentials" | ||
const builder = {} | ||
const handler = () => config.clear() | ||
|
||
module.exports = { | ||
command, | ||
description, | ||
builder, | ||
handler, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const {getLabels, deleteLabels, createLabels} = require("./github") | ||
|
||
const copy = async (source, destination, labels = [], clobber = false) => { | ||
const [sourceOwner, sourceRepo] = source.split("/") | ||
const [destinationOwner, destinationRepo] = destination.split("/") | ||
|
||
// delete existing labels | ||
if (clobber) { | ||
const oldLabels = await getLabels(destinationOwner, destinationRepo) | ||
await deleteLabels(oldLabels, destinationOwner, destinationRepo) | ||
} | ||
|
||
// create new labels | ||
const sourceLabels = await getLabels(sourceOwner, sourceRepo) | ||
|
||
const newLabels = labels.length | ||
? sourceLabels.filter(label => labels.includes(label.name)) | ||
: sourceLabels | ||
|
||
await createLabels(newLabels, destinationOwner, destinationRepo) | ||
} | ||
|
||
module.exports = copy |
This file was deleted.
Oops, something went wrong.