Include repositoryId as an attribute on build
For some reason (probably some problem with one of the serializers) we sometimes lack an id attribute for a promise that we get for a repo relationship on build. Because of that doing `build.get('repo.id')` may sometimes return undefined. A temporary workaround is to make sure that we always can access the `repository_id` property.
This commit is contained in:
parent
3946077c96
commit
d59e402314
|
@ -19,6 +19,7 @@ Build = Model.extend DurationCalculations,
|
||||||
pullRequestTitle: DS.attr()
|
pullRequestTitle: DS.attr()
|
||||||
pullRequestNumber: DS.attr('number')
|
pullRequestNumber: DS.attr('number')
|
||||||
eventType: DS.attr('string')
|
eventType: DS.attr('string')
|
||||||
|
repositoryId: DS.attr('number')
|
||||||
|
|
||||||
repo: DS.belongsTo('repo', async: true)
|
repo: DS.belongsTo('repo', async: true)
|
||||||
commit: DS.belongsTo('commit')
|
commit: DS.belongsTo('commit')
|
||||||
|
|
|
@ -35,7 +35,7 @@ Repo = Model.extend
|
||||||
builds: (->
|
builds: (->
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
builds = @store.filter('build', event_type: ['push', 'api'], repository_id: id, (b) ->
|
builds = @store.filter('build', event_type: ['push', 'api'], repository_id: id, (b) ->
|
||||||
b.get('repo.id') == id && (b.get('eventType') == 'push' || b.get('eventType') == 'api')
|
b.get('repositoryId')+'' == id+'' && (b.get('eventType') == 'push' || b.get('eventType') == 'api')
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: move to controller
|
# TODO: move to controller
|
||||||
|
@ -52,7 +52,7 @@ Repo = Model.extend
|
||||||
pullRequests: (->
|
pullRequests: (->
|
||||||
id = @get('id')
|
id = @get('id')
|
||||||
builds = @store.filter('build', event_type: 'pull_request', repository_id: id, (b) ->
|
builds = @store.filter('build', event_type: 'pull_request', repository_id: id, (b) ->
|
||||||
b.get('repo.id') == id && b.get('eventType') == 'pull_request'
|
b.get('repositoryId')+'' == id+'' && b.get('eventType') == 'pull_request'
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: move to controller
|
# TODO: move to controller
|
||||||
|
|
|
@ -16,4 +16,23 @@ Serializer = V2FallbackSerializer.extend
|
||||||
else
|
else
|
||||||
@_super.apply(this, arguments)
|
@_super.apply(this, arguments)
|
||||||
|
|
||||||
|
normalize: (modelClass, resourceHash) ->
|
||||||
|
result = @_super(modelClass, resourceHash)
|
||||||
|
|
||||||
|
data = result.data
|
||||||
|
|
||||||
|
# for some reasone repo's promise not always has its id set
|
||||||
|
# so we can't always do build.get('repo.id')
|
||||||
|
# this ensures that repositoryId is always reachable on build
|
||||||
|
# TODO: look into the real cause of the problem (maybe it will be gone
|
||||||
|
# after fully switching to V3 and/or updating ember-data)
|
||||||
|
if repoId = resourceHash.repository_id
|
||||||
|
data.attributes.repositoryId = repoId
|
||||||
|
else if resourceHash.repository
|
||||||
|
if href = resourceHash.repository['@href']
|
||||||
|
id = href.match(/\d+/)[0]
|
||||||
|
data.attributes.repositoryId = id
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
`export default Serializer`
|
`export default Serializer`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user