Skip to content

Commit

Permalink
Adapt to v14 data-shcema
Browse files Browse the repository at this point in the history
  • Loading branch information
minzcmu committed Oct 20, 2016
1 parent 0c0858e commit 50bb3d3
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 95 deletions.
3 changes: 2 additions & 1 deletion app/build/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export default DS.Model.extend({
parameters: DS.attr(),
meta: DS.attr(),
steps: DS.attr(),
status: DS.attr('string')
status: DS.attr('string'),
commit: DS.attr()
});
2 changes: 1 addition & 1 deletion app/components/pipeline-header/template.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{#link-to "pipeline" pipeline.id}}<h1>{{pipeline.appId}}</h1>{{/link-to}}
<a href="{{pipeline.hubUrl}}" class="branch">{{fa-icon "fa-code-fork"}} {{pipeline.repoData.branch}}</a>
<a href="{{pipeline.hubUrl}}" class="branch">{{fa-icon "fa-code-fork"}} {{pipeline.branch}}</a>
2 changes: 1 addition & 1 deletion app/components/search-list/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<li>
{{#link-to "pipeline" pipeline.id}}
<span class="appId">{{pipeline.appId}}</span>
<span class="branch">{{fa-icon "fa-code-fork"}}{{pipeline.repoData.branch}}</span>
<span class="branch">{{fa-icon "fa-code-fork"}}{{pipeline.branch}}</span>
{{/link-to}}
</li>
{{/each}}
Expand Down
39 changes: 13 additions & 26 deletions app/pipeline/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,30 @@ import Ember from 'ember';
export default DS.Model.extend({
scmUrl: DS.attr('string'),
configUrl: DS.attr('string', { defaultValue: '' }),
scmUri: DS.attr('string'),
createTime: DS.attr('date'),
admins: DS.attr(),
secrets: DS.hasMany('secret', { async: true }),
jobs: DS.hasMany('job', { async: true }),
repoData: Ember.computed('scmUrl', {
scmRepo: DS.attr(),
scmRepoObject: Ember.computed('scmRepo', {
get() {
const http = /^http[s]?:\/\/([^/]+)\/([^/]+)\/([^/]+)\.git#?(.*)?/;
const git = /^git@([^:]+):([^/]+)\/([^/]+)\.git#?(.*)?/;
const scmUrl = this.get('scmUrl');
const matches = /^git@/.test(scmUrl) ? scmUrl.match(git) : scmUrl.match(http);
let host;
let owner;
let repo;
let branch;

if (matches) {
host = matches[1];
owner = matches[2];
repo = matches[3];
branch = matches[4] || 'master';
}

return { host, owner, repo, branch };
return Ember.Object.create(this.get('scmRepo'));
}
}),
appId: Ember.computed('repoData', {
appId: Ember.computed('scmRepoObject', {
get() {
const data = this.get('repoData');

return `${data.owner}:${data.repo}`;
return this.get('scmRepoObject').name;
}
}),
hubUrl: Ember.computed('repoData', {
hubUrl: Ember.computed('scmRepoObject', {
get() {
const data = this.get('repoData');

return `https://${data.host}/${data.owner}/${data.repo}`;
return this.get('scmRepoObject').url;
}
}),
branch: Ember.computed('scmRepoObject', {
get() {
return this.get('scmRepoObject').branch;
}
})
});
2 changes: 1 addition & 1 deletion app/pipeline/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default DS.RESTSerializer.extend({
* @method serializeIntoHash
*/
serializeIntoHash(hash, typeClass, snapshot) {
return Ember.merge(hash, { scmUrl: snapshot.attr('scmUrl') });
return Ember.merge(hash, { checkoutUrl: snapshot.attr('scmUrl') });
}
});
13 changes: 11 additions & 2 deletions tests/acceptance/build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ moduleForAcceptance('Acceptance | build', {
JSON.stringify({
id: 'abcd',
scmUrl: 'git@github.com:foo/bar.git#master',
scmRepo: {
name: 'foo/bar',
branch: 'master',
url: 'https://github.com/foo/bar'
},
createTime: '2016-09-15T23:12:23.760Z',
admins: { batman: true },
workflow: ['main', 'publish', 'prod']
Expand Down Expand Up @@ -50,7 +55,11 @@ moduleForAcceptance('Acceptance | build', {
}, {
name: 'test'
}],
status: 'FAILURE'
status: 'FAILURE',
commit: {
url: 'https://github.com/commit',
message: 'merge this'
}
})
]);

Expand Down Expand Up @@ -105,7 +114,7 @@ test('visiting /pipelines/:id/build/:id', function (assert) {

andThen(() => {
assert.equal(currentURL(), '/pipelines/abcd/build/1234');
assert.equal(find('a h1').text().trim(), 'foo:bar', 'incorrect pipeline name');
assert.equal(find('a h1').text().trim(), 'foo/bar', 'incorrect pipeline name');
assert.equal(find('.line1 h1').text().trim(), 'PR-50', 'incorrect job name');
assert.equal(find('span.sha').text().trim(), '#c96f36', 'incorrect sha');
assert.equal(find('.is-open .logs').text().trim(), 'bad stuff', 'incorrect logs open');
Expand Down
7 changes: 6 additions & 1 deletion tests/acceptance/pipeline-builds-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ moduleForAcceptance('Acceptance | pipeline builds', {
JSON.stringify({
id: 'abcd',
scmUrl: 'git@github.com:foo/bar.git#master',
scmRepo: {
name: 'foo/bar',
branch: 'master',
url: 'https://github.com/foo/bar'
},
createTime: '2016-09-15T23:12:23.760Z',
admins: { batman: true },
workflow: ['main', 'publish']
Expand Down Expand Up @@ -136,7 +141,7 @@ test('visiting /pipelines/abcd', function (assert) {

andThen(() => {
assert.equal(currentURL(), '/pipelines/abcd');
assert.equal(find('a h1').text().trim(), 'foo:bar', 'incorrect pipeline name');
assert.equal(find('a h1').text().trim(), 'foo/bar', 'incorrect pipeline name');
assert.equal(find('.arrow-right').length, 4, 'not enough workflow');
assert.equal(find('.arrow-right').length, 4, 'not enough workflow');
assert.equal(find('button').length, 0, 'should not have a start button');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ test('it renders', function (assert) {
const pipelineMock = {
appId: 'batman/batmobile',
hubUrl: 'http://example.com/batman/batmobile',
repoData: {
branch: 'master'
}
branch: 'master'
};

this.set('pipelineMock', pipelineMock);
Expand Down
87 changes: 29 additions & 58 deletions tests/unit/pipeline/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,80 +12,51 @@ test('it exists', function (assert) {
assert.ok(!!model);
});

test('it gets correct repo data', function (assert) {
test('it gets correct appId', function (assert) {
let model = this.subject();

Ember.run(() => {
// http - no branch
model.set('scmUrl', 'http://example.com:8080/batman/batmobile.git');

assert.deepEqual(model.get('repoData'), {
host: 'example.com:8080',
owner: 'batman',
repo: 'batmobile',
branch: 'master'
});

// https - with branch
model.set('scmUrl', 'https://example.com/batman/batmobile.git#ejectorSeat');

assert.deepEqual(model.get('repoData'), {
host: 'example.com',
owner: 'batman',
repo: 'batmobile',
branch: 'ejectorSeat'
});

// git - with branch
model.set('scmUrl', 'git@example.com:batman/batmobile.git#ejectorSeat');

assert.deepEqual(model.get('repoData'), {
host: 'example.com',
owner: 'batman',
repo: 'batmobile',
branch: 'ejectorSeat'
});

// git - no branch
model.set('scmUrl', 'git@example.com:batman/batmobile.git');

assert.deepEqual(model.get('repoData'), {
host: 'example.com',
owner: 'batman',
repo: 'batmobile',
branch: 'master'
});

// invalid url
model.set('scmUrl', 'git@example.com:batman');

assert.deepEqual(model.get('repoData'), {
host: undefined,
owner: undefined,
repo: undefined,
branch: undefined
});
const scmRepoMock = {
name: 'foo/bar',
branch: 'master',
url: 'https://github.com/foo/bar'
};

model.set('scmRepo', scmRepoMock);

assert.equal(model.get('appId'), 'foo/bar');
});
});

test('it gets correct appId', function (assert) {
test('it gets correct hub url', function (assert) {
let model = this.subject();

Ember.run(() => {
// http - no branch
model.set('scmUrl', 'http://example.com:8080/batman/batmobile.git');
const scmRepoMock = {
name: 'foo/bar',
branch: 'master',
url: 'https://github.com/foo/bar'
};

assert.equal(model.get('appId'), 'batman:batmobile');
model.set('scmRepo', scmRepoMock);

assert.equal(model.get('hubUrl'), 'https://github.com/foo/bar');
});
});

test('it gets correct hub url', function (assert) {
test('it gets correct branch', function (assert) {
let model = this.subject();

Ember.run(() => {
// http - no branch
model.set('scmUrl', 'git@example.com:batman/batmobile.git#oilSlick');
const scmRepoMock = {
name: 'foo/bar',
branch: 'master',
url: 'https://github.com/foo/bar'
};

assert.equal(model.get('hubUrl'), 'https://example.com/batman/batmobile');
model.set('scmRepo', scmRepoMock);

assert.equal(model.get('branch'), 'master');
});
});

2 changes: 1 addition & 1 deletion tests/unit/pipeline/serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('it does not post with model name as key', function (assert) {
const payload = JSON.parse(request.requestBody);

assert.deepEqual(payload, {
scmUrl: 'git@example.com:foo/bar.git'
checkoutUrl: 'git@example.com:foo/bar.git'
});
});
});

0 comments on commit 50bb3d3

Please sign in to comment.