From 1be88e6d48701837c162846dd3c8a9774e2b1e64 Mon Sep 17 00:00:00 2001 From: Simon Boudrias Date: Sun, 5 Mar 2017 13:49:29 +0800 Subject: [PATCH] Remove callback API from Genrator#github.username() in favor of Promise one - ref #1006 --- lib/actions/user.js | 17 ++++++----------- test/user.js | 5 ++--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/actions/user.js b/lib/actions/user.js index aa7d557a..bfcf6ea5 100644 --- a/lib/actions/user.js +++ b/lib/actions/user.js @@ -17,6 +17,7 @@ user.github = {}; /** * Retrieves user's name from Git in the global scope or the project scope * (it'll take what Git will use in the current context) + * @return {String} configured git name or undefined */ user.git.name = () => { let name = nameCache.get(process.cwd()); @@ -36,6 +37,7 @@ user.git.name = () => { /** * Retrieves user's email from Git in the global scope or the project scope * (it'll take what Git will use in the current context) + * @return {String} configured git email or undefined */ user.git.email = () => { let email = emailCache.get(process.cwd()); @@ -54,16 +56,9 @@ user.git.email = () => { /** * Retrieves GitHub's username from the GitHub API + * @return {Promise} Resolved with the github username or rejected if unable to + * get the information */ -user.github.username = cb => { - const promise = githubUsername(user.git.email()); - - if (cb) { - promise.then( - val => cb(null, val), - err => cb(err) - ); - } - - return promise; +user.github.username = () => { + return githubUsername(user.git.email()); }; diff --git a/test/user.js b/test/user.js index a4ce0333..51ec2946 100644 --- a/test/user.js +++ b/test/user.js @@ -104,10 +104,9 @@ describe('Base#user', () => { nock.restore(); }); - it('is the username used by GitHub', function (done) { - this.user.github.username((_, res) => { + it('is the username used by GitHub', function () { + return this.user.github.username().then(res => { assert.equal(res, 'mockname'); - done(); }); }); });