Skip to content

Commit

Permalink
Merge pull request #25 from himynameisdave/v0.7.0
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
himynameisdave committed Feb 22, 2016
2 parents c113a44 + 2be40be commit 2837a85
Show file tree
Hide file tree
Showing 24 changed files with 146 additions and 91 deletions.
3 changes: 0 additions & 3 deletions .token.json

This file was deleted.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ Using this bad boy is a breeze. First `cd` into your git repository, run the com
git-labelmaker
```

![Preview of git-labelmaker](http://i.imgur.com/UYSjdNw.png)

#### Token

If it's the first time running it, you will be prompted for a GitHub token, which you can [generate over here](https://github.com/settings/tokens). You can reset your token later, but otherwise `git-labelmaker` will remember it for you. Your token must have `repo` permissions.
To interact with the GitHub API, you will need your own access token, which you can [generate over here](https://github.com/settings/tokens). Make sure your token has `repo` permissions.

Instead of having to enter your token each time, `git-labelmaker` will remember it and keep it secure for you while you instead only need to remember a password you create. You can make your password whatever you like - passwords are easier to remember than tokens!

#### Add Custom Labels

Expand Down
68 changes: 41 additions & 27 deletions index.js → bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const alertDeletes = require("./utils/alertDeletes"),
banner = require("./utils/banners"),
configGitLabel = require("./utils/configGitLabel"),
filterRemovalLabels = require("./utils/filterRemovalLabels"),
removeAll = require("./utils/removeAll"),
removeAllFromStr = require("./utils/removeAll"),
validateRemovals = require("./utils/validateRemovals");
// PROMPTS ARE THE PROMPTS ARRAYS FOR VARIOUS QUESTIONS
const prompts = {
Expand All @@ -31,14 +31,14 @@ const doCustomLabelPrompts = require("./modules/doCustomLabelPrompts")(prompts.a


// Kicks things off, named so that it can be called at any time
const gitLabelmaker = (mainPromptCallback) => {
// Checks for three things at once, each will return a nice error obj if they fail
Promise.all([ isGitRepo(), readGitConfig(), fetchToken() ])
// The params will sometimes come thru if we've just set the token, so if we got them we alter the call a lil...
const gitLabelmaker = (token) => {
Promise.all([ isGitRepo(), readGitConfig(), fetchToken(token) ])
.then(( values )=>{
let repo = readRepo(values[1]);
let token = values[2];
let _repo = readRepo(values[1]);
let _token = values[2];
banner.welcome();
iq.prompt( prompts.mainMenu, mainPromptCallback.bind(null, repo, token));
iq.prompt( prompts.mainMenu, handleMainPrompts.bind(null, _repo, _token));
})
.catch((e)=>{
console.warn(e.err);
Expand Down Expand Up @@ -68,7 +68,7 @@ const addCustom = (repo, token) => {

// addFromPackage function
const addFromPackage = (repo, token, path) => {
gitLabel.find( removeAll( path, [ "`", '"', "'" ] ) )
gitLabel.find( removeAllFromStr( path, [ "`", '"', "'" ] ) )
.then((newLabels)=>{
return gitLabel.add( configGitLabel(repo, token), newLabels );
})
Expand All @@ -77,7 +77,7 @@ const addFromPackage = (repo, token, path) => {
};

// removeLabels function
const removeLabels = (repo, token, mainPromptCallback, answers) => {
const removeLabels = (repo, token, answers) => {
// Tell the user what they're about to lose
console.log("About to delete the following labels:");
alertDeletes(answers.removals);// alerts the list of labels to be removed
Expand All @@ -87,7 +87,7 @@ const removeLabels = (repo, token, mainPromptCallback, answers) => {
if ( confirmRemove.youSure ) {
return gitLabel.remove( configGitLabel(repo, token), answers.removals );
}
gitLabelmaker(mainPromptCallback);
gitLabelmaker();
})
.then(console.log)
.catch(console.warn);
Expand All @@ -96,6 +96,11 @@ const removeLabels = (repo, token, mainPromptCallback, answers) => {
// Callback for the main prompts, handles program flow
const handleMainPrompts = (repo, token, ans) => {
switch ( ans.main.toLowerCase() ) {
case "quit":
banner.seeYa();
process.exit(1);
break;

case "reset token":
resetToken();
break;
Expand All @@ -120,26 +125,35 @@ const handleMainPrompts = (repo, token, ans) => {

case "remove labels":
banner.removeLabels();
requestLabels(repo, token)
.then((labels)=>{
return prompt([{
name: "removals",
type: "checkbox",
message: "Which labels would you like to remove?",
choices: labels.map((label) => label.name),
validate: validateRemovals,
filter: filterRemovalLabels.bind(null, labels)
}]);
})
.then((answers)=>{
removeLabels(repo, token, handleMainPrompts, answers);
})
.catch(console.warn);
// If there are no labels to be removed then we can skip this part
requestLabels(repo, token)
.then((labels)=>{
if ( labels.length > 0 ){
return prompt([{
name: "removals",
type: "checkbox",
message: "Which labels would you like to remove?",
choices: labels.map((label) => label.name),
validate: validateRemovals,
filter: filterRemovalLabels.bind(null, labels)
}]);
} else {
return new Error("This repo has no labels to remove!");
}
})
.then((answers)=>{
if (answers.removals){
return removeLabels(repo, token, answers);
}
console.log(answers);
gitLabelmaker();
})
.catch(console.warn);
break;

default:
gitLabelmaker(handleMainPrompts);
gitLabelmaker();
}
};

gitLabelmaker(handleMainPrompts);
gitLabelmaker();
File renamed without changes.
46 changes: 46 additions & 0 deletions bin/modules/fetchToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Returns a promise that fetches the token and resolves with it if it's found
* @dep {node} fs
* @return {Promise}
*/
"use strict";
const fs = require("fs");
const prompt = require("./prompt");
const bcupPath = __dirname+"/../../.git-labelmaker.bcup";
const Buttercup = require("buttercup");
const err = (message) => {
return { id: "TOKEN", err: message }
};

module.exports = (rememberedToken) => {
return new Promise((res, rej) => {
if (rememberedToken){
return res(rememberedToken);
}
fs.exists(bcupPath, (exists) => {
if (!exists) {
rej(err("No token found!"));
} else {
prompt([{
type: "password",
name: "master_password",
message: "What is your master password?"
}])
.then((answer) => {
let datasource = new Buttercup.FileDatasource(bcupPath);
return datasource.load(answer.master_password)
})
.then((archive) => {
// This is only guaranteed to work on buttercup 0.14.0, awaiting PR in buttercup
let groups = archive.getGroups();
let group = groups.filter((g) => g._remoteObject.title === 'git-labelmaker')[0];
let token = group.getAttribute('token');
res(token);
})
.catch((e)=>{
console.error(err(e.message));
})
}
});
});
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions bin/modules/setToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Returns a promise that fetches the token and resolves with it if it's found
* @dep {node} fs
* @dep {npm} inquirer
* @param {Function} callback function
*/
"use strict";
const fs = require("fs");
const prompt = require("./prompt");
const bcupPath = __dirname+"/../../.git-labelmaker.bcup";
const Buttercup = require("buttercup");

const writeToken = (password, token) => {
return new Promise((res, rej) => {
let datasource = new Buttercup.FileDatasource(bcupPath);
let archive = Buttercup.Archive.createWithDefaults();
let group = archive.createGroup("git-labelmaker");
group.setAttribute('token', token);
datasource.save(archive, password);
res(token);
});
};

module.exports = (done) => {
prompt([{
type: "input",
name: "token",
message: "What is your GitHub Access Token?",
validate: (answer) => {
return (answer !== undefined && answer.length !== 0);
}
}, {
type: "password",
name: "master_password",
message: "What is your master password, to keep your access token secure?",
when: (answer) => {
return (answer.token !== undefined && answer.token.length !== 0);
}
}])
.then((answer) => {
return writeToken(answer.master_password, answer.token);
})
.then((token)=>{
done(token);
})
.catch(console.warn);
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion prompts/mainMenu.js → bin/prompts/mainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = [
type: "list",
name: "main",
message: "Welcome to git-labelmaker!\nWhat would you like to do?",
choices: [ "Add Custom Labels", "Add Labels From Package", "Remove Labels", "Reset Token" ]
choices: [ "Add Custom Labels", "Add Labels From Package", "Remove Labels", "Reset Token", "Quit" ]
}
];
File renamed without changes.
3 changes: 2 additions & 1 deletion utils/banners.js → bin/utils/banners.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ module.exports = {
addCustom: printBanner(" Adding Custom Labels "),
addFromPackage: printBanner(" Adding Labels From Package "),
removeLabels: printBanner(" Removing Labels "),
resetToken: printBanner(" Resetting Token ")
resetToken: printBanner(" Resetting Token "),
seeYa: printBanner(" See Ya! ")
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions modules/fetchToken.js

This file was deleted.

34 changes: 0 additions & 34 deletions modules/setToken.js

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "git-labelmaker",
"version": "0.6.0",
"version": "0.7.0",
"description": "Create git labels from the command line using git-label!",
"main": "index.js",
"scripts": {
"postpublish": "git push && git push --tag"
"test": "echo No tests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/himynameisdave/git-labelmaker.git"
},
"bin": {
"git-labelmaker": "index.js"
"git-labelmaker": "bin/index.js"
},
"engines": {
"node": ">= 4.0.0"
Expand All @@ -31,7 +31,7 @@
},
"homepage": "https://github.com/himynameisdave/git-labelmaker#readme",
"dependencies": {
"commander": "^2.9.0",
"buttercup": "0.14.0",
"git-label": "^4.1.1",
"github-url-from-git": "^1.4.0",
"inquirer": "^0.11.1",
Expand Down

0 comments on commit 2837a85

Please sign in to comment.