Compare commits

...

4 Commits

Author SHA1 Message Date
Piotr Sarnacki
596217b14e Download 30 repos for the lefthand sidebar 2016-04-07 08:48:03 +02:00
Piotr Sarnacki
65967c10e1 Enable V3 API 2016-04-07 08:48:03 +02:00
Piotr Sarnacki
373069a76e Fix build serializer for v2 responses
We should create a branch object for a v2 response if branch_is_default
property is set on the commit object, not necessarily if it's true.
2016-04-07 08:48:03 +02:00
Piotr Sarnacki
59747f8424 Handle promises properly
With API V3 we have some relationships (like lastBuild on branch)
specified as asynchronuous, so sometimes we may deal with promises. This
commit fixes the situation by handling both plain records and promises.
2016-04-07 08:48:03 +02:00
12 changed files with 249 additions and 12 deletions

View File

@ -1,7 +1,5 @@
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['repo-main-tools']
});

View File

@ -1,6 +1,7 @@
import Ember from 'ember';
import { githubRepo, statusImage } from 'travis/utils/urls';
import config from 'travis/config/environment';
import eventually from 'travis/utils/eventually';
export default Ember.Controller.extend({
@ -122,9 +123,12 @@ export default Ember.Controller.extend({
},
_lastBuildDidChange() {
var build;
build = this.get('repo.lastBuild');
return this.set('build', build);
let lastBuild = this.get('repo.lastBuild');
if(lastBuild) {
eventually(lastBuild, (build) => {
this.set('build', build);
});
}
},
stopObservingLastBuild() {

View File

@ -26,7 +26,7 @@ Build.reopen({
number: attr('number'),
message: attr('string'),
_duration: attr('number'),
_config: attr('object'),
_config: attr(),
_startedAt: attr(),
_finishedAt: attr('string'),
pullRequest: attr('boolean'),

View File

@ -19,7 +19,7 @@ export default Model.extend(DurationCalculations, {
tags: attr(),
repositoryPrivate: attr(),
repositorySlug: attr(),
_config: attr('object'),
_config: attr(),
repo: belongsTo('repo', { async: true }),
build: belongsTo('build', { async: true }),

View File

@ -216,7 +216,7 @@ Repo.reopenClass({
promise = new Ember.RSVP.Promise(function(resolve, reject) {
return store.query('repo', {
'repository.active': 'true',
limit: 20
limit: 30
}).then(function() {
return resolve(repos);
}, function() {

View File

@ -63,7 +63,7 @@ var Serializer = V2FallbackSerializer.extend({
var data, href, id, repoId, result;
// 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,
commit = resourceHash.commit;
let branch = {

View File

@ -1,5 +1,6 @@
import Ember from 'ember';
import Config from 'travis/config/environment';
import eventually from 'travis/utils/eventually';
export default Ember.Service.extend({
records: [],
@ -28,7 +29,11 @@ export default Ember.Service.extend({
records.filter((record) => {
return this.get('allowFinishedBuilds') || !record.get('isFinished');
}).forEach((record) => {
record.updateTimes();
eventually(record, function(resolvedRecord) {
if(resolvedRecord) {
resolvedRecord.updateTimes();
}
});
});
this.set('records', []);

9
app/utils/eventually.js Normal file
View File

@ -0,0 +1,9 @@
export default function(anObjectOrAPromise, callback) {
if(anObjectOrAPromise.then) {
anObjectOrAPromise.then(function(result) {
callback(result);
});
} else {
callback(anObjectOrAPromise);
}
}

View File

@ -1,4 +1,5 @@
import Ember from 'ember';
import eventually from 'travis/utils/eventually';
export default Ember.Mixin.create({
restarting: false,
@ -31,7 +32,12 @@ export default Ember.Mixin.create({
onFinished = () => {
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() {
var type;

View File

@ -2,7 +2,7 @@
module.exports = function(environment) {
var ENV = {
useV3API: false,
useV3API: true,
modulePrefix: 'travis',
environment: environment,
baseURL: '/',

View 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);
});

View 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();
});
});