diff --git a/app/build/model.js b/app/build/model.js index 1cee46cd4..0d3455e18 100644 --- a/app/build/model.js +++ b/app/build/model.js @@ -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() }); diff --git a/app/components/pipeline-header/template.hbs b/app/components/pipeline-header/template.hbs index 942b4dd63..086eab66b 100644 --- a/app/components/pipeline-header/template.hbs +++ b/app/components/pipeline-header/template.hbs @@ -1,2 +1,2 @@ {{#link-to "pipeline" pipeline.id}}

{{pipeline.appId}}

{{/link-to}} -{{fa-icon "fa-code-fork"}} {{pipeline.repoData.branch}} +{{fa-icon "fa-code-fork"}} {{pipeline.branch}} diff --git a/app/components/search-list/template.hbs b/app/components/search-list/template.hbs index d5ef88757..7ba3ce1d6 100644 --- a/app/components/search-list/template.hbs +++ b/app/components/search-list/template.hbs @@ -3,7 +3,7 @@
  • {{#link-to "pipeline" pipeline.id}} {{pipeline.appId}} - {{fa-icon "fa-code-fork"}}{{pipeline.repoData.branch}} + {{fa-icon "fa-code-fork"}}{{pipeline.branch}} {{/link-to}}
  • {{/each}} diff --git a/app/pipeline/model.js b/app/pipeline/model.js index 6b75dfdb6..ec329ead1 100644 --- a/app/pipeline/model.js +++ b/app/pipeline/model.js @@ -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; } }) }); diff --git a/app/pipeline/serializer.js b/app/pipeline/serializer.js index 61beeaa87..ef5d04a38 100644 --- a/app/pipeline/serializer.js +++ b/app/pipeline/serializer.js @@ -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') }); } }); diff --git a/tests/acceptance/build-test.js b/tests/acceptance/build-test.js index 26b2e7163..4d1b8be94 100644 --- a/tests/acceptance/build-test.js +++ b/tests/acceptance/build-test.js @@ -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'] @@ -50,7 +55,11 @@ moduleForAcceptance('Acceptance | build', { }, { name: 'test' }], - status: 'FAILURE' + status: 'FAILURE', + commit: { + url: 'https://github.com/commit', + message: 'merge this' + } }) ]); @@ -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'); diff --git a/tests/acceptance/pipeline-builds-test.js b/tests/acceptance/pipeline-builds-test.js index 31fc1f34f..58cc58f96 100644 --- a/tests/acceptance/pipeline-builds-test.js +++ b/tests/acceptance/pipeline-builds-test.js @@ -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'] @@ -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'); diff --git a/tests/integration/components/pipeline-header/component-test.js b/tests/integration/components/pipeline-header/component-test.js index da9b8300b..1c1af5398 100644 --- a/tests/integration/components/pipeline-header/component-test.js +++ b/tests/integration/components/pipeline-header/component-test.js @@ -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); diff --git a/tests/unit/pipeline/model-test.js b/tests/unit/pipeline/model-test.js index bf31d9ec7..78e2748b6 100644 --- a/tests/unit/pipeline/model-test.js +++ b/tests/unit/pipeline/model-test.js @@ -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'); }); }); + diff --git a/tests/unit/pipeline/serializer-test.js b/tests/unit/pipeline/serializer-test.js index db365c84b..ad1b9eb1f 100644 --- a/tests/unit/pipeline/serializer-test.js +++ b/tests/unit/pipeline/serializer-test.js @@ -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' }); }); });