Skip to content

Commit 3ab59e9

Browse files
authored
Merge pull request #2062 from CodeNow/revert-commit-selector
ASAP-revert-commit-selector
2 parents 310bb46 + 52d6173 commit 3ab59e9

File tree

8 files changed

+56
-74
lines changed

8 files changed

+56
-74
lines changed

client/directives/components/editRepoCommit/EditRepoCommitController.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ function EditRepoCommitController(
1616
errs,
1717
loading,
1818
ModalService,
19-
updateInstanceWithNewAcvData,
20-
github
19+
updateInstanceWithNewAcvData
2120
) {
2221
var ERCC = this;
2322
ERCC.isLatestCommitDeployed = true;
@@ -30,14 +29,15 @@ function EditRepoCommitController(
3029

3130
$scope.$watch('ERCC.acv', function (newAcv, oldAcv) {
3231
if (newAcv) {
32+
var branch = ERCC.acv.githubRepo.newBranch(ERCC.acv.attrs.branch, {warn: false});
3333
$q.all({
3434
activeCommit: fetchCommitData.activeCommit(ERCC.acv),
35-
branchCommits: github.branchOrPRCommits(ERCC.acv)
35+
branchCommits: promisify(branch.commits, 'fetch')()
3636
})
3737
.then(function(commits) {
3838
ERCC.activeCommit = commits.activeCommit;
39-
ERCC.latestBranchCommit = keypather.get(commits, 'branchCommits[0]');
40-
ERCC.isLatestCommitDeployed = ERCC.activeCommit.attrs.sha === ERCC.latestBranchCommit.sha;
39+
ERCC.latestBranchCommit = keypather.get(commits, 'branchCommits.models[0]');
40+
ERCC.isLatestCommitDeployed = ERCC.activeCommit.attrs.sha === ERCC.latestBranchCommit.attrs.sha;
4141
});
4242
}
4343
});
@@ -107,12 +107,13 @@ function EditRepoCommitController(
107107
};
108108

109109
ERCC.updateInstance = function() {
110+
var branch = ERCC.acv.githubRepo.newBranch(ERCC.acv.attrs.branch, {warn: false});
110111
loading('updatingInstance', true);
111-
$q.when(github.branchOrPRCommits(ERCC.acv))
112+
promisify(branch.commits, 'fetch')()
112113
.then(function(commits) {
113-
ERCC.latestBranchCommit = commits[0];
114+
ERCC.latestBranchCommit = keypather.get(commits, 'models[0]');
114115
repoObject.commit = ERCC.latestBranchCommit;
115-
if (ERCC.activeCommit.attrs.sha !== ERCC.latestBranchCommit.sha) {
116+
if (ERCC.activeCommit.attrs.sha !== ERCC.latestBranchCommit.attrs.sha) {
116117
return updateInstanceWithNewAcvData(ERCC.instance, ERCC.acv, repoObject)
117118
.then(function(instance) {
118119
loading('updatingInstance', false);

client/directives/components/lists/branchCommitSelector/branchCommitSelectorController.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ function BranchCommitSelectorController(
1313
BCSC.eventTracking = eventTracking;
1414

1515
BCSC.onCommitFetch = function (commits) {
16-
if (!commits.length) { return; }
17-
BCSC.data.commits = commits;
16+
if (!commits.models.length) { return; }
1817
if (BCSC.data.commit) {
19-
BCSC.data.commit = commits.find(function (otherCommits) {
18+
BCSC.data.commit = commits.models.find(function (otherCommits) {
2019
return otherCommits === BCSC.data.commit;
21-
}) || commits[0];
22-
BCSC.isLatestCommitDeployed = commits[0] === BCSC.data.commit;
20+
}) || commits.models[0];
21+
BCSC.isLatestCommitDeployed = commits.models[0] === BCSC.data.commit;
2322
}
2423
};
2524

2625
BCSC.isLatestCommit = function (setToLatestCommit) {
2726
if (arguments.length) {
28-
BCSC.data.commit = keypather.get(BCSC.data.branch, 'commits[0]');
27+
BCSC.data.commit = keypather.get(BCSC.data.branch, 'commits.models[0]');
2928
BCSC.data.useLatest = setToLatestCommit;
3029
if (setToLatestCommit) {
3130
$scope.$emit('commit::selected', BCSC.data.commit);
@@ -44,7 +43,7 @@ function BranchCommitSelectorController(
4443

4544
BCSC.deployLatestCommit = function () {
4645
if (BCSC.isAutoDeployOn() && !BCSC.isLatestCommitDeployed) {
47-
BCSC.data.commit = keypather.get(BCSC.data.branch, 'commits[0]');
46+
BCSC.data.commit = keypather.get(BCSC.data.branch, 'commits.models[0]');
4847
BCSC.updateInstance();
4948
}
5049
};

client/directives/components/lists/branchCommitSelector/branchCommitSelectorDirective.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ require('app')
1111
*/
1212
function branchCommitSelector(
1313
errs,
14-
promisify,
15-
github
14+
promisify
1615
) {
1716
return {
1817
restrict: 'A',
@@ -29,8 +28,7 @@ function branchCommitSelector(
2928
$scope.$watch('BCSC.data.branch', function (branch) {
3029
if (branch) {
3130
$scope.fetchingCommits = true;
32-
var acv = $scope.BCSC.data.acv;
33-
return github.branchOrPRCommits(acv)
31+
return promisify(branch.commits, 'fetch')()
3432
.then($scope.BCSC.onCommitFetch)
3533
.catch(errs.handler)
3634
.finally(function () {

client/directives/components/lists/branchCommitSelector/branchCommitSelectorView.jade

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ ul.list.list-servers
6363
ng-include = "'spinner'"
6464
)
6565
li.list-item(
66-
ng-attr-title = "{{commit.commit.message}}"
66+
ng-attr-title = "{{commit.attrs.commit.message}}"
6767
ng-disabled = "BCSC.isAutoDeployOn() || BCSC.isLastestCommit()"
6868
ng-class = "{\
6969
'active': BCSC.data.commit === commit,\
7070
'disabled': BCSC.isAutoDeployOn() || BCSC.isLastestCommit()\
7171
}"
7272
ng-click = "BCSC.selectCommit(commit, $index === 0)"
7373
ng-if = "!fetchingCommits"
74-
ng-repeat = "commit in BCSC.data.commits | orderBy: '-commit.committer.date'"
75-
) {{commit.commit.message}}
74+
ng-repeat = "commit in BCSC.data.branch.commits.models | orderBy: '-attrs.commit.committer.date'"
75+
) {{commit.attrs.commit.message}}
7676
.row.row-author.clearfix(
77-
ng-attr-title = "{{commit.author.login}} authored {{commit.commit.committer.date | timeFrom}}"
77+
ng-attr-title = "{{commit.attrs.author.login}} authored {{commit.attrs.commit.committer.date | timeFrom}}"
7878
)
7979
//- if invite flows...
8080
.btn-user.text-overflow(
@@ -88,19 +88,19 @@ ul.list.list-servers
8888
)
8989
span.small(
9090
ng-if = "$root.featureFlags.inviteFlows"
91-
) —{{commit.commit.committer.date | timeFrom}}
91+
) —{{commit.attrs.commit.committer.date | timeFrom}}
9292

9393
//- else
9494
span.small(
9595
ng-if = "!$root.featureFlags.inviteFlows"
96-
) {{commit.author.login}}—{{commit.commit.committer.date | timeFrom}}
96+
) {{commit.attrs.author.login}}—{{commit.attrs.commit.committer.date | timeFrom}}
9797

9898
a.small.link.monospace(
9999
ng-click = "$event.stopPropagation()"
100-
ng-href = "{{commit.html_url}}"
100+
ng-href = "{{commit.attrs.html_url}}"
101101
target = "_blank"
102102
title = "View on GitHub"
103-
) {{::commit.sha | limitTo:7}}
103+
) {{::commit.attrs.sha | limitTo:7}}
104104
svg.iconnables.icons-fat-check(
105105
ng-if = "!BCSC.isLatestCommit()"
106106
)

client/services/githubService.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ function github(
3333
});
3434
}
3535
return {
36-
branchOrPRCommits: function (acv) {
37-
var pullRequest = acv.attrs.pullRequest;
38-
var repo = acv.attrs.lowerRepo;
39-
var githubUrl;
40-
if (pullRequest) {
41-
githubUrl = '/repos/' + repo + '/pulls/' + pullRequest + '/commits?per_page=100';
42-
} else {
43-
githubUrl = '/repos/' + repo + '/commits?sha=' + acv.attrs.branch + '&per_page=100';
44-
}
45-
var ghRequest = {
46-
method: 'get',
47-
url: githubAPIUrl + githubUrl
48-
};
49-
return makeGhRequest(ghRequest);
50-
},
5136
forkRepo: function (repoOwner, repoName, targetOrg, isPersonalAccount) {
5237
var ghRequest = {
5338
method: 'post',

test/unit/controllers/branchCommitSelectorController.unit.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ describe('branchCommitSelectorController'.bold.underline.blue, function () {
1616
ctx.commit = {
1717
name: 'This is a commit message!'
1818
};
19-
ctx.commits = [ctx.commit];
19+
ctx.commits = {
20+
fetch: sinon.stub().returns({
21+
models: [ctx.commit]
22+
}),
23+
models: [ctx.commit]
24+
};
2025
ctx.branch = {
2126
attrs: {
2227
name: 'default'
@@ -84,15 +89,15 @@ describe('branchCommitSelectorController'.bold.underline.blue, function () {
8489
$scope.$digest();
8590
branchCommitSelectorController.onCommitFetch(ctx.commits);
8691
$scope.$digest();
87-
expect(branchCommitSelectorController.data.commit, 'data.commit').to.equal(ctx.commits[0]);
92+
expect(branchCommitSelectorController.data.commit, 'data.commit').to.equal(ctx.commits.models[0]);
8893
$rootScope.$destroy();
8994
});
9095

9196
it('should leave the commit if it can find the current one in the list', function () {
9297
var newCommit = {
9398
sadsa: 'asdasd'
9499
};
95-
ctx.commits.push(newCommit);
100+
ctx.commits.models.push(newCommit);
96101
branchCommitSelectorController.data = {
97102
useLatest: true,
98103
branch: ctx.branch,
@@ -115,7 +120,7 @@ describe('branchCommitSelectorController'.bold.underline.blue, function () {
115120
branchCommitSelectorController.isLatestCommit(false);
116121
expect(branchCommitSelectorController.isLatestCommit(), 'useLatest').to.be.false;
117122
expect(branchCommitSelectorController.data.useLatest, 'data.useLatest').to.be.false;
118-
expect(branchCommitSelectorController.data.commit, 'data.commit').to.equal(ctx.commits[0]);
123+
expect(branchCommitSelectorController.data.commit, 'data.commit').to.equal(ctx.commits.models[0]);
119124
$rootScope.$destroy();
120125
});
121126
it('useLatest emits commit::selected on set true, not false', function () {
@@ -134,7 +139,7 @@ describe('branchCommitSelectorController'.bold.underline.blue, function () {
134139
sinon.assert.calledOnce(commitSelectedSpy);
135140

136141
expect(branchCommitSelectorController.data.useLatest, 'data.useLatest').to.be.true;
137-
expect(branchCommitSelectorController.data.commit, 'data.commit').to.equal(ctx.commits[0]);
142+
expect(branchCommitSelectorController.data.commit, 'data.commit').to.equal(ctx.commits.models[0]);
138143
$rootScope.$destroy();
139144
});
140145

test/unit/directives/branchCommitSelectorDirective.unit.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ describe('branchCommitSelectorDirective'.bold.underline.blue, function () {
4040
link: angular.noop
4141
};
4242
});
43-
$provide.factory('github', function ($q) {
44-
ctx.github = {
45-
branchOrPRCommits: sinon.stub().returns($q.when(ctx.commits))
46-
};
47-
return ctx.github;
48-
});
4943
});
5044

5145
angular.mock.inject(function (
@@ -87,7 +81,7 @@ describe('branchCommitSelectorDirective'.bold.underline.blue, function () {
8781
//Should fetch once the branch is set
8882
$scope.$digest();
8983
expect($elScope.BCSC.data.branch, 'data.branch').to.equal(ctx.branch);
90-
sinon.assert.called(ctx.github.branchOrPRCommits);
84+
sinon.assert.called(ctx.branch.commits.fetch);
9185
expect($elScope.fetchingCommits, 'fetchingCommits').to.be.false;
9286
$rootScope.$destroy();
9387
});

test/unit/directives/editRepoCommitController.unit.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,31 @@ describe('EditRepoCommitController'.bold.underline.blue, function() {
1111
var $q;
1212
var editRepoCommitController;
1313
var ERCC;
14+
var getCommitStub;
1415
var commits;
15-
var newCommits;
1616
var acvMock;
17-
var branchCommitsStub;
17+
var newBranchStub;
1818

1919
function setup() {
2020
ctx = {};
21-
ctx.commitData = apiMocks.commit.bitcoinRepoCommit1
2221
ctx.branch = {attrs: apiMocks.branches.bitcoinRepoBranches[0]};
23-
ctx.commit = {attrs: ctx.commitData};
24-
branchCommitsStub = sinon.stub().returns([ctx.commitData]);
22+
ctx.commit = {attrs: apiMocks.commit.bitcoinRepoCommit1};
23+
getCommitStub = sinon.stub().returns({models: [ctx.commit]});
24+
newBranchStub = sinon.stub().returns({
25+
commits: {
26+
fetch: getCommitStub
27+
}
28+
})
2529
acvMock = {
2630
attrs: {
2731
repo: 'foo/bar',
2832
commit: 'commitSha'
2933
},
30-
githubRepo: {}
34+
githubRepo: {
35+
newBranch: newBranchStub
36+
}
3137
};
3238
commits = {models: [apiMocks.commit.bitcoinRepoCommit2, ctx.commit]};
33-
newCommits = [apiMocks.commit.bitcoinRepoCommit2, ctx.commitData]
3439
angular.mock.module('app', function ($provide) {
3540
$provide.factory('fetchCommitData', function ($q) {
3641
ctx.fetchCommitData = {
@@ -55,12 +60,6 @@ describe('EditRepoCommitController'.bold.underline.blue, function() {
5560
});
5661
return promisifyMock;
5762
});
58-
$provide.factory('github', function ($q) {
59-
ctx.github = {
60-
branchOrPRCommits: branchCommitsStub
61-
};
62-
return ctx.github;
63-
});
6463
});
6564

6665
angular.mock.inject(function (
@@ -121,7 +120,7 @@ describe('EditRepoCommitController'.bold.underline.blue, function() {
121120

122121
expect($scope.model.attrs.commit).to.equal(sha);
123122
});
124-
123+
125124
it('should trigger update on change of locked attribute', function () {
126125
expect($scope.ERCC.autoDeploy()).to.not.be.ok;
127126

@@ -160,14 +159,15 @@ describe('EditRepoCommitController'.bold.underline.blue, function() {
160159

161160
describe('updating the instance when new commits are made', function() {
162161
beforeEach(function() {
163-
branchCommitsStub.returns(newCommits);
162+
getCommitStub.returns(commits);
164163
$scope.ERCC.acv = {
165164
attrs: {
166165
repo: 'foo/bar',
167166
commit: 'commitSha'
168167
},
169-
githubRepo: {}
170-
};
168+
githubRepo: {
169+
newBranch: newBranchStub
170+
}};
171171
$scope.$digest();
172172
});
173173

@@ -176,11 +176,11 @@ describe('EditRepoCommitController'.bold.underline.blue, function() {
176176
});
177177

178178
it('should update the instance when triggered by user', function () {
179-
branchCommitsStub.reset();
179+
getCommitStub.reset();
180180
$scope.ERCC.updateInstance();
181181
$scope.$digest();
182-
expect($scope.ERCC.latestBranchCommit.sha).to.equal(newCommits[0].sha);
183-
sinon.assert.calledOnce(branchCommitsStub);
182+
expect($scope.ERCC.latestBranchCommit.attrs.sha).to.equal(commits.models[0].attrs.sha);
183+
sinon.assert.calledOnce(getCommitStub);
184184
sinon.assert.calledOnce(updateInstanceWithNewAcvDataStub);
185185
});
186186
});

0 commit comments

Comments
 (0)