Compare commits
4 Commits
master
...
use-api-v3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
596217b14e | ||
![]() |
65967c10e1 | ||
![]() |
373069a76e | ||
![]() |
59747f8424 |
|
@ -1,7 +1,5 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
|
|
||||||
classNames: ['repo-main-tools']
|
classNames: ['repo-main-tools']
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import { githubRepo, statusImage } from 'travis/utils/urls';
|
import { githubRepo, statusImage } from 'travis/utils/urls';
|
||||||
import config from 'travis/config/environment';
|
import config from 'travis/config/environment';
|
||||||
|
import eventually from 'travis/utils/eventually';
|
||||||
|
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
@ -122,9 +123,12 @@ export default Ember.Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
_lastBuildDidChange() {
|
_lastBuildDidChange() {
|
||||||
var build;
|
let lastBuild = this.get('repo.lastBuild');
|
||||||
build = this.get('repo.lastBuild');
|
if(lastBuild) {
|
||||||
return this.set('build', build);
|
eventually(lastBuild, (build) => {
|
||||||
|
this.set('build', build);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
stopObservingLastBuild() {
|
stopObservingLastBuild() {
|
||||||
|
|
|
@ -26,7 +26,7 @@ Build.reopen({
|
||||||
number: attr('number'),
|
number: attr('number'),
|
||||||
message: attr('string'),
|
message: attr('string'),
|
||||||
_duration: attr('number'),
|
_duration: attr('number'),
|
||||||
_config: attr('object'),
|
_config: attr(),
|
||||||
_startedAt: attr(),
|
_startedAt: attr(),
|
||||||
_finishedAt: attr('string'),
|
_finishedAt: attr('string'),
|
||||||
pullRequest: attr('boolean'),
|
pullRequest: attr('boolean'),
|
||||||
|
|
|
@ -19,7 +19,7 @@ export default Model.extend(DurationCalculations, {
|
||||||
tags: attr(),
|
tags: attr(),
|
||||||
repositoryPrivate: attr(),
|
repositoryPrivate: attr(),
|
||||||
repositorySlug: attr(),
|
repositorySlug: attr(),
|
||||||
_config: attr('object'),
|
_config: attr(),
|
||||||
|
|
||||||
repo: belongsTo('repo', { async: true }),
|
repo: belongsTo('repo', { async: true }),
|
||||||
build: belongsTo('build', { async: true }),
|
build: belongsTo('build', { async: true }),
|
||||||
|
|
|
@ -216,7 +216,7 @@ Repo.reopenClass({
|
||||||
promise = new Ember.RSVP.Promise(function(resolve, reject) {
|
promise = new Ember.RSVP.Promise(function(resolve, reject) {
|
||||||
return store.query('repo', {
|
return store.query('repo', {
|
||||||
'repository.active': 'true',
|
'repository.active': 'true',
|
||||||
limit: 20
|
limit: 30
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return resolve(repos);
|
return resolve(repos);
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|
|
@ -63,7 +63,7 @@ var Serializer = V2FallbackSerializer.extend({
|
||||||
var data, href, id, repoId, result;
|
var data, href, id, repoId, result;
|
||||||
|
|
||||||
// TODO: remove this after switching to V3 entirely
|
// TODO: remove this after switching to V3 entirely
|
||||||
if(!resourceHash['@type'] && resourceHash.commit && resourceHash.commit.branch_is_default) {
|
if(!resourceHash['@type'] && resourceHash.commit && resourceHash.commit.hasOwnProperty('branch_is_default')) {
|
||||||
let build = resourceHash.build,
|
let build = resourceHash.build,
|
||||||
commit = resourceHash.commit;
|
commit = resourceHash.commit;
|
||||||
let branch = {
|
let branch = {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import Config from 'travis/config/environment';
|
import Config from 'travis/config/environment';
|
||||||
|
import eventually from 'travis/utils/eventually';
|
||||||
|
|
||||||
export default Ember.Service.extend({
|
export default Ember.Service.extend({
|
||||||
records: [],
|
records: [],
|
||||||
|
@ -28,7 +29,11 @@ export default Ember.Service.extend({
|
||||||
records.filter((record) => {
|
records.filter((record) => {
|
||||||
return this.get('allowFinishedBuilds') || !record.get('isFinished');
|
return this.get('allowFinishedBuilds') || !record.get('isFinished');
|
||||||
}).forEach((record) => {
|
}).forEach((record) => {
|
||||||
record.updateTimes();
|
eventually(record, function(resolvedRecord) {
|
||||||
|
if(resolvedRecord) {
|
||||||
|
resolvedRecord.updateTimes();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.set('records', []);
|
this.set('records', []);
|
||||||
|
|
9
app/utils/eventually.js
Normal file
9
app/utils/eventually.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export default function(anObjectOrAPromise, callback) {
|
||||||
|
if(anObjectOrAPromise.then) {
|
||||||
|
anObjectOrAPromise.then(function(result) {
|
||||||
|
callback(result);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(anObjectOrAPromise);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
import eventually from 'travis/utils/eventually';
|
||||||
|
|
||||||
export default Ember.Mixin.create({
|
export default Ember.Mixin.create({
|
||||||
restarting: false,
|
restarting: false,
|
||||||
|
@ -31,7 +32,12 @@ export default Ember.Mixin.create({
|
||||||
onFinished = () => {
|
onFinished = () => {
|
||||||
this.set('restarting', false);
|
this.set('restarting', false);
|
||||||
};
|
};
|
||||||
return this.get('item').restart().then(onFinished, onFinished);
|
let restart = function(record) {
|
||||||
|
record.restart().then(onFinished, onFinished);
|
||||||
|
};
|
||||||
|
eventually(this.get('item'), (item) => {
|
||||||
|
item.restart();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
cancel: function() {
|
cancel: function() {
|
||||||
var type;
|
var type;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
module.exports = function(environment) {
|
module.exports = function(environment) {
|
||||||
var ENV = {
|
var ENV = {
|
||||||
useV3API: false,
|
useV3API: true,
|
||||||
modulePrefix: 'travis',
|
modulePrefix: 'travis',
|
||||||
environment: environment,
|
environment: environment,
|
||||||
baseURL: '/',
|
baseURL: '/',
|
||||||
|
|
190
tests/unit/serializers/build-test.js
Normal file
190
tests/unit/serializers/build-test.js
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
import { moduleForModel, test } from 'ember-qunit';
|
||||||
|
|
||||||
|
moduleForModel('build', 'Unit | Serializer | build', {
|
||||||
|
// Specify the other units that are required for this test.
|
||||||
|
needs: ['serializer:build', 'model:commit', 'model:job', 'model:branch']
|
||||||
|
});
|
||||||
|
|
||||||
|
test("it normalizes the singular response", function() {
|
||||||
|
QUnit.dump.maxDepth = 10;
|
||||||
|
let payload = {
|
||||||
|
build: {
|
||||||
|
id: 1,
|
||||||
|
repository_id: 2,
|
||||||
|
commit_id: 3,
|
||||||
|
number: "10",
|
||||||
|
event_type: "push",
|
||||||
|
pull_request: false,
|
||||||
|
pull_request_title: null,
|
||||||
|
pull_request_number:null,
|
||||||
|
config: { "language": "ruby" },
|
||||||
|
state: "passed",
|
||||||
|
started_at: "2016-02-24T16:37:54Z",
|
||||||
|
finished_at:"2016-02-24T16:40:10Z",
|
||||||
|
duration: 72,
|
||||||
|
job_ids:[5, 6]
|
||||||
|
},
|
||||||
|
commit: {
|
||||||
|
id: 3,
|
||||||
|
sha: "864c69a9588024331ba0190e9d8492ae0b6d5eff",
|
||||||
|
branch: "development",
|
||||||
|
branch_is_default: false,
|
||||||
|
message: "A commit",
|
||||||
|
committed_at: "2016-02-24T16:36:23Z",
|
||||||
|
author_name: "Mr. Travis",
|
||||||
|
author_email: "nothing@travis-ci.org",
|
||||||
|
committer_name: "Mr. Travis",
|
||||||
|
committer_email: "nothing@travis-ci.org",
|
||||||
|
compare_url: "https://github.com/drogus/test-project-1/compare/432d5426aa67...864c69a95880"
|
||||||
|
},
|
||||||
|
jobs: [{
|
||||||
|
id: 5,
|
||||||
|
repository_id: 2,
|
||||||
|
build_id: 1,
|
||||||
|
commit_id: 3,
|
||||||
|
log_id: 7,
|
||||||
|
state: "passed",
|
||||||
|
number: "10.1",
|
||||||
|
config: { "language": "ruby" },
|
||||||
|
started_at: "2016-02-24T16:37:54Z",
|
||||||
|
finished_at: "2016-02-24T16:38:19Z",
|
||||||
|
queue: "builds.docker",
|
||||||
|
allow_failure: false,
|
||||||
|
tags:null
|
||||||
|
},{
|
||||||
|
id: 6,
|
||||||
|
repository_id: 2,
|
||||||
|
build_id: 1,
|
||||||
|
commit_id: 3,
|
||||||
|
log_id: 8,
|
||||||
|
state: "passed",
|
||||||
|
number: "10.2",
|
||||||
|
config: { "language": "ruby" },
|
||||||
|
started_at: "2016-02-24T16:37:54Z",
|
||||||
|
finished_at: "2016-02-24T16:38:19Z",
|
||||||
|
queue: "builds.docker",
|
||||||
|
allow_failure: false,
|
||||||
|
tags:null
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let store = this.store();
|
||||||
|
let serializer = store.serializerFor('build');
|
||||||
|
let result = serializer.normalizeResponse(store, store.modelFor('build'), payload, 1, 'findRecord');
|
||||||
|
|
||||||
|
let expectedResult = {
|
||||||
|
"data": {
|
||||||
|
"id": "1",
|
||||||
|
"type": "build",
|
||||||
|
"attributes": {
|
||||||
|
"state": "passed",
|
||||||
|
"number": 10,
|
||||||
|
"_duration": 72,
|
||||||
|
"_config": { "language": "ruby" },
|
||||||
|
"_startedAt": "2016-02-24T16:37:54Z",
|
||||||
|
"_finishedAt": "2016-02-24T16:40:10Z",
|
||||||
|
"pullRequest": false,
|
||||||
|
"pullRequestTitle": null,
|
||||||
|
"pullRequestNumber": null,
|
||||||
|
"eventType": "push"
|
||||||
|
},
|
||||||
|
"relationships": {
|
||||||
|
"branch": {
|
||||||
|
"data": {
|
||||||
|
"name": "development",
|
||||||
|
"default_branch": false,
|
||||||
|
"@href": "\/repo\/2\/branch\/development",
|
||||||
|
"id": "\/repo\/2\/branch\/development",
|
||||||
|
"type": "branch"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repo": {
|
||||||
|
"data": {
|
||||||
|
"id": "2",
|
||||||
|
"type": "repo"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"commit": {
|
||||||
|
"data": {
|
||||||
|
"id": "3",
|
||||||
|
"sha": "864c69a9588024331ba0190e9d8492ae0b6d5eff",
|
||||||
|
"branch": "development",
|
||||||
|
"branch_is_default": false,
|
||||||
|
"message": "A commit",
|
||||||
|
"committed_at": "2016-02-24T16:36:23Z",
|
||||||
|
"author_name": "Mr. Travis",
|
||||||
|
"author_email": "nothing@travis-ci.org",
|
||||||
|
"committer_name": "Mr. Travis",
|
||||||
|
"committer_email": "nothing@travis-ci.org",
|
||||||
|
"compare_url": "https:\/\/github.com\/drogus\/test-project-1\/compare\/432d5426aa67...864c69a95880",
|
||||||
|
"type": "commit"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"jobs": {
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": "5",
|
||||||
|
"repository_id": 2,
|
||||||
|
"build_id": 1,
|
||||||
|
"commit_id": 3,
|
||||||
|
"log_id": 7,
|
||||||
|
"state": "passed",
|
||||||
|
"number": "10.1",
|
||||||
|
"config": { "language": "ruby" },
|
||||||
|
"started_at": "2016-02-24T16:37:54Z",
|
||||||
|
"finished_at": "2016-02-24T16:38:19Z",
|
||||||
|
"queue": "builds.docker",
|
||||||
|
"allow_failure": false,
|
||||||
|
"tags": null,
|
||||||
|
"type": "job"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6",
|
||||||
|
"repository_id": 2,
|
||||||
|
"build_id": 1,
|
||||||
|
"commit_id": 3,
|
||||||
|
"log_id": 8,
|
||||||
|
"state": "passed",
|
||||||
|
"number": "10.2",
|
||||||
|
"config": { "language": "ruby" },
|
||||||
|
"started_at": "2016-02-24T16:37:54Z",
|
||||||
|
"finished_at": "2016-02-24T16:38:19Z",
|
||||||
|
"queue": "builds.docker",
|
||||||
|
"allow_failure": false,
|
||||||
|
"tags": null,
|
||||||
|
"type": "job"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"included": [
|
||||||
|
{
|
||||||
|
"id": "\/repo\/2\/branch\/development",
|
||||||
|
"type": "branch",
|
||||||
|
"attributes": {},
|
||||||
|
"relationships": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3",
|
||||||
|
"type": "commit",
|
||||||
|
"attributes": {},
|
||||||
|
"relationships": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "5",
|
||||||
|
"type": "job",
|
||||||
|
"attributes": {},
|
||||||
|
"relationships": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "6",
|
||||||
|
"type": "job",
|
||||||
|
"attributes": {},
|
||||||
|
"relationships": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
deepEqual(expectedResult, result);
|
||||||
|
});
|
25
tests/unit/utils/eventually-test.js
Normal file
25
tests/unit/utils/eventually-test.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import eventually from 'travis/utils/eventually';
|
||||||
|
|
||||||
|
module("eventually");
|
||||||
|
|
||||||
|
test("eventually runs a callback with passed item right away if it's not a promise", function() {
|
||||||
|
stop();
|
||||||
|
expect(1);
|
||||||
|
|
||||||
|
eventually({ foo: 'bar' }, function(result) {
|
||||||
|
equal(result.foo, 'bar');
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("eventually runs a callback when promise resolves if a passed object is a promise", function() {
|
||||||
|
stop();
|
||||||
|
expect(1);
|
||||||
|
|
||||||
|
let promise = { then: function(callback) { callback({ foo: 'bar'}); } };
|
||||||
|
eventually(promise, function(result) {
|
||||||
|
equal(result.foo, 'bar');
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user