From 34253397bbd4f68d94783918e86e9faf29ea318b Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Wed, 14 Sep 2016 11:31:47 -0400 Subject: [PATCH 1/9] Extract branch from repo url --- src/scripts/deploy.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scripts/deploy.js b/src/scripts/deploy.js index 40cf881..67d6b43 100644 --- a/src/scripts/deploy.js +++ b/src/scripts/deploy.js @@ -293,9 +293,13 @@ const sortRegisterInput = (input1, input2) => { const deploy = (app, appGuid, spaceGuid, spaceName, robot, res) => { - const urlTokens = app.url.split('/'); + const regex = /(.*)\/tree\/(.*)/; + const match = regex.exec(app.url); + const urlTokens = match !== null ? match[1] : app.url.split('/'); + const branch = match !== null ? match[2] : undefined; const reponame = urlTokens.pop(); const repoowner = urlTokens.pop(); + let domain = ''; let appZip; let applicationGuid; @@ -317,7 +321,7 @@ const deploy = (app, appGuid, spaceGuid, spaceName, robot, res) => { } robot.logger.info(`${TAG}: Beginning deployment steps for ${app.app} ...`); - getUserRepo(robot, domain, repoowner, reponame) + getUserRepo(robot, domain, repoowner, reponame, branch) .then((bf) => { let message = i18n.__('github.deploy.obtaining.zip', app.app); robot.emit('ibmcloud.formatter', { response: res, message: message}); From ee274e3c99fd17bca62eeb7382b8fdc591de5680 Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 09:10:15 -0400 Subject: [PATCH 2/9] Prompt user for branch --- src/messages/en.json | 3 +- src/scripts/deploy.js | 201 +++++++++++++++++++++++++----------------- 2 files changed, 120 insertions(+), 84 deletions(-) diff --git a/src/messages/en.json b/src/messages/en.json index 899861c..748fffe 100644 --- a/src/messages/en.json +++ b/src/messages/en.json @@ -9,7 +9,7 @@ "github.deploy.app.select": "Which app would you like to deploy? Here are the ones I know about:", "github.deploy.failure": "Sorry, I tried my best.", - "github.deploy.in.progress": "Deploying *%s* from master branch of %s.", + "github.deploy.in.progress": "Deploying *%s* from *%s* branch of %s.", "github.deploy.in.progress.matching": "Deploying matching apps.", "github.deploy.started": "Deployment *%s* has been started.", "github.deploy.name.invalid": "You didn't give me a valid app name. I would love to do something with this, but I cannot.", @@ -38,6 +38,7 @@ "github.deploy.error": "A deployment error occurred for app *%s*: %s.", "github.deploy.manifest.error": "Invalid manifest.yml file for app *%s*.", "github.deploy.route.error": "Error adding route to the application: *%s*.", + "github.deploy.branch.prompt": "Which *branch* would you like to deploy?", "help.github.deploy": "Deployment setup with prompts for application and GitHub URL.", "help.github.deploy.app": "Deployment setup for , or prompt you to provide a GitHub URL to deploy to .", diff --git a/src/scripts/deploy.js b/src/scripts/deploy.js index 67d6b43..79e40f6 100644 --- a/src/scripts/deploy.js +++ b/src/scripts/deploy.js @@ -59,7 +59,7 @@ module.exports = function(robot) { if (parameters && parameters.appname) { if (parameters && parameters.url) { const entry = { app: parameters.appname, url: parameters.url }; - processAppDeploy(robot, res, entry); + processAppDeploy(robot, res, switchBoard, entry); } else { robot.logger.error(`${TAG}: Error extracting repository from text [${res.message.text}].`); @@ -106,21 +106,23 @@ module.exports = function(robot) { let prompt = i18n.__('github.deploy.name.confirm', entry.app, entry.url); let negativeResponse = i18n.__('github.deploy.failure'); utils.getConfirmedResponse(res, switchBoard, prompt, negativeResponse).then((dialogResult) => { - let message = i18n.__('github.deploy.in.progress', entry.app, entry.url); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - apps[entry.app] = entry.url; - // update brain - robot.brain.set('github-apps', apps); + getEntry(robot, res, switchBoard, entry).then(entry => { + let message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); + robot.emit('ibmcloud.formatter', { response: res, message: message}); + apps[entry.app] = entry.url; + // update brain + robot.brain.set('github-apps', apps); - robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); - const activeSpace = cf.activeSpace(robot, res); - cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { - robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); - deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); - }) - .catch((err) => { - robot.logger.error(`${TAG}: An error occurred.`); - robot.logger.error(err); + robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); + const activeSpace = cf.activeSpace(robot, res); + cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { + robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); + deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); + }) + .catch((err) => { + robot.logger.error(`${TAG}: An error occurred.`); + robot.logger.error(err); + }); }); }); } @@ -143,17 +145,20 @@ module.exports = function(robot) { let prompt = i18n.__('github.deploy.app.select'); utils.getExpectedResponse(res, robot, switchBoard, prompt, expr).then((response) => { let chosenApp = response.match[1]; - let message = i18n.__('github.deploy.in.progress', chosenApp, apps[app]); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - const activeSpace = cf.activeSpace(robot, res); - robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${chosenApp}.`); - cf.Apps.getApp(chosenApp, activeSpace.guid).then((result) => { - robot.logger.info(`${TAG}: cf library returned with app info for ${chosenApp}.`); - deploy({ app: chosenApp, url: apps[app] }, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); - }) - .catch((err) => { - robot.logger.error(`${TAG}: An error occurred.`); - robot.logger.error(err); + const entry = {app: chosenApp, url: apps[chosenApp]}; + getEntry(robot, res, switchBoard, entry).then(entry => { + let message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); + robot.emit('ibmcloud.formatter', { response: res, message: message}); + const activeSpace = cf.activeSpace(robot, res); + robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); + cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { + robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); + deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); + }) + .catch((err) => { + robot.logger.error(`${TAG}: An error occurred.`); + robot.logger.error(err); + }); }); }); @@ -181,23 +186,25 @@ module.exports = function(robot) { utils.getConfirmedResponse(res, switchBoard, prompt, negativeResponse).then((dialogResult) => { let prompt = i18n.__('github.deploy.name.prompt'); utils.getExpectedResponse(res, robot, switchBoard, prompt, /(.*)/i).then((nameRes) => { - const name = nameRes.match[1]; - let message = i18n.__('github.deploy.register.in.progress', name, input); + const entry = {app: nameRes.match[1], url: input}; + let message = i18n.__('github.deploy.register.in.progress', entry.app, entry.url); robot.emit('ibmcloud.formatter', { response: res, message: message}); - apps[name] = input; + apps[entry.app] = entry.url; // update brain robot.brain.set('github-apps', apps); - message = i18n.__('github.deploy.in.progress', name, input); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - const activeSpace = cf.activeSpace(robot, res); - robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${name}.`); - cf.Apps.getApp(name, activeSpace.guid).then((result) => { - robot.logger.info(`${TAG}: cf library returned with app info for ${name}.`); - deploy({ app: name, url: input }, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); - }) - .catch((err) => { - robot.logger.error(`${TAG}: An error occurred.`); - robot.logger.error(err); + getEntry(robot, res, switchBoard, entry).then(entry => { + message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); + robot.emit('ibmcloud.formatter', { response: res, message: message}); + const activeSpace = cf.activeSpace(robot, res); + robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); + cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { + robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); + deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); + }) + .catch((err) => { + robot.logger.error(`${TAG}: An error occurred.`); + robot.logger.error(err); + }); }); }); }); @@ -231,17 +238,19 @@ module.exports = function(robot) { const entry = { app: input, url: url }; // upsert into apps object apps[entry.app] = entry.url; - let message = i18n.__('github.deploy.in.progress', entry.app, entry.url); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - const activeSpace = cf.activeSpace(robot, res); - robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); - cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { - robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); - deploy({ app: input, url: url }, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); - }) - .catch((err) => { - robot.logger.error(`${TAG}: An error occurred.`); - robot.logger.error(err); + getEntry(robot, res, switchBoard, entry).then(entry => { + let message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); + robot.emit('ibmcloud.formatter', { response: res, message: message}); + const activeSpace = cf.activeSpace(robot, res); + robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); + cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { + robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); + deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); + }) + .catch((err) => { + robot.logger.error(`${TAG}: An error occurred.`); + robot.logger.error(err); + }); }); } }); @@ -251,17 +260,20 @@ module.exports = function(robot) { let message = i18n.__('github.deploy.in.progress.matching'); robot.emit('ibmcloud.formatter', { response: res, message: message}); matchingApps.forEach((app) => { - let message = i18n.__('github.deploy.in.progress', app, apps[app]); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - const activeSpace = cf.activeSpace(robot, res); - robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${app}.`); - cf.Apps.getApp(app, activeSpace.guid).then((result) => { - robot.logger.info(`${TAG}: cf library returned with app info for ${app}.`); - deploy({ app: app, url: apps[app] }, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); - }) - .catch((err) => { - robot.logger.error(`${TAG}: An error occurred.`); - robot.logger.error(err); + const entry = {app: app, url: apps[app]}; + getEntry(robot, res, switchBoard, entry).then(entry => { + let message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); + robot.emit('ibmcloud.formatter', { response: res, message: message}); + const activeSpace = cf.activeSpace(robot, res); + robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); + cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { + robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); + deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); + }) + .catch((err) => { + robot.logger.error(`${TAG}: An error occurred.`); + robot.logger.error(err); + }); }); }); } @@ -270,10 +282,11 @@ module.exports = function(robot) { }); robot.respond(/deploy\s+(\S+)\s+(\S+)$/i, {id: 'github.deploy'}, (res) => { + console.log("YOU ARE HERE LALALLALALALALA"); robot.logger.debug(`${TAG}: res.message.text=${res.message.text}.`); const entry = sortRegisterInput(res.match[1], res.match[2]); - processAppDeploy(robot, res, entry); + processAppDeploy(robot, res, switchBoard, entry); }); }; @@ -293,10 +306,10 @@ const sortRegisterInput = (input1, input2) => { const deploy = (app, appGuid, spaceGuid, spaceName, robot, res) => { - const regex = /(.*)\/tree\/(.*)/; - const match = regex.exec(app.url); - const urlTokens = match !== null ? match[1] : app.url.split('/'); - const branch = match !== null ? match[2] : undefined; + console.log(app); + + const urlTokens = app.url.split('/'); + const branch = app.branch; const reponame = urlTokens.pop(); const repoowner = urlTokens.pop(); @@ -584,7 +597,8 @@ function asyncGet(robot, url) { }); }; -function processAppDeploy(robot, res, entry){ +function processAppDeploy(robot, res, switchBoard, entry){ + console.log('AN NOW HERE'); let apps = robot.brain.get('github-apps') || {}; if (!entry) { @@ -592,21 +606,42 @@ function processAppDeploy(robot, res, entry){ robot.emit('ibmcloud.formatter', { response: res, message: message}); } else { - // upsert - apps[entry.app] = entry.url; - - // get to deployment - let message = i18n.__('github.deploy.in.progress', entry.app, entry.url); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - const activeSpace = cf.activeSpace(robot, res); - robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); - cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { - robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); - deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); - }) - .catch((err) => { - robot.logger.error(`${TAG}: An error occurred.`); - robot.logger.error(err); + getEntry(robot, res, switchBoard, entry).then(entry => { + // upsert + apps[entry.app] = entry.url; + // get to deployment + let message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); + robot.emit('ibmcloud.formatter', { response: res, message: message}); + const activeSpace = cf.activeSpace(robot, res); + robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); + cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { + robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); + deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); + }) + .catch((err) => { + robot.logger.error(`${TAG}: An error occurred.`); + robot.logger.error(err); + }); }); } } + +function getEntry(robot, res, switchBoard, entry) { + return new Promise((resolve, reject) => { + const regex = /(.*)\/tree\/(.*)/; + const match = regex.exec(entry.url); + entry.branch = match !== null ? match[2] : undefined; + entry.url = match !== null ? match[1] : entry.url; + + if (entry.branch) { + resolve(entry); + } + else { + let prompt = i18n.__('github.deploy.branch.prompt'); + utils.getExpectedResponse(res, robot, switchBoard, prompt, /(?:\S+\s+){1}(\S+)/i).then((branchRes) => { + entry.branch = branchRes.match[1]; + resolve(entry); + }); + } + }); +} From 4872b4be98bcd52d190804c2922d5a3008015aae Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 09:11:09 -0400 Subject: [PATCH 3/9] Remove console logs --- src/scripts/deploy.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/scripts/deploy.js b/src/scripts/deploy.js index 79e40f6..0928c0d 100644 --- a/src/scripts/deploy.js +++ b/src/scripts/deploy.js @@ -282,7 +282,6 @@ module.exports = function(robot) { }); robot.respond(/deploy\s+(\S+)\s+(\S+)$/i, {id: 'github.deploy'}, (res) => { - console.log("YOU ARE HERE LALALLALALALALA"); robot.logger.debug(`${TAG}: res.message.text=${res.message.text}.`); const entry = sortRegisterInput(res.match[1], res.match[2]); @@ -305,9 +304,6 @@ const sortRegisterInput = (input1, input2) => { }; const deploy = (app, appGuid, spaceGuid, spaceName, robot, res) => { - - console.log(app); - const urlTokens = app.url.split('/'); const branch = app.branch; const reponame = urlTokens.pop(); @@ -598,7 +594,6 @@ function asyncGet(robot, url) { }; function processAppDeploy(robot, res, switchBoard, entry){ - console.log('AN NOW HERE'); let apps = robot.brain.get('github-apps') || {}; if (!entry) { From 4b4529ecea99e3f8beee828b37d8df9891dba2cf Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 10:06:14 -0400 Subject: [PATCH 4/9] Updated tests to include branch prompt --- test/bluemix.github.deploy.cognitive.test.js | 10 +++- test/bluemix.github.deploy.test.js | 51 +++++++++++++++++--- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/test/bluemix.github.deploy.cognitive.test.js b/test/bluemix.github.deploy.cognitive.test.js index 1fdab5e..eda82d5 100644 --- a/test/bluemix.github.deploy.cognitive.test.js +++ b/test/bluemix.github.deploy.cognitive.test.js @@ -66,14 +66,20 @@ describe('Interacting with Deploy via NLS', function() { }); context('user calls `I want to deploy my application`', function() { + let replyFn = function(msg) { + if (msg.indexOf('Which *branch* would you like to deploy?') >= 0) { + return room.user.say('anId', '@hubot master'); + } + }; + it('should respond with the application deploy', function(done) { room.robot.on('ibmcloud.formatter', (event) => { expect(event.message).to.be.a('string'); - expect(event.message).to.contain(i18n.__('github.deploy.in.progress', 'node-helloworld', 'normanb/node-helloworld')); + expect(event.message).to.contain(i18n.__('github.deploy.in.progress', 'node-helloworld', 'master', 'normanb/node-helloworld')); done(); }); - const res = { message: {text: 'start application deployment', user: {id: 'anId'}}, response: room }; + const res = { message: {text: 'start application deployment', user: {id: 'anId'}}, response: room, reply: replyFn }; room.robot.emit('github.deploy', res, {appname: 'node-helloworld', url: 'normanb/node-helloworld'}); }); }); diff --git a/test/bluemix.github.deploy.test.js b/test/bluemix.github.deploy.test.js index 79a0979..006882a 100644 --- a/test/bluemix.github.deploy.test.js +++ b/test/bluemix.github.deploy.test.js @@ -114,7 +114,12 @@ describe('Interacting with Bluemix via Slack', function() { return room.user.say('mimiron', '@hubot node-helloworld'); }).then(() => { expect(room.messages.length).to.eql(5); - expect(room.messages[4]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'normanb/node-helloworld')}`]); + expect(room.messages[4][1]).to.be.a('String'); + expect(room.messages[4]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(7); + expect(room.messages[6]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'master', 'normanb/node-helloworld')}`]); }); }); }); @@ -154,12 +159,22 @@ describe('Interacting with Bluemix via Slack', function() { return room.user.say('mimiron', '@hubot deploy normanb/node-helloworld node-helloworld').then(() => { expect(room.messages.length).to.eql(2); expect(room.messages[1][1]).to.be.a('String'); - expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'normanb/node-helloworld')}`]); - return room.user.say('mimiron', '@hubot deploy node-helloworld normanb/node-helloworld'); + expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); }).then(() => { expect(room.messages.length).to.eql(4); expect(room.messages[3][1]).to.be.a('String'); - expect(room.messages[3]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'normanb/node-helloworld')}`]); + expect(room.messages[3]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'master', 'normanb/node-helloworld')}`]); + return room.user.say('mimiron', '@hubot deploy node-helloworld normanb/node-helloworld'); + }).then(() => { + expect(room.messages.length).to.eql(8); + expect(room.messages[7][1]).to.be.a('String'); + expect(room.messages[7]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(10); + expect(room.messages[9][1]).to.be.a('String'); + expect(room.messages[9]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'master', 'normanb/node-helloworld')}`]); }); }); }); @@ -230,7 +245,12 @@ describe('Interacting with Bluemix via Slack', function() { expect(room.messages[1][1]).to.be.a('String'); expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress.matching')}`]); expect(room.messages[2][1]).to.be.a('String'); - expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'normanb/node-helloworld')}`]); + expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(5); + expect(room.messages[4][1]).to.be.a('String'); + expect(room.messages[4]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'master', 'normanb/node-helloworld')}`]); }); }); }); @@ -247,7 +267,12 @@ describe('Interacting with Bluemix via Slack', function() { return room.user.say('mimiron', 'helloworld'); }).then(() => { expect(room.messages.length).to.eql(7); - expect(room.messages[6]).to.eql(['hubot', '@mimiron ' + i18n.__('github.deploy.in.progress', 'helloworld', 'user/helloworld')]); + expect(room.messages[6][1]).to.be.a('String'); + expect(room.messages[6]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(9); + expect(room.messages[8]).to.eql(['hubot', '@mimiron ' + i18n.__('github.deploy.in.progress', 'helloworld', 'master', 'user/helloworld')]); }); }); }); @@ -268,7 +293,12 @@ describe('Interacting with Bluemix via Slack', function() { expect(room.messages[1][1]).to.be.a('String'); expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress.matching')}`]); expect(room.messages[2][1]).to.be.a('String'); - expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'manifestTest', 'user/manifestTest')}`]); + expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(5); + expect(room.messages[4][1]).to.be.a('String'); + expect(room.messages[4]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'manifestTest', 'master', 'user/manifestTest')}`]); }); }); }); @@ -289,7 +319,12 @@ describe('Interacting with Bluemix via Slack', function() { expect(room.messages[1][1]).to.be.a('String'); expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress.matching')}`]); expect(room.messages[2][1]).to.be.a('String'); - expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'manifestTestNoApp', 'user/manifestTestNoApp')}`]); + expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(5); + expect(room.messages[4][1]).to.be.a('String'); + expect(room.messages[4]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'manifestTestNoApp', 'master', 'user/manifestTestNoApp')}`]); }); }); }); From a3525d5edcc0c7736a133b66444a93c06faa539b Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 12:06:47 -0400 Subject: [PATCH 5/9] List repo branches --- package.json | 3 ++- src/lib/github.js | 24 ++++++++++++++++++ src/scripts/deploy.js | 57 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 src/lib/github.js diff --git a/package.json b/package.json index 568a1ca..07baf3f 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,8 @@ ], "dependencies": { "adm-zip": "^0.4.7", - "yamljs": "^0.2.8" + "yamljs": "^0.2.8", + "github": "^3.0.0" }, "config": { "commitizen": { diff --git a/src/lib/github.js b/src/lib/github.js new file mode 100644 index 0000000..d1b245d --- /dev/null +++ b/src/lib/github.js @@ -0,0 +1,24 @@ + +/* + * Licensed Materials - Property of IBM + * (C) Copyright IBM Corp. 2016. All Rights Reserved. + * US Government Users Restricted Rights - Use, duplication or + * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. + */ +'use strict'; + +const Github = require('github'); + +const gh = new Github({ + version: '3.0.0', + host: process.env.HUBOT_GITHUB_DOMAIN || 'api.github.com' +}); + +if (process.env.HUBOT_GITHUB_TOKEN) { + gh.authenticate({ + type: 'token', + token: process.env.HUBOT_GITHUB_TOKEN + }); +} + +module.exports = gh; diff --git a/src/scripts/deploy.js b/src/scripts/deploy.js index 0928c0d..7ff6e12 100644 --- a/src/scripts/deploy.js +++ b/src/scripts/deploy.js @@ -7,11 +7,18 @@ // HUBOT_BLUEMIX_SPACE Bluemix space // HUBOT_BLUEMIX_USER Bluemix User ID // HUBOT_BLUEMIX_PASSWORD Password for the Bluemix User +// HUBOT_GITHUB_TOKEN Github API Auth token // // Commands: -// hubot deploy help - Show available commands in the deploy category. +// hubot deploy help - Show available commands in the deploy category. +// hubot deploy - Deployment setup with prompts for application, GitHub URL and branch. +// hubot deploy - Deployment setup for app, or prompt you to provide a GitHub URL and branch to depoy to. +// hubot deploy - Deployment setup for url and prompt you for the Bluemix application name and branch. +// hubot deploy - Deployment of app with url, prompt for branch if not provided. +// // Author: // aeweidne +// reicruz // 'use strict'; @@ -24,6 +31,7 @@ const AdmZip = require('adm-zip'); const fs = require('fs'); const path = require('path'); const YAML = require('yamljs'); +const github = require('../lib/github'); const TAG = path.basename(__filename); @@ -304,10 +312,9 @@ const sortRegisterInput = (input1, input2) => { }; const deploy = (app, appGuid, spaceGuid, spaceName, robot, res) => { - const urlTokens = app.url.split('/'); const branch = app.branch; - const reponame = urlTokens.pop(); - const repoowner = urlTokens.pop(); + const reponame = app.repo; + const repoowner = app.user; let domain = ''; let appZip; @@ -628,14 +635,48 @@ function getEntry(robot, res, switchBoard, entry) { entry.branch = match !== null ? match[2] : undefined; entry.url = match !== null ? match[1] : entry.url; + const urlTokens = entry.url.split('/'); + entry.repo = urlTokens.pop(); + entry.user = urlTokens.pop(); + if (entry.branch) { resolve(entry); } else { - let prompt = i18n.__('github.deploy.branch.prompt'); - utils.getExpectedResponse(res, robot, switchBoard, prompt, /(?:\S+\s+){1}(\S+)/i).then((branchRes) => { - entry.branch = branchRes.match[1]; - resolve(entry); + github.repos.getBranches({ + user: entry.user, + repo: entry.repo + }, (err, branches) => { + if (!err) { + if (branches.length === 1) { + entry.branch = branches[0].name; + resolve(entry); + } + else { + const regex = utils.generateRegExpForNumberedList(branches.length + 1); + let prompt = i18n.__('github.deploy.branch.prompt') + '\n'; + for (let i = 0; i < branches.length; i++) { + prompt += `(${i + 1}) ${branches[i].name}\n`; + } + utils.getExpectedResponse(res, robot, switchBoard, prompt, regex).then((result) => { + let response = result.match[1]; + let resNum = parseInt(response, 10); + entry.branch = branches[resNum - 1].name; + resolve(entry); + }).catch((err) => { + reject(err); + }); + } + } + else { + let prompt = i18n.__('github.deploy.branch.prompt'); + utils.getExpectedResponse(res, robot, switchBoard, prompt, /(?:\S+\s+){1}(\S+)/i).then((branchRes) => { + entry.branch = branchRes.match[1]; + resolve(entry); + }).catch((err) => { + reject(err); + }); + } }); } }); From f174452198a1a7dd8be943e44463e304e01a41c6 Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 12:12:25 -0400 Subject: [PATCH 6/9] Update readme to include branch info --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 44fbdfe..e5fcae2 100644 --- a/README.md +++ b/README.md @@ -30,16 +30,19 @@ If you are new to Hubot visit the [getting started](https://hubot.github.com/doc HUBOT_BLUEMIX_SPACE= HUBOT_BLUEMIX_USER= HUBOT_BLUEMIX_PASSWORD= + HUBOT_GITHUB_TOKEN= (optional) + HUBOT_GITHUB_DOMAIN= (optional) 5. Start up your bot & off to the races! ## Commands -- `hubot deploy` - Deployment setup with prompts for application and GitHub URL. -- `hubot deploy ` - Deployment setup for , or prompt you to provide a GitHub URL to deploy to . -- `hubot deploy ` - Deployment setup for and prompt you for the Bluemix application name. -- `hubot deploy ` - Deployment of as on Bluemix. -- `hubot deploy help`- Show available deploy commands. +- `hubot deploy` - Deployment setup with prompts for application, GitHub URL and branch. +- `hubot deploy ` - Deployment setup for app, or prompt you to provide a GitHub URL and branch to depoy to. +- `hubot deploy ` - Deployment setup for url and prompt you for the Bluemix application name and branch. +- `hubot deploy ` - Deployment of app with url, prompt for branch if not provided. +- `hubot deploy help` - Show available commands in the deploy category. + Your github repository should contain a `manifest.yml` that describes the deployment of the application. More information about application deployment and manifest files can be read here: https://console.ng.bluemix.net/docs/manageapps/depapps.html#deployingapps @@ -68,6 +71,8 @@ Please refer to the [CONTRIBUTING.md](https://github.com/ibm-cloud-solutions/hub export HUBOT_BLUEMIX_SPACE= export HUBOT_BLUEMIX_USER= export HUBOT_BLUEMIX_PASSWORD= + export HUBOT_GITHUB_TOKEN= (optional) + export HUBOT_GITHUB_DOMAIN= (optional) 3. In order to view content in chat clients you will need to add `hubot-ibmcloud-formatter` to your `external-scripts.json` file. Additionally, if you want to use `hubot-help` to make sure your command documentation is correct. Create `external-scripts.json` in the root of this project, with the following contents: From 80fbfa38756cad7e207d3fb6022e68742d84b2ab Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 14:07:39 -0400 Subject: [PATCH 7/9] Added more tests to cover branch changes --- src/scripts/deploy.js | 49 +++++++++------------ test/bluemix.github.deploy.test.js | 70 +++++++++++++++++++++++++++--- test/mock.utils.gh.js | 25 +++++++++-- test/resources/mock.branches.json | 29 +++++++++++++ 4 files changed, 134 insertions(+), 39 deletions(-) create mode 100644 test/resources/mock.branches.json diff --git a/src/scripts/deploy.js b/src/scripts/deploy.js index 7ff6e12..2ce6e80 100644 --- a/src/scripts/deploy.js +++ b/src/scripts/deploy.js @@ -106,34 +106,28 @@ module.exports = function(robot) { let prompt = i18n.__('github.deploy.prompt.name'); utils.getExpectedResponse(res, robot, switchBoard, prompt, /(.+\/.+)\s(.+)/i).then((registerRes) => { const entry = sortRegisterInput(registerRes.match[1], registerRes.match[2]); - if (!entry) { - let message = i18n.__('github.deploy.repo.invalid'); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - } - else { - let prompt = i18n.__('github.deploy.name.confirm', entry.app, entry.url); - let negativeResponse = i18n.__('github.deploy.failure'); - utils.getConfirmedResponse(res, switchBoard, prompt, negativeResponse).then((dialogResult) => { - getEntry(robot, res, switchBoard, entry).then(entry => { - let message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); - robot.emit('ibmcloud.formatter', { response: res, message: message}); - apps[entry.app] = entry.url; - // update brain - robot.brain.set('github-apps', apps); - - robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); - const activeSpace = cf.activeSpace(robot, res); - cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { - robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); - deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); - }) - .catch((err) => { - robot.logger.error(`${TAG}: An error occurred.`); - robot.logger.error(err); - }); + let prompt = i18n.__('github.deploy.name.confirm', entry.app, entry.url); + let negativeResponse = i18n.__('github.deploy.failure'); + utils.getConfirmedResponse(res, switchBoard, prompt, negativeResponse).then((dialogResult) => { + getEntry(robot, res, switchBoard, entry).then(entry => { + let message = i18n.__('github.deploy.in.progress', entry.app, entry.branch, entry.url); + robot.emit('ibmcloud.formatter', { response: res, message: message}); + apps[entry.app] = entry.url; + // update brain + robot.brain.set('github-apps', apps); + + robot.logger.info(`${TAG}: Asynch call using cf library to obtain application data for ${entry.app}.`); + const activeSpace = cf.activeSpace(robot, res); + cf.Apps.getApp(entry.app, activeSpace.guid).then((result) => { + robot.logger.info(`${TAG}: cf library returned with app info for ${entry.app}.`); + deploy(entry, result ? result.metadata.guid : undefined, activeSpace.guid, activeSpace.name, robot, res); + }) + .catch((err) => { + robot.logger.error(`${TAG}: An error occurred.`); + robot.logger.error(err); }); }); - } + }); }); }); } @@ -537,9 +531,6 @@ const printHelp = (res, robot) => { const getUserRepo = (robot, domain, repoowner, reponame, branch) => { let gitBranch = branch; - if (!branch) { - gitBranch = 'master'; - } let url = `https://${domain}/${repoowner}/${reponame}/archive/${gitBranch}.zip`; robot.logger.info(`${TAG}: Obtaining application code from ${url}.`); diff --git a/test/bluemix.github.deploy.test.js b/test/bluemix.github.deploy.test.js index 006882a..b12ca19 100644 --- a/test/bluemix.github.deploy.test.js +++ b/test/bluemix.github.deploy.test.js @@ -195,11 +195,17 @@ describe('Interacting with Bluemix via Slack', function() { return room.user.say('mimiron', 'yes'); }).then(() => { expect(room.messages.length).to.eql(10); + expect(room.messages[9][1]).to.be.a('String'); + expect(room.messages[9]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(12); + expect(room.messages[11]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'node-helloworld', 'master', 'normanb/node-helloworld')}`]); }); }); context('user calls `deploy app`', function() { - it('should respond with the deploy steps and fail', function() { + it('should respond with the deploy steps', function() { return room.user.say('mimiron', '@hubot deploy app1').then(() => { expect(room.messages.length).to.eql(3); expect(room.messages[1][1]).to.be.a('String'); @@ -209,6 +215,14 @@ describe('Interacting with Bluemix via Slack', function() { expect(room.messages[4]).to.eql(['hubot', '@mimiron ' + i18n.__('general.awesome')]); expect(room.messages[5]).to.eql(['hubot', '@mimiron ' + i18n.__('github.deploy.repo.name.prompt')]); return room.user.say('mimiron', 'user/helloworld'); + }).then(() => { + expect(room.messages.length).to.eql(8); + expect(room.messages[7][1]).to.be.a('String'); + expect(room.messages[7]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + return room.user.say('mimiron', '@hubot master'); + }).then(() => { + expect(room.messages.length).to.eql(10); + expect(room.messages[9]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'app1', 'master', 'user/helloworld')}`]); }); }); @@ -277,6 +291,15 @@ describe('Interacting with Bluemix via Slack', function() { }); }); + context('user calls `deploy url` with branch', function() { + it('should respond with the deploy steps', function() { + return room.user.say('mimiron', '@hubot deploy app user/helloworld/tree/master').then(() => { + expect(room.messages.length).to.eql(2); + expect(room.messages[1]).to.eql(['hubot', '@mimiron ' + i18n.__('github.deploy.in.progress', 'app', 'master', 'user/helloworld')]); + }); + }); + }); + context('user calls `deploy app` with a zip and it exists', function() { beforeEach(function() { room.robot.brain.set('github-apps', { @@ -293,12 +316,32 @@ describe('Interacting with Bluemix via Slack', function() { expect(room.messages[1][1]).to.be.a('String'); expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress.matching')}`]); expect(room.messages[2][1]).to.be.a('String'); - expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); - return room.user.say('mimiron', '@hubot master'); - }).then(() => { - expect(room.messages.length).to.eql(5); - expect(room.messages[4][1]).to.be.a('String'); - expect(room.messages[4]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'manifestTest', 'master', 'user/manifestTest')}`]); + expect(room.messages[2]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'manifestTest', 'master', 'user/manifestTest')}`]); + }); + }); + }); + + context('user calls `deploy app` with a zip and it exists with multiple Branches', function() { + beforeEach(function() { + room.robot.brain.set('github-apps', { + manifestTest: 'user/manifestTestMultipleBranches' + }); + }); + afterEach(function() { + room.robot.brain.remove('github-apps'); + }); + + it('should respond with list of branches to select from', function() { + return room.user.say('mimiron', '@hubot deploy manifestTest').then(() => { + expect(room.messages.length).to.eql(3); + expect(room.messages[1][1]).to.be.a('String'); + expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress.matching')}`]); + expect(room.messages[2][1]).to.be.a('String'); + expect(room.messages[2][1]).to.contain(i18n.__('github.deploy.branch.prompt')); + return room.user.say('mimiron', '@hubot 2').then(() => { + expect(room.messages.length).to.eql(5); + expect(room.messages[4]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress', 'manifestTest', 'test-branch', 'user/manifestTestMultipleBranches')}`]); + }); }); }); }); @@ -329,4 +372,17 @@ describe('Interacting with Bluemix via Slack', function() { }); }); + // context('user calls `deploy app` with a zip for new app', function() { + // + // it.only('should respond with the apps that it will deploy with zip', function() { + // return room.user.say('mimiron', '@hubot deploy manifestTest user/manifestTest').then(() => { + // expect(room.messages.length).to.eql(2); + // expect(room.messages[1][1]).to.be.a('String'); + // expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress.matching')}`]); + // expect(room.messages[0][1]).to.be.a('String'); + // expect(room.messages[0]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); + // + // }); + // }); + // }); }); diff --git a/test/mock.utils.gh.js b/test/mock.utils.gh.js index 79af9f0..f865eb7 100644 --- a/test/mock.utils.gh.js +++ b/test/mock.utils.gh.js @@ -7,15 +7,22 @@ 'use strict'; const nock = require('nock'); +const path = require('path'); nock.disableNetConnect(); nock.enableNetConnect('localhost'); -const endpoint = 'https://github.com:443'; +const ghApiEndpoint = 'https://api.github.com'; +const ghEndpoint = 'https://github.com'; + +const mockBranches = require(path.resolve(__dirname, 'resources', 'mock.branches.json')); module.exports = { setupMockery: function() { - let ghScope = nock(endpoint) + let ghScope = nock(ghEndpoint) + .persist(); + + let ghApiScope = nock(ghApiEndpoint) .persist(); ghScope.get('/user/helloworld/archive/master.zip') @@ -27,7 +34,19 @@ module.exports = { ghScope.get('/user/manifestTest/archive/master.zip') .replyWithFile(200, __dirname + '/resources/manifestTest/master.zip'); + ghScope.get('/user/manifestTest/archive/master.zip') + .replyWithFile(200, __dirname + '/resources/manifestTest/master.zip'); + ghScope.get('/user/manifestTestNoApp/archive/master.zip') - .replyWithFile(200, __dirname + '/resources/manifestTestNoApp/master.zip'); + .replyWithFile(200, __dirname + '/resources/manifestTestNoApp/master.zip'); + + ghScope.get('/user/manifestTestMultipleBranches/archive/test-branch.zip') + .replyWithFile(200, __dirname + '/resources/manifestTest/master.zip'); + + ghApiScope.get('/repos/user/manifestTest/branches') + .reply(200, mockBranches.oneBranch); + + ghApiScope.get('/repos/user/manifestTestMultipleBranches/branches') + .reply(200, mockBranches.multipleBranches); } }; diff --git a/test/resources/mock.branches.json b/test/resources/mock.branches.json new file mode 100644 index 0000000..72b9aeb --- /dev/null +++ b/test/resources/mock.branches.json @@ -0,0 +1,29 @@ +{ + "multipleBranches": + [ + { + "name": "master", + "commit": { + "sha": "mockCommit", + "url": "mockURL" + } + }, + { + "name": "test-branch", + "commit": { + "sha": "mockCommit", + "url": "mockURL" + } + } + ], + "oneBranch": + [ + { + "name": "master", + "commit": { + "sha": "mockCommit", + "url": "mockURL" + } + } + ] +} From 50c57c14e997bf2533168ff2106018a3bfa3a20e Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 14:14:57 -0400 Subject: [PATCH 8/9] Indentation fix --- README.md | 4 +-- package.json | 2 +- src/messages/en.json | 2 +- src/scripts/deploy.js | 12 +++----- test/resources/mock.branches.json | 48 +++++++++++++++---------------- 5 files changed, 31 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index e5fcae2..b30307c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ If you are new to Hubot visit the [getting started](https://hubot.github.com/doc HUBOT_BLUEMIX_USER= HUBOT_BLUEMIX_PASSWORD= HUBOT_GITHUB_TOKEN= (optional) - HUBOT_GITHUB_DOMAIN= (optional) + HUBOT_GITHUB_DOMAIN= (optional) 5. Start up your bot & off to the races! @@ -72,7 +72,7 @@ Please refer to the [CONTRIBUTING.md](https://github.com/ibm-cloud-solutions/hub export HUBOT_BLUEMIX_USER= export HUBOT_BLUEMIX_PASSWORD= export HUBOT_GITHUB_TOKEN= (optional) - export HUBOT_GITHUB_DOMAIN= (optional) + export HUBOT_GITHUB_DOMAIN= (optional) 3. In order to view content in chat clients you will need to add `hubot-ibmcloud-formatter` to your `external-scripts.json` file. Additionally, if you want to use `hubot-help` to make sure your command documentation is correct. Create `external-scripts.json` in the root of this project, with the following contents: diff --git a/package.json b/package.json index 07baf3f..91b97ac 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "dependencies": { "adm-zip": "^0.4.7", "yamljs": "^0.2.8", - "github": "^3.0.0" + "github": "^3.0.0" }, "config": { "commitizen": { diff --git a/src/messages/en.json b/src/messages/en.json index 748fffe..fe1bc6c 100644 --- a/src/messages/en.json +++ b/src/messages/en.json @@ -38,7 +38,7 @@ "github.deploy.error": "A deployment error occurred for app *%s*: %s.", "github.deploy.manifest.error": "Invalid manifest.yml file for app *%s*.", "github.deploy.route.error": "Error adding route to the application: *%s*.", - "github.deploy.branch.prompt": "Which *branch* would you like to deploy?", + "github.deploy.branch.prompt": "Which *branch* would you like to deploy?", "help.github.deploy": "Deployment setup with prompts for application and GitHub URL.", "help.github.deploy.app": "Deployment setup for , or prompt you to provide a GitHub URL to deploy to .", diff --git a/src/scripts/deploy.js b/src/scripts/deploy.js index 2ce6e80..4124756 100644 --- a/src/scripts/deploy.js +++ b/src/scripts/deploy.js @@ -7,10 +7,10 @@ // HUBOT_BLUEMIX_SPACE Bluemix space // HUBOT_BLUEMIX_USER Bluemix User ID // HUBOT_BLUEMIX_PASSWORD Password for the Bluemix User -// HUBOT_GITHUB_TOKEN Github API Auth token +// HUBOT_GITHUB_TOKEN Github API Auth token // // Commands: -// hubot deploy help - Show available commands in the deploy category. +// hubot deploy help - Show available commands in the deploy category. // hubot deploy - Deployment setup with prompts for application, GitHub URL and branch. // hubot deploy - Deployment setup for app, or prompt you to provide a GitHub URL and branch to depoy to. // hubot deploy - Deployment setup for url and prompt you for the Bluemix application name and branch. @@ -306,17 +306,13 @@ const sortRegisterInput = (input1, input2) => { }; const deploy = (app, appGuid, spaceGuid, spaceName, robot, res) => { - const branch = app.branch; - const reponame = app.repo; - const repoowner = app.user; - let domain = ''; let appZip; let applicationGuid; let temp = os.tmpdir(); let now = Date.now(); let deploymentDir = `${temp}/${now}`; - let filename = `${deploymentDir}/${reponame}_${now}.zip`; + let filename = `${deploymentDir}/${app.repo}_${now}.zip`; let applicationDomain; let applicationHost; let applicationDomainGuid; @@ -331,7 +327,7 @@ const deploy = (app, appGuid, spaceGuid, spaceName, robot, res) => { } robot.logger.info(`${TAG}: Beginning deployment steps for ${app.app} ...`); - getUserRepo(robot, domain, repoowner, reponame, branch) + getUserRepo(robot, domain, app.user, app.repo, app.branch) .then((bf) => { let message = i18n.__('github.deploy.obtaining.zip', app.app); robot.emit('ibmcloud.formatter', { response: res, message: message}); diff --git a/test/resources/mock.branches.json b/test/resources/mock.branches.json index 72b9aeb..8e23ac3 100644 --- a/test/resources/mock.branches.json +++ b/test/resources/mock.branches.json @@ -1,29 +1,27 @@ { - "multipleBranches": - [ - { - "name": "master", - "commit": { - "sha": "mockCommit", - "url": "mockURL" - } - }, - { - "name": "test-branch", - "commit": { - "sha": "mockCommit", - "url": "mockURL" - } + "multipleBranches": [ + { + "name": "master", + "commit": { + "sha": "mockCommit", + "url": "mockURL" } - ], - "oneBranch": - [ - { - "name": "master", - "commit": { - "sha": "mockCommit", - "url": "mockURL" - } + }, + { + "name": "test-branch", + "commit": { + "sha": "mockCommit", + "url": "mockURL" } - ] + } + ], + "oneBranch": [ + { + "name": "master", + "commit": { + "sha": "mockCommit", + "url": "mockURL" + } + } + ] } From 67d26d39f9bb15df6cc4604bf7052b83b28f9e8b Mon Sep 17 00:00:00 2001 From: Reinaldo Cruz Date: Thu, 15 Sep 2016 14:23:29 -0400 Subject: [PATCH 9/9] Remove commented test --- test/bluemix.github.deploy.test.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/bluemix.github.deploy.test.js b/test/bluemix.github.deploy.test.js index b12ca19..82e2cd7 100644 --- a/test/bluemix.github.deploy.test.js +++ b/test/bluemix.github.deploy.test.js @@ -371,18 +371,4 @@ describe('Interacting with Bluemix via Slack', function() { }); }); }); - - // context('user calls `deploy app` with a zip for new app', function() { - // - // it.only('should respond with the apps that it will deploy with zip', function() { - // return room.user.say('mimiron', '@hubot deploy manifestTest user/manifestTest').then(() => { - // expect(room.messages.length).to.eql(2); - // expect(room.messages[1][1]).to.be.a('String'); - // expect(room.messages[1]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.in.progress.matching')}`]); - // expect(room.messages[0][1]).to.be.a('String'); - // expect(room.messages[0]).to.eql(['hubot', `@mimiron ${i18n.__('github.deploy.branch.prompt')}`]); - // - // }); - // }); - // }); });