-
Notifications
You must be signed in to change notification settings - Fork 34
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 #25 from himynameisdave/v0.7.0
v0.7.0
- Loading branch information
Showing
24 changed files
with
146 additions
and
91 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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 @@ | ||
/** | ||
* 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.
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,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.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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