From 4c0a2fefa15c5c75bf789d78d43ae196c698410a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aper=C3=A7u?= Date: Tue, 13 Oct 2015 23:19:02 +0200 Subject: [PATCH] fix(core): reactive flow --- api/services/github.service.js | 40 +++++++++++----------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/api/services/github.service.js b/api/services/github.service.js index ec77938..1b1a3b6 100644 --- a/api/services/github.service.js +++ b/api/services/github.service.js @@ -39,6 +39,9 @@ exports.addUserToOrg = (user, org) => { return q.reject(new Error('Invalid organization.')); } + const userGithub = new Github({ version: '3.0.0', debug: true }); + userGithub.authenticate({ type: 'oauth', token: user.token }); + return user.save() .then(() => { return q.nfcall( @@ -47,33 +50,16 @@ exports.addUserToOrg = (user, org) => { ); }) .then(() => { - - /* - - const userGithub = new Github({ version: '3.0.0', debug: true }); - userGithub.authenticate({ type: 'oauth', token: user.token }); - - userGithub.user.listOrganizationMembership({ org: 'KeyCode-5', user: user.name }, function (err, res) { - console.log(err, res); - }); - - userGithub.orgs.publicizeMembership({ org: 'KeyCode-5', user: user.name }, function (err, res) { - console.log(err, res); - }); - userGithub.user.editOrganizationMembership({ org: 'KeyCode-5', state: 'active' }, (err, res) => { - console.log(err, res); - }); - - github.orgs.addTeamMember({ id: config.orgIds[org], user: user.name }, (err, res) => { - console.log(err, res); - }); - - userGithub.user.listOrganizationMembership({ org: 'KeyCode-5', user: user.name }, function (err, res) { - console.log(err, res); - }); - - */ - return null; + return q.nfcall( + userGithub.user.editOrganizationMembership, + { org: `KeyCode-${org}`, state: 'active' } + ); + }) + .then(() => { + return q.nfcall( + userGithub.orgs.publicizeMembership, + { org: `KeyCode-${org}`, user: user.name } + ); }); };