Use lastBuild from defaultBranch on repository
One thing that is not standard here is a serializer for branch, which uses @href as id. At this point branches don't have ids and ember-data needs one, so using @href is the easiest way.
This commit is contained in:
parent
d9cff6e8b4
commit
47439657a1
|
@ -14,9 +14,9 @@ export default V3Adapter.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hash.data.include) {
|
if(hash.data.include) {
|
||||||
hash.data.include += ',repository.last_build,build.commit';
|
hash.data.include += ',repository.default_branch,branch.last_build,build.commit';
|
||||||
} else {
|
} else {
|
||||||
hash.data.include = 'repository.last_build,build.commit';
|
hash.data.include = 'repository.default_branch,branch.last_build,build.commit';
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._super(url, type, hash);
|
return this._super(url, type, hash);
|
||||||
|
|
|
@ -15,6 +15,10 @@ ReposListItemComponent = Ember.Component.extend Polling,
|
||||||
@get('repo') == @get('selectedRepo')
|
@get('repo') == @get('selectedRepo')
|
||||||
).property('selectedRepo')
|
).property('selectedRepo')
|
||||||
|
|
||||||
|
color: (->
|
||||||
|
colorForState(@get('repo.defaultBranch.lastBuild.state'))
|
||||||
|
).property('repo.defaultBranch.lastBuild.state')
|
||||||
|
|
||||||
scrollTop: (->
|
scrollTop: (->
|
||||||
if (window.scrollY > 0)
|
if (window.scrollY > 0)
|
||||||
$('html, body').animate({scrollTop: 0}, 200)
|
$('html, body').animate({scrollTop: 0}, 200)
|
||||||
|
|
|
@ -77,15 +77,15 @@ Controller = Ember.Controller.extend
|
||||||
Ember.run.scheduleOnce('actions', this, @_lastBuildDidChange);
|
Ember.run.scheduleOnce('actions', this, @_lastBuildDidChange);
|
||||||
|
|
||||||
_lastBuildDidChange: ->
|
_lastBuildDidChange: ->
|
||||||
build = @get('repo.lastBuild')
|
build = @get('repo.defaultBranch.lastBuild')
|
||||||
@set('build', build)
|
@set('build', build)
|
||||||
|
|
||||||
stopObservingLastBuild: ->
|
stopObservingLastBuild: ->
|
||||||
@removeObserver('repo.lastBuild', this, 'lastBuildDidChange')
|
@removeObserver('repo.defaultBranch.lastBuild', this, 'lastBuildDidChange')
|
||||||
|
|
||||||
observeLastBuild: ->
|
observeLastBuild: ->
|
||||||
@lastBuildDidChange()
|
@lastBuildDidChange()
|
||||||
@addObserver('repo.lastBuild', this, 'lastBuildDidChange')
|
@addObserver('repo.defaultBranch.lastBuild', this, 'lastBuildDidChange')
|
||||||
|
|
||||||
connectTab: (tab) ->
|
connectTab: (tab) ->
|
||||||
# TODO: such implementation seems weird now, because we render
|
# TODO: such implementation seems weird now, because we render
|
||||||
|
|
|
@ -2,25 +2,6 @@
|
||||||
`import Model from 'travis/models/model'`
|
`import Model from 'travis/models/model'`
|
||||||
|
|
||||||
Branch = Model.extend
|
Branch = Model.extend
|
||||||
repositoryId: DS.attr('number')
|
lastBuild: DS.belongsTo('build')
|
||||||
commitId: DS.attr('number')
|
|
||||||
state: DS.attr()
|
|
||||||
number: DS.attr('number')
|
|
||||||
branch: DS.attr()
|
|
||||||
message: DS.attr()
|
|
||||||
result: DS.attr('number')
|
|
||||||
duration: DS.attr('number')
|
|
||||||
startedAt: DS.attr()
|
|
||||||
finishedAt: DS.attr()
|
|
||||||
|
|
||||||
commit: DS.belongsTo('commit')
|
|
||||||
|
|
||||||
repo: (->
|
|
||||||
@store.find('repo', @get('repositoryId')) if @get('repositoryId')
|
|
||||||
).property('repositoryId')
|
|
||||||
|
|
||||||
updateTimes: ->
|
|
||||||
@notifyPropertyChange 'started_at'
|
|
||||||
@notifyPropertyChange 'finished_at'
|
|
||||||
|
|
||||||
`export default Branch`
|
`export default Branch`
|
||||||
|
|
|
@ -13,10 +13,12 @@ Repo = Model.extend
|
||||||
private: DS.attr('boolean')
|
private: DS.attr('boolean')
|
||||||
githubLanguage: DS.attr()
|
githubLanguage: DS.attr()
|
||||||
active: DS.attr()
|
active: DS.attr()
|
||||||
lastBuild: DS.belongsTo('build')
|
|
||||||
|
#lastBuild: DS.belongsTo('build')
|
||||||
|
defaultBranch: DS.belongsTo('branch')
|
||||||
|
|
||||||
withLastBuild: ->
|
withLastBuild: ->
|
||||||
@filter( (repo) -> repo.get('lastBuild') )
|
@filter( (repo) -> repo.get('defaultBranch.lastBuild') )
|
||||||
|
|
||||||
sshKey: (->
|
sshKey: (->
|
||||||
@store.find('ssh_key', @get('id'))
|
@store.find('ssh_key', @get('id'))
|
||||||
|
@ -83,27 +85,21 @@ Repo = Model.extend
|
||||||
(@get('slug') || '').split('/')[1]
|
(@get('slug') || '').split('/')[1]
|
||||||
).property('slug')
|
).property('slug')
|
||||||
|
|
||||||
lastBuildDuration: (->
|
|
||||||
duration = @get('_lastBuildDuration')
|
|
||||||
duration = durationFromHelper(@get('lastBuildStartedAt'), @get('lastBuildFinishedAt')) unless duration
|
|
||||||
duration
|
|
||||||
).property('_lastBuildDuration', 'lastBuildStartedAt', 'lastBuildFinishedAt')
|
|
||||||
|
|
||||||
sortOrderForLandingPage: (->
|
sortOrderForLandingPage: (->
|
||||||
state = @get('lastBuildState')
|
state = @get('defaultBranch.lastBuild.state')
|
||||||
if state != 'passed' && state != 'failed'
|
if state != 'passed' && state != 'failed'
|
||||||
0
|
0
|
||||||
else
|
else
|
||||||
parseInt(@get('lastBuildId'))
|
parseInt(@get('defaultBranch.lastBuild.id'))
|
||||||
).property('lastBuildId', 'lastBuildState')
|
).property('defaultBranch.lastBuild.id', 'defaultBranch.lastBuild.state')
|
||||||
|
|
||||||
sortOrder: (->
|
sortOrder: (->
|
||||||
# cuz sortAscending seems buggy when set to false
|
# cuz sortAscending seems buggy when set to false
|
||||||
if lastBuildFinishedAt = @get('lastBuildFinishedAt')
|
if lastBuildFinishedAt = @get('defaultBranch.lastBuild.finishedAt')
|
||||||
- new Date(lastBuildFinishedAt).getTime()
|
- new Date(lastBuildFinishedAt).getTime()
|
||||||
else
|
else
|
||||||
- new Date('9999').getTime() - parseInt(@get('lastBuildId'))
|
- new Date('9999').getTime() - parseInt(@get('defaultBranch.lastBuild.id'))
|
||||||
).property('lastBuildFinishedAt', 'lastBuildId')
|
).property('defaultBranch.lastBuild.state', 'defaultBranch.lastBuild.finishedAt')
|
||||||
|
|
||||||
stats: (->
|
stats: (->
|
||||||
if @get('slug')
|
if @get('slug')
|
||||||
|
@ -114,7 +110,7 @@ Repo = Model.extend
|
||||||
).property('slug')
|
).property('slug')
|
||||||
|
|
||||||
updateTimes: ->
|
updateTimes: ->
|
||||||
@notifyPropertyChange 'lastBuildDuration'
|
@notifyPropertyChange 'defaultBranch.lastBuild.duration'
|
||||||
|
|
||||||
regenerateKey: (options) ->
|
regenerateKey: (options) ->
|
||||||
@get('ajax').ajax '/repos/' + @get('id') + '/key', 'post', options
|
@get('ajax').ajax '/repos/' + @get('id') + '/key', 'post', options
|
||||||
|
@ -153,7 +149,7 @@ Repo.reopenClass
|
||||||
|
|
||||||
withLastBuild: (store) ->
|
withLastBuild: (store) ->
|
||||||
repos = store.filter('repo', {}, (build) ->
|
repos = store.filter('repo', {}, (build) ->
|
||||||
build.get('lastBuild')
|
build.get('defaultBranch.lastBuild')
|
||||||
)
|
)
|
||||||
|
|
||||||
repos.then () ->
|
repos.then () ->
|
||||||
|
|
|
@ -6,7 +6,7 @@ Route = TravisRoute.extend
|
||||||
@controllerFor('repo').activate('current')
|
@controllerFor('repo').activate('current')
|
||||||
|
|
||||||
renderTemplate: ->
|
renderTemplate: ->
|
||||||
if @modelFor('repo').get('lastBuild')
|
if @modelFor('repo').get('defaultBranch.lastBuild')
|
||||||
@render 'build'
|
@render 'build'
|
||||||
else
|
else
|
||||||
@render 'builds/not_found'
|
@render 'builds/not_found'
|
||||||
|
|
12
app/serializers/branch.js
Normal file
12
app/serializers/branch.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import V3Serializer from 'travis/serializers/v3';
|
||||||
|
|
||||||
|
export default V3Serializer.extend({
|
||||||
|
extractAttributes(klass, payload) {
|
||||||
|
payload.id = payload['@href'];
|
||||||
|
return this._super(...arguments);
|
||||||
|
},
|
||||||
|
extractId(modelClass, resourceHash) {
|
||||||
|
return resourceHash.id || resourceHash['@href'];
|
||||||
|
}
|
||||||
|
});
|
|
@ -3,8 +3,5 @@
|
||||||
|
|
||||||
Serializer = V2FallbackSerializer.extend
|
Serializer = V2FallbackSerializer.extend
|
||||||
isNewSerializerAPI: true
|
isNewSerializerAPI: true
|
||||||
attrs: {
|
|
||||||
_lastBuildDuration: { key: 'last_build_duration' }
|
|
||||||
}
|
|
||||||
|
|
||||||
`export default Serializer`
|
`export default Serializer`
|
||||||
|
|
|
@ -52,7 +52,7 @@ export default DS.JSONSerializer.extend({
|
||||||
if(type = payload['@type']) {
|
if(type = payload['@type']) {
|
||||||
items = payload[type];
|
items = payload[type];
|
||||||
} else {
|
} else {
|
||||||
items = payload[primaryModelClass.modelName + 's'];
|
items = payload[primaryModelClass.modelName.underscore() + 's'];
|
||||||
}
|
}
|
||||||
|
|
||||||
documentHash.data = items.map((item) => {
|
documentHash.data = items.map((item) => {
|
||||||
|
|
|
@ -20,6 +20,7 @@ Store = DS.Store.extend
|
||||||
canHandleEvent: (event, data) ->
|
canHandleEvent: (event, data) ->
|
||||||
[name, type] = event.split(':')
|
[name, type] = event.split(':')
|
||||||
auth = @get('auth')
|
auth = @get('auth')
|
||||||
|
|
||||||
if event != 'job:log' && auth.get('signedIn') &&
|
if event != 'job:log' && auth.get('signedIn') &&
|
||||||
!config.pro && !config.enterprise
|
!config.pro && !config.enterprise
|
||||||
# if recent repos hasn't been opened yet, we can safely
|
# if recent repos hasn't been opened yet, we can safely
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
<div class="tile {{repo.lastBuild.state}}">
|
<div class="tile {{repo.defaultBranch.lastBuild.state}}">
|
||||||
<h2 class="tile-title {{repo.lastBuild.state}}">
|
<h2 class="tile-title {{repo.defaultBranch.lastBuild.state}}">
|
||||||
{{#if repo.slug}}
|
{{#if repo.slug}}
|
||||||
{{#link-to "repo" repo}}
|
{{#link-to "repo" repo}}
|
||||||
{{status-icon status=repo.lastBuildState}}
|
{{status-icon status=repo.defaultBranch.lastBuild.state}}
|
||||||
<span class="label-align">{{repo.slug}}</span>
|
<span class="label-align">{{repo.slug}}</span>
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
{{#if repo.slug}}
|
{{#if repo.slug}}
|
||||||
{{#if repo.lastBuild.id}}
|
{{#if repo.defaultBranch.lastBuild.id}}
|
||||||
<p class="tile-title float-right {{repo.lastBuild.state}}">
|
<p class="tile-title float-right {{repo.defaultBranch.lastBuild.state}}">
|
||||||
{{#link-to "build" repo repo.lastBuild.id}}
|
{{#link-to "build" repo repo.defaultBranch.lastBuild.id}}
|
||||||
<span class="icon-hash"></span>
|
<span class="icon-hash"></span>
|
||||||
<span class="label-align">{{lastBuild.number}}</span>
|
<span class="label-align">{{repo.defaultBranch.lastBuild.number}}</span>
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
</p>
|
</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -22,16 +22,16 @@
|
||||||
<p>
|
<p>
|
||||||
<span class="icon-clock"></span>
|
<span class="icon-clock"></span>
|
||||||
<span class="label-align">Duration:
|
<span class="label-align">Duration:
|
||||||
<abbr class="duration" title={{lastBuild.startedAt}}>
|
<abbr class="duration" title={{repo.defaultBranch.lastBuild.startedAt}}>
|
||||||
{{format-duration repo.lastBuild.duration}}
|
{{format-duration repo.defaultBranch.lastBuild.duration}}
|
||||||
</abbr></span>
|
</abbr></span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="icon-calendar"></span>
|
<span class="icon-calendar"></span>
|
||||||
<span class="label-align">Finished:
|
<span class="label-align">Finished:
|
||||||
<abbr class="finished_at timeago" title={{lastBuild.finishedAt}}>
|
<abbr class="finished_at timeago" title={{repo.defaultBranch.lastBuild.finishedAt}}>
|
||||||
{{format-time repo.lastBuild.finishedAt}}
|
{{format-time repo.defaultBranch.lastBuild.finishedAt}}
|
||||||
</abbr></span>
|
</abbr></span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
{{#if repo.active}}
|
{{#if repo.active}}
|
||||||
{{outlet}}
|
{{outlet}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#if repo.lastBuildId}}
|
{{#if repo.defaultBranch.lastBuild.id}}
|
||||||
{{outlet}}
|
{{outlet}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{not-active user=currentUser repo=repo}}
|
{{not-active user=currentUser repo=repo}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user