This commit is contained in:
Sven Fuchs 2012-07-08 15:25:24 +02:00
parent 2a8f2bd4bf
commit fb618f05a7
14 changed files with 244 additions and 96 deletions

View File

@ -38,6 +38,9 @@ Ember.ENV.RAISE_ON_DEPRECATION = true
@routes = Travis.Router.create()
@routes.start()
receive: (event, data) ->
Travis.app.store.loadData(event, data)
connect: ->
@controller = Em.Controller.create()
view = Em.View.create

View File

@ -21,7 +21,7 @@ require 'travis/log'
if values.length == 0 then '-' else values.join(', ')
formatMessage: (message, options) ->
message = message or ''
message = message || ''
message = message.split(/\n/)[0] if options.short
@_emojize(@_escape(message)).replace /\n/g, '<br/>'

View File

@ -1,20 +1,21 @@
require 'travis/model'
@Travis.Branch = Travis.Model.extend Travis.Helpers,
repository_id: DS.attr('number')
number: DS.attr('number')
branch: DS.attr('string')
message: DS.attr('string')
result: DS.attr('number')
duration: DS.attr('number')
started_at: DS.attr('string')
finished_at: DS.attr('string')
repositoryId: DS.attr('number')
commitId: DS.attr('number')
number: DS.attr('number')
branch: DS.attr('string')
message: DS.attr('string')
result: DS.attr('number')
duration: DS.attr('number')
started_at: DS.attr('string')
finished_at: DS.attr('string')
commit: DS.belongsTo('Travis.Commit')
repository: (->
Travis.Repository.find @get('repository_id') if @get('repository_id')
).property('repository_id').cacheable()
Travis.Repository.find @get('repositoryId') if @get('repositoryId')
).property('repositoryId')
tick: ->
@notifyPropertyChange 'started_at'

View File

@ -1,6 +1,8 @@
require 'travis/model'
@Travis.Build = Travis.Model.extend
repositoryId: DS.attr('number')
commitId: DS.attr('number')
state: DS.attr('string')
number: DS.attr('number')
branch: DS.attr('string')
@ -16,7 +18,7 @@ require 'travis/model'
author_email: DS.attr('string')
compare_url: DS.attr('string')
repository: DS.belongsTo('Travis.Repository')
repository: DS.belongsTo('Travis.Repository', key: 'repository_id')
commit: DS.belongsTo('Travis.Commit')
# jobs: DS.hasMany('Travis.Job')

View File

@ -1,6 +1,7 @@
require 'travis/model'
@Travis.Commit = Travis.Model.extend
buildId: DS.attr('number')
sha: DS.attr('string')
branch: DS.attr('string')
message: DS.attr('string')
@ -10,4 +11,4 @@ require 'travis/model'
committerName: DS.attr('string')
committerEmail: DS.attr('string')
build: DS.belongsTo('Travis.Build')
build: DS.belongsTo('Travis.Build', key: 'buildId')

View File

@ -1,22 +1,23 @@
require 'travis/model'
@Travis.Job = Travis.Model.extend
repository_id: DS.attr('number')
build_id: DS.attr('number')
log_id: DS.attr('number')
queue: DS.attr('string')
state: DS.attr('string')
number: DS.attr('string')
result: DS.attr('number')
duration: DS.attr('number')
started_at: DS.attr('string')
finished_at: DS.attr('string')
allow_failure: DS.attr('boolean')
repositoryId: DS.attr('number')
commitId: DS.attr('number')
buildId: DS.attr('number')
logId: DS.attr('number')
queue: DS.attr('string')
state: DS.attr('string')
number: DS.attr('string')
result: DS.attr('number')
duration: DS.attr('number')
started_at: DS.attr('string')
finished_at: DS.attr('string')
allow_failure: DS.attr('boolean')
repository: DS.belongsTo('Travis.Repository')
commit: DS.belongsTo('Travis.Commit')
build: DS.belongsTo('Travis.Build')
log: DS.belongsTo('Travis.Artifact')
commit: DS.belongsTo('Travis.Commit')
build: DS.belongsTo('Travis.Build')
log: DS.belongsTo('Travis.Artifact')
config: (->
@getPath 'data.config'

View File

@ -3,3 +3,25 @@ require 'store/rest_adapter'
Travis.Store = DS.Store.extend
revision: 4
adapter: Travis.RestAdapter.create()
loadData: (event, data) ->
mappings = @adapter.get('mappings')
name = event.split(':').shift()
if type = mappings[name]
@_loadMany(this, type, data)
else if type = mappings[@adapter.pluralize(name)]
@_loadOne(this, type, data)
else
throw "can't find type for #{name}" unless type
_loadOne: (store, type, json) ->
root = type.singularName()
@adapter.sideload(store, type, json, root)
type.load(json[root])
_loadMany: (store, type, json) ->
root = type.pluralName()
@adapter.sideload(store, type, json, root)
@loadMany(type, json[root])

View File

@ -1,77 +1,87 @@
require 'models'
@Travis.RestAdapter = DS.RESTAdapter.extend
init: ->
@_super()
# TODO should be able to specify these as strings
@set 'mappings',
builds: Travis.Build,
commits: Travis.Commit,
jobs: Travis.Job
DEFAULT_OPTIONS:
accepts:
json: 'application/vnd.travis-ci.2+json'
mappings:
repositories: Travis.Repository
builds: Travis.Build
commits: Travis.Commit
jobs: Travis.Job
plurals:
repository: 'repositories',
build: 'builds'
branch: 'branches'
job: 'jobs'
worker: 'workers'
find: (store, type, id) ->
url = '/' + type.buildURL(id)
# console.log "find: #{url}"
ajax: (url, method, options) ->
@_super(url, method, $.extend(options, @DEFAULT_OPTIONS))
@ajax url, 'GET',
success: (json) ->
root = type.singularName()
@sideload(store, type, json, root)
store.load(type, json[root])
accepts:
json: 'application/vnd.travis-ci.2+json'
# init: ->
# @_super()
findMany: (store, type, ids) ->
url = '/' + type.buildURL()
# console.log "findMany: #{url}"
# find: (store, type, id) ->
# url = '/' + type.buildURL(id)
# # console.log "find: #{url}"
# @ajax url, 'GET',
# success: (json) =>
# @loadOne(store, type, json)
@ajax url, 'GET',
data:
ids: ids
success: (json) ->
root = type.pluralName()
@sideload(store, type, json, root)
store.loadMany(type, json[root])
accepts:
json: 'application/vnd.travis-ci.2+json'
# findMany: (store, type, ids) ->
# url = '/' + type.buildURL()
# query = { ids: ids }
# # console.log "findMany: #{url}"
# @ajax url, 'GET',
# data: query
# success: (json) =>
# @loadMany(store, type, json)
findAll: (store, type) ->
url = '/' + type.buildURL()
# console.log "findAll: #{url}"
# findAll: (store, type) ->
# url = '/' + type.buildURL()
# # console.log "findAll: #{url}"
# @ajax url, 'GET',
# success: (json) =>
# @loadMany(store, type, json)
@ajax url, 'GET',
success: (json) ->
root = type.pluralName()
@sideload(store, type, json, root)
store.loadMany(type, json[root])
accepts:
json: 'application/vnd.travis-ci.2+json'
# findQuery: (store, type, query, recordArray) ->
# url = '/' + type.buildURL()
# # console.log "findQuery: #{url} (#{query})"
# @ajax url, 'GET',
# data: query,
# success: (json) =>
# @loadQuery(store, type, json, recordArray)
findQuery: (store, type, query, recordArray) ->
url = '/' + type.buildURL()
# console.log "findQuery: #{url} (#{query})"
# updateRecord: (store, type, record) ->
# id = get(record, record.get('primaryKey') || 'id')
# url = '/' + type.buildURL(id)
# data = { root: record.toJSON() }
# @ajax url, 'PUT',
# data: data
# success: (json) =>
# loadUpdatedRecord(store, type, record)
@ajax url, 'GET',
data: query,
success: (json) ->
root = type.pluralName()
@sideload(store, type, json, root)
recordArray.load(json[root])
accepts:
json: 'application/vnd.travis-ci.2+json'
# loadOne: (store, type, json) ->
# root = type.singularName()
# @sideload(store, type, json, root)
# store.load(type, json[root])
# loadMany: (store, type, json) ->
# root = type.pluralName()
# @sideload(store, type, json, root)
# store.loadMany(type, json[root])
# loadQuery: (store, type, json, recordArray) ->
# root = type.pluralName()
# @sideload(store, type, json, root)
# recordArray.load(json[root])
# loadUpdatedRecord: (store, type, json) ->
# root = type.singularName()
# @sideload(store, type, json, root)
# store.didUpdateRecord(record, json && json[root])
updateRecord: (store, type, record) ->
id = get(record, record.get('primaryKey') || 'id')
url = '/' + type.buildURL(id)
data = root: record.toJSON()
@ajax url, 'PUT',
data: data
success: (json) ->
root = type.singularName()
@sideload(store, type, json, root)
store.didUpdateRecord(record, json && json[root])

View File

@ -83,6 +83,12 @@ for repository in repositories
responseTime: responseTime
responseText: { repositories: [repository] }
$.mockjax
url: '/builds'
data: { ids: repository.build_ids }
responseTime: responseTime
responseText: { builds: $.select(builds, (build) -> repository.build_ids.indexOf(build.id) != -1) }
for build in builds
$.mockjax
url: '/builds/' + build.id

View File

@ -0,0 +1,55 @@
describe 'events', ->
beforeEach ->
app
waitFor buildRendered
it 'foo', ->
# Travis.app.receive 'job:created',
# job:
# id: 10
# repository_id: 1
# build_id: 10
# commit_id: 10
# log_id: 10
# number: '10.1'
# commit:
# id: 10
# sha: '1234567'
# branch: 'master'
# message: 'commit message 1'
# author_name: 'author name'
# author_email: 'author@email.com'
# committer_name: 'committer name'
# committer_email: 'committer@email.com'
# compare_url: 'http://github.com/compare/0123456..1234567'
Travis.app.receive 'build:started',
repository:
id: 10
owner: 'travis-ci'
name: 'travis-support'
slug: 'travis-ci/travis-support'
build_ids: [10]
last_build_id: 10
last_build_number: 10
last_build_started_at: '2012-07-02T00:02:00Z'
description: 'Description of travis-hub'
build:
id: 10
repository_id: 1
commit_id: 10
job_ids: [10]
number: 10
event_type: 'push'
config: { rvm: ['rbx'] }
commit:
id: 10
sha: '1234567'
branch: 'master'
message: 'commit message 1'
author_name: 'author name'
author_email: 'author@email.com'
committer_name: 'committer name'
committer_email: 'committer@email.com'
compare_url: 'http://github.com/compare/0123456..1234567'

View File

@ -3128,8 +3128,8 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
if (cachedValue) {
var key = association.options.key || get(this, 'namingConvention').keyToJSONKey(name),
ids = data.get(key) || [];
var clientIds;
var clientIds;
if(association.options.embedded) {
clientIds = store.loadMany(association.type, ids).clientIds;
} else {
@ -3137,7 +3137,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
return store.clientIdForId(association.type, id);
});
}
set(cachedValue, 'content', Ember.A(clientIds));
cachedValue.fetch();
}
@ -3738,7 +3738,7 @@ var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
DS.RESTAdapter = DS.Adapter.extend({
bulkCommit: false,
createRecord: function(store, type, record) {
var root = this.rootForType(type);

File diff suppressed because one or more lines are too long

View File

@ -79,6 +79,53 @@
});
});
}).call(this);
(function() {
describe('events', function() {
beforeEach(function() {
app;
return waitFor(buildRendered);
});
return it('foo', function() {
return Travis.app.receive('build:started', {
repository: {
id: 10,
owner: 'travis-ci',
name: 'travis-support',
slug: 'travis-ci/travis-support',
build_ids: [10],
last_build_id: 10,
last_build_number: 10,
last_build_started_at: '2012-07-02T00:02:00Z',
description: 'Description of travis-hub'
},
build: {
id: 10,
repository_id: 1,
commit_id: 10,
job_ids: [10],
number: 10,
event_type: 'push',
config: {
rvm: ['rbx']
}
},
commit: {
id: 10,
sha: '1234567',
branch: 'master',
message: 'commit message 1',
author_name: 'author name',
author_email: 'author@email.com',
committer_name: 'committer name',
committer_email: 'committer@email.com',
compare_url: 'http://github.com/compare/0123456..1234567'
}
});
});
});
}).call(this);
(function() {

View File

@ -25224,8 +25224,8 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
if (cachedValue) {
var key = association.options.key || get(this, 'namingConvention').keyToJSONKey(name),
ids = data.get(key) || [];
var clientIds;
var clientIds;
if(association.options.embedded) {
clientIds = store.loadMany(association.type, ids).clientIds;
} else {
@ -25233,7 +25233,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
return store.clientIdForId(association.type, id);
});
}
set(cachedValue, 'content', Ember.A(clientIds));
cachedValue.fetch();
}
@ -25834,7 +25834,7 @@ var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
DS.RESTAdapter = DS.Adapter.extend({
bulkCommit: false,
createRecord: function(store, type, record) {
var root = this.rootForType(type);