diff --git a/client/directives/instances/instance/instanceHeaderDirective.js b/client/directives/instances/instance/instanceHeaderDirective.js index ec84ca379..b618031fc 100644 --- a/client/directives/instances/instance/instanceHeaderDirective.js +++ b/client/directives/instances/instance/instanceHeaderDirective.js @@ -41,7 +41,7 @@ function instanceHeader( }); }); $scope.showPrCallout = function () { - return demoFlowService.isInDemoFlow() && demoFlowService.shouldAddPR() && !demoFlowService.getItem('clickedPrLink'); + return demoFlowService.isInDemoFlow() && !demoFlowService.getItem('clickedPrLink'); }; $scope.isInGuide = ahaGuide.isInGuide; diff --git a/client/directives/instances/instanceList/DemoAddBranchController.js b/client/directives/instances/instanceList/DemoAddBranchController.js deleted file mode 100644 index 16efb242d..000000000 --- a/client/directives/instances/instanceList/DemoAddBranchController.js +++ /dev/null @@ -1,150 +0,0 @@ -'use strict'; - -require('app') - .controller('DemoAddBranchController', DemoAddBranchController); - -function DemoAddBranchController( - $q, - $scope, - $state, - $timeout, - currentOrg, - demoFlowService, - errs, - fetchInstancesByPod, - featureFlags, - github, - keypather, - loading, - promisify, - watchOncePromise -) { - var DBC = this; - - function getBranchForPR () { - return promisify(currentOrg.github, 'fetchRepo')(DBC.instance.getRepoName()) - .then(function (repo) { - return promisify(repo, 'fetchBranch')('dark-theme'); - }) - .then(function (branch) { - var sha = branch.attrs.commit.sha; - var branchName = branch.attrs.name; - return promisify(DBC.instance, 'fork')(branchName, sha); - }); - } - - fetchInstancesByPod() - .then(function (instances) { - return watchOncePromise($scope, function () { - return instances.models.find(function (instance) { - return keypather.get(instance, 'children.models[0]'); - }); - }, true); - }) - .then(function (instance) { - var branchInstance = instance.children.models[0]; - if (!instance.attrs.dependencies.length) { - // If the master instance depends on anything, then we need to wait for the isolation - return branchInstance; - } - return watchOncePromise($scope, function () { - // Wait for the isolation model to populate - return keypather.get(branchInstance, 'isolation.instances.fetch'); - }, true) - .then(function () { - // Now fetch the isolation - return promisify(branchInstance.isolation.instances, 'fetch')(); - }) - .then(function () { - return branchInstance; - }); - }) - .then(function (branchInstance) { - demoFlowService.hasAddedBranch(true); - if (demoFlowService.shouldAddPR()) { - return demoFlowService.submitDemoPR(branchInstance) - .then(function () { - return branchInstance; - }) - .catch(function (err) { - if (keypather.get(err, 'errors[0].message').match(/(pull request.*exists)/)) { - return branchInstance; - } - errs.handler(err); - }); - } - return branchInstance; - }) - .then(function (branchInstance) { - return $state.go('base.instances.instance', { - instanceName: branchInstance.getName() - }); - }) - .finally(function () { - loading('creatingNewBranchFromDemo', false); - }); - - DBC.shouldUseBranchForPR = function () { - return demoFlowService.shouldAddPR(); - }; - - DBC.getBranchName = function () { - if (DBC.shouldUseBranchForPR()) { - return 'dark-theme'; - } - return 'my-branch'; - }; - - DBC.getNewBranchString = function () { - if (!DBC.shouldUseBranchForPR()) { - return '-b '; - } - return ''; - }; - - DBC.getBranchCloneCopyText = function () { - var lb = '\r\n'; - var string = 'git clone https://github.com/' + - DBC.userName + '/' + DBC.instance.getRepoName() + '.git' + lb + - 'cd ' + DBC.instance.getRepoName() + lb + - 'git checkout ' + DBC.getNewBranchString() + DBC.getBranchName() + lb; - if (DBC.shouldUseBranchForPR()) { - string += 'echo \':)\' >> README.md' + lb + - 'git add -u' + lb + - 'git commit -m \'a friendlier README\'' + lb; - } - string += 'git push origin ' + DBC.getBranchName() + ';'; - return string; - }; - - DBC.createNewBranch = function (count) { - loading('creatingNewBranchFromDemo', true); - count = count || 0; - var acv = DBC.instance.contextVersion.getMainAppCodeVersion(); - var completeRepoName = acv.attrs.repo.split('/'); - var repoOwner = completeRepoName[0]; - var repoName = completeRepoName[1]; - var branchName = DBC.getBranchName(); - if (count) { - branchName += '-' + count; - } - if (demoFlowService.shouldAddPR()) { - return getBranchForPR(DBC.instance); - } - return github.createNewBranch(repoOwner, repoName, acv.attrs.commit, branchName) - .catch(function (err) { - if (err.message.match(/reference already exists/gi)) { - return DBC.createNewBranch(++count); - } - errs.handler(err); - }); - }; - - DBC.onClipboardEvent = function (err) { - if (err) { - DBC.clipboardText = 'Could not copy text'; - } else { - DBC.clipboardText = 'Copied!'; - } - }; -} diff --git a/client/directives/instances/instanceList/demoAddBranchDirective.js b/client/directives/instances/instanceList/demoAddBranchDirective.js deleted file mode 100644 index 83a979d9f..000000000 --- a/client/directives/instances/instanceList/demoAddBranchDirective.js +++ /dev/null @@ -1,20 +0,0 @@ - 'use strict'; - -require('app') - .directive('demoAddBranch', demoAddBranch); -/** - * @ngInject - */ -function demoAddBranch() { - return { - restrict: 'A', - templateUrl: 'demoAddBranchView', - scope: { - userName: '=', - instance: '=' - }, - controller: 'DemoAddBranchController', - controllerAs: 'DBC', - bindToController: true - }; -} diff --git a/client/directives/instances/instanceList/demoAddBranchView.jade b/client/directives/instances/instanceList/demoAddBranchView.jade deleted file mode 100644 index ca6b4394c..000000000 --- a/client/directives/instances/instanceList/demoAddBranchView.jade +++ /dev/null @@ -1,46 +0,0 @@ -.grid-block.align-center.justify-justified.demo-progress( - demo-progress-bar - demo-step = 4 -) - -p.p.commands-wrapper.padding-sm Launch new environments by pushing a branch to GitHub. - -.commands-wrapper - .small.padding-top-sm.padding-left-sm.padding-right-sm - | Try it in your terminal: - //- tooltip should work like the one on the Copy button for container URLs - button.btn.btn-xxs.btn-copy.float-right( - clipboard - ng-click = "$event.preventDefault()" - ng-mouseleave = "showToolTip = false" - on-copied = "DBC.onClipboardEvent(); showToolTip = true;" - text = "DBC.getBranchCloneCopyText()" - tooltip - tooltip-active-attr = "{{showToolTip}}" - tooltip-eval="DBC.clipboardText" - tooltip-options = "{\"class\":\"bottom no-arrow\",\"right\":-16,\"top\":27}" - ) Copy - pre.monospace.padding-sm.padding-bottom-xs - {{DBC.getBranchCloneCopyText()}} - - -.grid-block.align-start.vertical.padding-sm.padding-top-xs.commands-wrapper.skip-wrapper - - //- hide while creating branch - small.small( - ng-if = "!$root.isLoading.creatingNewBranchFromDemo" - ) Or we can create a branch for you using the GitHub API. - - button.btn.btn-sm.green.margin-top-xxs( - ng-click = "DBC.createNewBranch()" - ng-if = "!$root.isLoading.creatingNewBranchFromDemo" - ) Create Branch - - //- show while creating branch - .grid-block.align-center.small.noscroll( - ng-if = "$root.isLoading.creatingNewBranchFromDemo" - ) - .spinner-wrapper.spinner-sm.spinner-gray.margin-right-xxs( - ng-include = "'spinner'" - ) - | Creating branch… diff --git a/client/services/demoFlowService.js b/client/services/demoFlowService.js index b697a6655..d1347d1b5 100644 --- a/client/services/demoFlowService.js +++ b/client/services/demoFlowService.js @@ -77,15 +77,13 @@ function demoFlowService( unregisterContainerUrlClickListener(); forkNewInstance(instance) .then(function () { - if (currentOrg.isPersonalAccount()) { - submitDemoPR(instance) - .catch(function (err) { - if (keypather.get(err, 'errors[0].message').match(/(pull request.*exists)/)) { - return instance; - } - errs.handler(err); - }); - } + submitDemoPR(instance) + .catch(function (err) { + if (keypather.get(err, 'errors[0].message').match(/(pull request.*exists)/)) { + return instance; + } + errs.handler(err); + }); }); }); } @@ -170,9 +168,6 @@ function demoFlowService( return endDemoFlow(); }); - function shouldAddPR () { - return currentOrg.isPersonalAccount(); - } function shouldShowTeamCTA () { return currentOrg.isPersonalAccount() && isInDemoFlow() && getItem('clickedPrLink'); } @@ -194,7 +189,6 @@ function demoFlowService( hasAddedBranch: hasAddedBranch, hasSeenHangTightMessage: hasSeenHangTightMessage, hasSeenUrlCallout: hasSeenUrlCallout, - shouldAddPR: shouldAddPR, isInDemoFlow: isInDemoFlow, resetFlags: resetFlags, setItem: setItem, diff --git a/test/unit/controllers/demoAddBranchController.unit.js b/test/unit/controllers/demoAddBranchController.unit.js deleted file mode 100644 index 764d91ffa..000000000 --- a/test/unit/controllers/demoAddBranchController.unit.js +++ /dev/null @@ -1,242 +0,0 @@ -'use strict'; - -var apiMocks = require('../apiMocks/index'); -var $controller; -var $q; -var $rootScope; -var $scope; -var $stateMock; -var $timeout; -var currentOrgMock; -var DBC; -var demoFlowServiceMock; -var fetchInstancesByPodStub; -var fetchRepoBranchesStub; -var githubStub; -var promisifyMock; -var keypather; -var loadingMock; -var branchMock; -var watchOncePromiseStub; -var instanceMock = { - attrs: { - dependencies: [] - }, - children: { - models: [{ - isolation: { - instances: { - fetch: sinon.stub().returns({ - getName: sinon.stub().returns('way back') - }) - } - }, - getName: sinon.stub().returns('way back') - }] - }, - contextVersion: { - getMainAppCodeVersion: sinon.stub().returns({ - attrs: { - repo: 'this/isarepo!' - } - }) - }, - getRepoName: sinon.stub().returns('isarepo!'), - getName: sinon.stub().returns('henrys branch') -}; -var featureFlagsMock = { - flags: { - demoMultiTierPRLink: true - - } -}; -var shouldAddPR; - - -describe('DemoAddBranchController'.bold.underline.blue, function () { - - function setup() { - shouldAddPR = true; - angular.mock.module('app', function ($provide) { - $provide.factory('promisify', function ($q) { - promisifyMock = sinon.spy(function (obj, key) { - return function () { - return $q.when(obj[key].apply(obj, arguments)); - }; - }); - return promisifyMock; - }); - $provide.factory('github', function ($q) { - githubStub = { - createNewBranch: sinon.stub().returns($q.when(true)) - }; - return githubStub; - }); - $provide.factory('$state', function () { - $stateMock = { - go: sinon.stub() - }; - return $stateMock; - }) - $provide.factory('demoFlowService', function ($q) { - demoFlowServiceMock = { - hasAddedBranch: sinon.stub(), - shouldAddPR: sinon.stub().returns(shouldAddPR), - submitDemoPR: sinon.stub().returns($q.when(instanceMock)), - endDemoFlow: sinon.stub().returns($q.when(true)), - }; - return demoFlowServiceMock; - }); - $provide.factory('loading', function () { - return function () {return true;}; - }); - $provide.factory('currentOrg', function ($q) { - currentOrgMock = { - github: { - fetchRepo: sinon.stub().returns($q.when({ - fetchRepo: sinon.stub().returns(function () { - return { - fetchBranch: sinon.stub().returns($q.when(function () { - return branchMock; - })) - } - }) - })) - } - } - return currentOrgMock; - }); - $provide.factory('fetchInstancesByPod', function ($q) { - fetchInstancesByPodStub = sinon.stub().returns($q.when(instanceMock)); - return fetchInstancesByPodStub; - }); - $provide.factory('fetchRepoBranches', function ($q) { - fetchRepoBranchesStub = sinon.stub().returns($q.when(true)); - return fetchRepoBranchesStub; - }); - $provide.factory('watchOncePromise', function ($q) { - watchOncePromiseStub = sinon.stub().returns($q.when(instanceMock)); - return watchOncePromiseStub; - }) - }); - angular.mock.inject(function ( - _$controller_, - _$q_, - _$rootScope_, - _keypather_, - _$state_, - _$timeout_ - ) { - $controller = _$controller_; - $q = _$q_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); - keypather = _keypather_; - $timeout = _$timeout_; - }); - - DBC = $controller('DemoAddBranchController', { - '$scope': $scope - }); - - DBC.instance = instanceMock; - DBC.userName = 'heavenstobetsy'; - } - - describe('fetching instances on load when submitting a PR'.blue, function () { - beforeEach(setup); - - it('should call fetch instances and change state for personal account', function () { - $rootScope.$digest(); - sinon.assert.called(fetchInstancesByPodStub); - sinon.assert.called(watchOncePromiseStub); - sinon.assert.called(demoFlowServiceMock.hasAddedBranch); - sinon.assert.called(demoFlowServiceMock.shouldAddPR); - sinon.assert.called(demoFlowServiceMock.submitDemoPR); - sinon.assert.notCalled(demoFlowServiceMock.endDemoFlow); - sinon.assert.called($stateMock.go); - sinon.assert.calledWithExactly($stateMock.go, - 'base.instances.instance', - { - instanceName: 'way back' - } - ); - }); - - it('should return true when calling shouldUseBranchForPR', function () { - var shouldUseBranchForPR = DBC.shouldUseBranchForPR(); - expect(shouldUseBranchForPR).to.equal(true); - sinon.assert.called(demoFlowServiceMock.shouldAddPR); - }); - - it('should return the right branch name', function () { - var branchName = DBC.getBranchName(); - expect(branchName).to.equal('dark-theme'); - }); - - it('should not return a new branch checkout command', function () { - var newBranchString = DBC.getNewBranchString(); - expect(newBranchString).to.equal(''); - }); - - it('should create a commit for clone copy text', function () { - var cloneCopyText = DBC.getBranchCloneCopyText(); - expect(cloneCopyText).to.equal('git clone https://github.com/heavenstobetsy/isarepo!.git\r\ncd isarepo!\r\ngit checkout dark-theme\r\necho \':)\' >> README.md\r\ngit add -u\r\ngit commit -m \'a friendlier README\'\r\ngit push origin dark-theme;'); - }); - - it('should not call createNewBranch', function () { - DBC.createNewBranch(); - sinon.assert.notCalled(githubStub.createNewBranch); - }); - }); - - describe('fetching instances on load when not submitting a PR '.blue, function () { - beforeEach(function () { - setup(); - demoFlowServiceMock.shouldAddPR.returns(false) - }); - - it('should call fetch instances and change state for personal account', function () { - $rootScope.$digest(); - sinon.assert.called(fetchInstancesByPodStub); - sinon.assert.called(watchOncePromiseStub); - sinon.assert.called(demoFlowServiceMock.hasAddedBranch); - sinon.assert.called(demoFlowServiceMock.shouldAddPR); - sinon.assert.notCalled(demoFlowServiceMock.submitDemoPR); - sinon.assert.called($stateMock.go); - sinon.assert.calledWithExactly($stateMock.go, - 'base.instances.instance', - { - instanceName: 'way back' - } - ); - }); - - it('should return false when calling shouldUseBranchForPR', function () { - var shouldUseBranchForPR = DBC.shouldUseBranchForPR(); - expect(shouldUseBranchForPR).to.equal(false); - sinon.assert.called(demoFlowServiceMock.shouldAddPR); - }); - - it('should return the right branch name', function () { - var branchName = DBC.getBranchName(); - expect(branchName).to.equal('my-branch'); - }); - - it('should return a new branch checkout command', function () { - var newBranchString = DBC.getNewBranchString(); - expect(newBranchString).to.equal('-b '); - }); - - it('should not create a commit for clone copy text', function () { - var cloneCopyText = DBC.getBranchCloneCopyText(); - expect(cloneCopyText).to.equal('git clone https://github.com/heavenstobetsy/isarepo!.git\r\ncd isarepo!\r\ngit checkout -b my-branch\r\ngit push origin my-branch;'); - }); - - it('should call createNewBranch', function () { - DBC.createNewBranch(); - sinon.assert.called(githubStub.createNewBranch); - }); - }); - -});