Refactor repo actions support
This commit refactors repo-actions support to use components and make the implementation much simpler. It also fixes a bug with buttons being displayed when they shouldn't be.
This commit is contained in:
parent
082427c469
commit
d9cb754879
9
app/components/build-repo-actions.coffee
Normal file
9
app/components/build-repo-actions.coffee
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
`import Ember from 'ember'`
|
||||||
|
`import RepoActionsItemComponentMixin from 'travis/utils/repo-actions-item-component-mixin'`
|
||||||
|
|
||||||
|
BuildRepoActionsComponent = Ember.Component.extend(RepoActionsItemComponentMixin,
|
||||||
|
item: Ember.computed.alias('build')
|
||||||
|
type: 'build'
|
||||||
|
)
|
||||||
|
|
||||||
|
`export default BuildRepoActionsComponent`
|
9
app/components/job-repo-actions.coffee
Normal file
9
app/components/job-repo-actions.coffee
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
`import Ember from 'ember'`
|
||||||
|
`import RepoActionsItemComponentMixin from 'travis/utils/repo-actions-item-component-mixin'`
|
||||||
|
|
||||||
|
JobRepoActionsComponent = Ember.Component.extend(RepoActionsItemComponentMixin,
|
||||||
|
item: Ember.computed.alias('job')
|
||||||
|
type: 'job'
|
||||||
|
)
|
||||||
|
|
||||||
|
`export default JobRepoActionsComponent`
|
15
app/components/repo-actions.coffee
Normal file
15
app/components/repo-actions.coffee
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
`import Ember from 'ember'`
|
||||||
|
|
||||||
|
RepoActionsComponent = Ember.Component.extend(
|
||||||
|
displayCodeClimate: (->
|
||||||
|
@get('repo.githubLanguage') == 'Ruby'
|
||||||
|
).property('repo.githubLanguage')
|
||||||
|
|
||||||
|
actions:
|
||||||
|
codeClimatePopup: ->
|
||||||
|
$('.popup').removeClass('display')
|
||||||
|
$('#code-climate').addClass('display')
|
||||||
|
return false
|
||||||
|
)
|
||||||
|
|
||||||
|
`export default RepoActionsComponent`
|
|
@ -92,11 +92,13 @@ Build = Model.extend DurationCalculations,
|
||||||
@get('jobs').filterBy('canCancel').length
|
@get('jobs').filterBy('canCancel').length
|
||||||
).property('jobs.@each.canCancel')
|
).property('jobs.@each.canCancel')
|
||||||
|
|
||||||
|
canRestart: Ember.computed.alias('isFinished')
|
||||||
|
|
||||||
cancel: (->
|
cancel: (->
|
||||||
Ajax.post "/builds/#{@get('id')}/cancel"
|
Ajax.post "/builds/#{@get('id')}/cancel"
|
||||||
)
|
)
|
||||||
|
|
||||||
requeue: ->
|
restart: ->
|
||||||
Ajax.post "/builds/#{@get('id')}/restart"
|
Ajax.post "/builds/#{@get('id')}/restart"
|
||||||
|
|
||||||
formattedFinishedAt: (->
|
formattedFinishedAt: (->
|
||||||
|
|
|
@ -91,6 +91,8 @@ Job = Model.extend DurationCalculations,
|
||||||
!@get('isFinished')
|
!@get('isFinished')
|
||||||
).property('state')
|
).property('state')
|
||||||
|
|
||||||
|
canRestart: Ember.computed.alias('isFinished')
|
||||||
|
|
||||||
cancel: (->
|
cancel: (->
|
||||||
Ajax.post "/jobs/#{@get('id')}/cancel"
|
Ajax.post "/jobs/#{@get('id')}/cancel"
|
||||||
)
|
)
|
||||||
|
@ -103,7 +105,7 @@ Job = Model.extend DurationCalculations,
|
||||||
@clearLog()
|
@clearLog()
|
||||||
@get('log').fetch()
|
@get('log').fetch()
|
||||||
|
|
||||||
requeue: ->
|
restart: ->
|
||||||
Ajax.post "/jobs/#{@get('id')}/restart"
|
Ajax.post "/jobs/#{@get('id')}/restart"
|
||||||
|
|
||||||
appendLog: (part) ->
|
appendLog: (part) ->
|
||||||
|
|
|
@ -54,6 +54,12 @@ User = Model.extend
|
||||||
permissions
|
permissions
|
||||||
).property()
|
).property()
|
||||||
|
|
||||||
|
hasAccessToRepo: (repo) ->
|
||||||
|
id = if repo.get then repo.get('id') else repo
|
||||||
|
|
||||||
|
if permissions = @get('permissions')
|
||||||
|
permissions.contains parseInt(id)
|
||||||
|
|
||||||
type: (->
|
type: (->
|
||||||
'user'
|
'user'
|
||||||
).property()
|
).property()
|
||||||
|
|
|
@ -65,8 +65,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{{view 'repo-actions'}}
|
{{repo-actions build=build repo=build.repo user=auth.currentUser}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
20
app/templates/components/build-repo-actions.hbs
Normal file
20
app/templates/components/build-repo-actions.hbs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{{#if canCancel}}
|
||||||
|
{{#if cancelling}}
|
||||||
|
<span class="sync-spinner sync-spinner--grey"><i></i><i></i><i></i></span>
|
||||||
|
{{else}}
|
||||||
|
<a href="#" {{action "cancel"}} class="button-circle"
|
||||||
|
title="Cancel Build">
|
||||||
|
<span class="icon icon--cancel"></span>
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if canRestart}}
|
||||||
|
{{#if restarting}}
|
||||||
|
<span class="sync-spinner sync-spinner--grey"><i></i><i></i><i></i></span>
|
||||||
|
{{else}}
|
||||||
|
<a href="#" {{action "restart"}} class="button-circle" title="Restart Build">
|
||||||
|
<span class="icon icon--trigger">
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
44
app/templates/components/code-climate-popup.hbs
Normal file
44
app/templates/components/code-climate-popup.hbs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<div id="code-climate" class="popup">
|
||||||
|
<img src="/images/icons/code-climate-logo.svg" id="code-climate-logo"/>
|
||||||
|
<a href="#" class="close" {{action "popupClose" target=view}}></a>
|
||||||
|
<p>
|
||||||
|
<b>Want test coverage for your tests?</b>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Integrating <a href="https://codeclimate.com">Code Climate's test coverage</a> reporting with your test
|
||||||
|
suite on Travis CI allows to track changes in coverage over time. If you haven't tried it out already, <a
|
||||||
|
{{bind-attr href=config.codeClimateUrl}}" target="_blank">sign
|
||||||
|
up today</a> to improve your code's quality. New customers get 20% off for the first three months!
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
It only takes a few steps, once you've set up your project:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li>
|
||||||
|
Add the `code-climate-reporter` gem to your Gemfile:<br/>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
gem "codeclimate-test-reporter", group: :test, require: nil
|
||||||
|
</pre>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Load the reporter in your `test_helper` or `spec_helper`, putting it at the very top:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
require "codeclimate-test-reporter"
|
||||||
|
CodeClimate::TestReporter.start
|
||||||
|
</pre>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Add the Code Climate token to your .travis.yml:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
addons:
|
||||||
|
code_climate:
|
||||||
|
repo_token: adf08323...
|
||||||
|
</pre>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
19
app/templates/components/job-repo-actions.hbs
Normal file
19
app/templates/components/job-repo-actions.hbs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{{#if canCancel}}
|
||||||
|
{{#if cancelling}}
|
||||||
|
<span class="sync-spinner sync-spinner--grey"><i></i><i></i><i></i></span>
|
||||||
|
{{else}}
|
||||||
|
<a href="#" {{action "cancel"}} class="button-circle" title="Cancel Job">
|
||||||
|
<span class="icon icon--cancel"></span>
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if canRestart}}
|
||||||
|
{{#if restarting}}
|
||||||
|
<span class="sync-spinner sync-spinner--grey"><i></i><i></i><i></i></span>
|
||||||
|
{{else}}
|
||||||
|
<a href="#" {{action "restart"}} class="button-circle" title="Restart Job">
|
||||||
|
<span class="icon icon--trigger">
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
33
app/templates/components/repo-actions.hbs
Normal file
33
app/templates/components/repo-actions.hbs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<div id="actions" class="repo-main-tools">
|
||||||
|
|
||||||
|
{{! TODO: when `component` helper is available we could just use
|
||||||
|
with a component name based on type that is passed here }}
|
||||||
|
{{#if job}}
|
||||||
|
{{job-repo-actions job=job user=user repo=repo}}
|
||||||
|
{{else}}
|
||||||
|
{{build-repo-actions build=build user=user repo=repo}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if displayCodeClimate}}
|
||||||
|
<a href="#" name="code-climate"
|
||||||
|
{{action "codeClimatePopup"}} class="button-circle open-popup"
|
||||||
|
{{bind-attr class=":open-popup"}} title="Test Coverage with Code Climate">
|
||||||
|
<span class="icon icon--codeclimate"></span>
|
||||||
|
</a>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="remove-log-popup" class="popup">
|
||||||
|
<a href="#" class="close" {{action "popupClose" target=view}}></a>
|
||||||
|
<p><strong>This action will remove the log permanently!</strong></p>
|
||||||
|
<p>Do you want to continue?</p>
|
||||||
|
<p>
|
||||||
|
<a class="sync_now button" {{action "removeLog" target="view"}}>Yes, please!</a>
|
||||||
|
<span class="or">or</span>
|
||||||
|
<a href="#" class="cancel" {{action "popupClose" target=view}}>Cancel</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{code-climate-popup}}
|
|
@ -55,7 +55,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{{view 'repo-actions'}}
|
{{repo-actions job=job repo=job.repo user=auth.currentUser}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
<div id="actions" class="repo-main-tools">
|
|
||||||
|
|
||||||
{{#if view.displayCancelBuild}}
|
|
||||||
<a href="#" {{action "cancelBuild" target=view}} class="button-circle"
|
|
||||||
{{bind-attr class="view.canCancelBuild::disabled"}} title="Cancel Build">
|
|
||||||
<span class="icon icon--cancel"></span>
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
{{#if view.displayCancelJob}}
|
|
||||||
<a href="#" {{action "cancelJob" target=view}} class="button-circle"
|
|
||||||
{{bind-attr class="view.canCancelJob::disabled"}} title="Cancel Job">
|
|
||||||
<span class="icon icon--cancel"></span>
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
{{#if view.displayRequeueBuild}}
|
|
||||||
{{#if view.requeueing}}
|
|
||||||
<span class="sync-spinner sync-spinner--grey"><i></i><i></i><i></i></span>
|
|
||||||
{{else}}
|
|
||||||
<a href="#" {{action "requeueBuild" target=view}} class="button-circle"
|
|
||||||
{{bind-attr class="view.canRequeueBuild::disabled"}} title="Restart Build">
|
|
||||||
<span class="icon icon--trigger">
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
||||||
{{#if view.displayRequeueJob}}
|
|
||||||
{{#if view.requeueing}}
|
|
||||||
<span class="sync-spinner sync-spinner--grey"><i></i><i></i><i></i></span>
|
|
||||||
{{else}}
|
|
||||||
<a href="#" {{action "requeueJob" target=view}} class="button-circle"
|
|
||||||
{{bind-attr class="view.canRequeueJob::disabled"}} title="Restart Job">
|
|
||||||
<span class="icon icon--trigger">
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
||||||
{{#if view.displayCodeClimate}}
|
|
||||||
<a href="#" name="code-climate"
|
|
||||||
{{action "codeClimatePopup" target=view}} class="button-circle open-popup"
|
|
||||||
{{bind-attr class=":open-popup"}} title="Test Coverage with Code Climate">
|
|
||||||
<span class="icon icon--codeclimate"></span>
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="remove-log-popup" class="popup">
|
|
||||||
<a href="#" class="close" {{action "popupClose" target=view}}></a>
|
|
||||||
<p><strong>This action will remove the log permanently!</strong></p>
|
|
||||||
<p>Do you want to continue?</p>
|
|
||||||
<p>
|
|
||||||
<a class="sync_now button" {{action "removeLog" target="view"}}>Yes, please!</a>
|
|
||||||
<span class="or">or</span>
|
|
||||||
<a href="#" class="cancel" {{action "popupClose" target=view}}>Cancel</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
|
@ -17,7 +17,6 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="regenerate-key" class="popup">
|
<div id="regenerate-key" class="popup">
|
||||||
<a href="#" class="close" {{action "popupClose" target=view}}></a>
|
<a href="#" class="close" {{action "popupClose" target=view}}></a>
|
||||||
<p>
|
<p>
|
||||||
|
@ -45,48 +44,3 @@
|
||||||
You can read more about encryption keys <a href="http://about.travis-ci.org/docs/user/encryption-keys/">in Travis documentation</a>
|
You can read more about encryption keys <a href="http://about.travis-ci.org/docs/user/encryption-keys/">in Travis documentation</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="code-climate" class="popup">
|
|
||||||
<img src="/images/icons/code-climate-logo.svg" id="code-climate-logo"/>
|
|
||||||
<a href="#" class="close" {{action "popupClose" target=view}}></a>
|
|
||||||
<p>
|
|
||||||
<b>Want test coverage for your tests?</b>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Integrating <a href="https://codeclimate.com">Code Climate's test coverage</a> reporting with your test
|
|
||||||
suite on Travis CI allows to track changes in coverage over time. If you haven't tried it out already, <a
|
|
||||||
{{bind-attr href=config.codeClimateUrl}}" target="_blank">sign
|
|
||||||
up today</a> to improve your code's quality. New customers get 20% off for the first three months!
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
It only takes a few steps, once you've set up your project:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ol>
|
|
||||||
<li>
|
|
||||||
Add the `code-climate-reporter` gem to your Gemfile:<br/>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
gem "codeclimate-test-reporter", group: :test, require: nil
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
Load the reporter in your `test_helper` or `spec_helper`, putting it at the very top:
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
require "codeclimate-test-reporter"
|
|
||||||
CodeClimate::TestReporter.start
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
Add the Code Climate token to your .travis.yml:
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
addons:
|
|
||||||
code_climate:
|
|
||||||
repo_token: adf08323...
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
</ol>
|
|
||||||
</div>
|
|
||||||
|
|
50
app/utils/repo-actions-item-component-mixin.coffee
Normal file
50
app/utils/repo-actions-item-component-mixin.coffee
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
`import Ember from 'ember'`
|
||||||
|
|
||||||
|
Mixin = Ember.Mixin.create(
|
||||||
|
restarting: false
|
||||||
|
cancelling: false
|
||||||
|
|
||||||
|
userHasPermissionForRepo: (->
|
||||||
|
repo = @get('repo')
|
||||||
|
user = @get('user')
|
||||||
|
if user && repo
|
||||||
|
user.hasAccessToRepo(repo)
|
||||||
|
).property('user.permissions.[]', 'repo', 'user')
|
||||||
|
|
||||||
|
canCancel: (->
|
||||||
|
@get('item.canCancel') && @get('userHasPermissionForRepo')
|
||||||
|
).property('userHasPermissionForRepo', 'item.canCancel')
|
||||||
|
|
||||||
|
canRestart: (->
|
||||||
|
@get('item.canRestart') && @get('userHasPermissionForRepo')
|
||||||
|
).property('userHasPermissionForRepo', 'item.canRestart')
|
||||||
|
|
||||||
|
actions:
|
||||||
|
restart: ->
|
||||||
|
return if @get('restarting')
|
||||||
|
@set('restarting', true)
|
||||||
|
|
||||||
|
onFinished = =>
|
||||||
|
@set('restarting', false)
|
||||||
|
@get('item').restart().then(onFinished, onFinished)
|
||||||
|
|
||||||
|
cancel: ->
|
||||||
|
return if @get('cancelling')
|
||||||
|
@set('cancelling', true)
|
||||||
|
|
||||||
|
type = @get('type')
|
||||||
|
|
||||||
|
@get('item').cancel().then =>
|
||||||
|
@set('cancelling', false)
|
||||||
|
Travis.flash(success: "#{type.capitalize()} has been successfully canceled.")
|
||||||
|
, (xhr) =>
|
||||||
|
@set('cancelling', false)
|
||||||
|
if xhr.status == 422
|
||||||
|
Travis.flash(error: "This #{type} can't be canceled")
|
||||||
|
else if xhr.status == 403
|
||||||
|
Travis.flash(error: "You don't have sufficient access to cancel this #{type}")
|
||||||
|
else
|
||||||
|
Travis.flash(error: "An error occured when canceling the #{type}")
|
||||||
|
)
|
||||||
|
|
||||||
|
`export default Mixin`
|
|
@ -1,172 +0,0 @@
|
||||||
`import Ember from 'ember'`
|
|
||||||
`import { plainTextLog as plainTextLogUrl } from 'travis/utils/urls'`
|
|
||||||
`import Job from 'travis/models/job'`
|
|
||||||
`import config from 'travis/config/environment'`
|
|
||||||
`import BasicView from 'travis/views/basic'`
|
|
||||||
|
|
||||||
View = BasicView.extend
|
|
||||||
templateName: 'repos/show/actions'
|
|
||||||
|
|
||||||
repoBinding: 'controller.repo'
|
|
||||||
buildBinding: 'controller.build'
|
|
||||||
jobBinding: 'controller.job'
|
|
||||||
tabBinding: 'controller.tab'
|
|
||||||
currentUserBinding: 'controller.currentUser'
|
|
||||||
|
|
||||||
actions:
|
|
||||||
requeueBuild: ->
|
|
||||||
if @get('canRequeueBuild')
|
|
||||||
@requeue @get('build')
|
|
||||||
|
|
||||||
requeueJob: ->
|
|
||||||
if @get('canRequeueJob')
|
|
||||||
@requeue @get('_job')
|
|
||||||
|
|
||||||
cancelBuild: ->
|
|
||||||
if @get('canCancelBuild')
|
|
||||||
Travis.flash(notice: 'Build cancellation has been scheduled.')
|
|
||||||
@get('build').cancel().then ->
|
|
||||||
Travis.flash(success: 'Build has been successfully canceled.')
|
|
||||||
, (xhr) ->
|
|
||||||
if xhr.status == 422
|
|
||||||
Travis.flash(error: 'This build can\'t be canceled')
|
|
||||||
else if xhr.status == 403
|
|
||||||
Travis.flash(error: 'You don\'t have sufficient access to cancel this build')
|
|
||||||
else
|
|
||||||
Travis.flash(error: 'An error occured when canceling the build')
|
|
||||||
|
|
||||||
|
|
||||||
removeLog: ->
|
|
||||||
@popupCloseAll()
|
|
||||||
if @get('canRemoveLog')
|
|
||||||
job = @get('_job') || @get('build.jobs.firstObject')
|
|
||||||
job.removeLog().then ->
|
|
||||||
Travis.flash(success: 'Log has been successfully removed.')
|
|
||||||
, (xhr) ->
|
|
||||||
if xhr.status == 409
|
|
||||||
Travis.flash(error: 'Log can\'t be removed')
|
|
||||||
else if xhr.status == 401
|
|
||||||
Travis.flash(error: 'You don\'t have sufficient access to remove the log')
|
|
||||||
else
|
|
||||||
Travis.flash(error: 'An error occured when removing the log')
|
|
||||||
|
|
||||||
cancelJob: ->
|
|
||||||
if @get('canCancelJob')
|
|
||||||
Travis.flash(notice: 'Job cancellation has been scheduled.')
|
|
||||||
@get('_job').cancel().then ->
|
|
||||||
Travis.flash(success: 'Job has been successfully canceled.')
|
|
||||||
, (xhr) ->
|
|
||||||
if xhr.status == 422
|
|
||||||
Travis.flash(error: 'This job can\'t be canceled')
|
|
||||||
else if xhr.status == 403
|
|
||||||
Travis.flash(error: 'You don\'t have sufficient access to cancel this job')
|
|
||||||
else
|
|
||||||
Travis.flash(error: 'An error occured when canceling the job')
|
|
||||||
|
|
||||||
codeClimatePopup: ->
|
|
||||||
@popupCloseAll()
|
|
||||||
console.log('repo-actions view')
|
|
||||||
@popup('code-climate')
|
|
||||||
return false
|
|
||||||
|
|
||||||
hasPermission: (->
|
|
||||||
if permissions = @get('currentUser.permissions')
|
|
||||||
permissions.contains parseInt(@get('repo.id'))
|
|
||||||
).property('currentUser.permissions.length', 'repo.id')
|
|
||||||
|
|
||||||
hasPushPermission: (->
|
|
||||||
if permissions = @get('currentUser.pushPermissions')
|
|
||||||
permissions.contains parseInt(@get('repo.id'))
|
|
||||||
).property('currentUser.pushPermissions.length', 'repo.id')
|
|
||||||
|
|
||||||
displayRequeueBuild: (->
|
|
||||||
@get('isBuildTab') && @get('build.isFinished')
|
|
||||||
).property('isBuildTab', 'build.isFinished')
|
|
||||||
|
|
||||||
canRequeueBuild: (->
|
|
||||||
@get('displayRequeueBuild') && @get('hasPermission')
|
|
||||||
).property('displayRequeueBuild', 'hasPermission')
|
|
||||||
|
|
||||||
displayRequeueJob: (->
|
|
||||||
@get('isJobTab') && @get('job.isFinished')
|
|
||||||
).property('isJobTab', 'job.isFinished')
|
|
||||||
|
|
||||||
canRequeueJob: (->
|
|
||||||
@get('displayRequeueJob') && @get('hasPermission')
|
|
||||||
).property('displayRequeueJob', 'hasPermission')
|
|
||||||
|
|
||||||
showDownloadLog: (->
|
|
||||||
@get('jobIdForLog') && (@get('isJobTab') || @get('isBuildTab'))
|
|
||||||
).property('jobIdForLog', 'isJobTab', 'isBuildTab')
|
|
||||||
|
|
||||||
_job: (->
|
|
||||||
if id = @get('jobIdForLog')
|
|
||||||
store =Travis.__container__.lookup('store:main')
|
|
||||||
store.find('job', id)
|
|
||||||
store.recordForId('job', id)
|
|
||||||
).property('jobIdForLog')
|
|
||||||
|
|
||||||
jobIdForLog: (->
|
|
||||||
job = @get('job.id')
|
|
||||||
unless job
|
|
||||||
if @get('build.jobs.length') == 1
|
|
||||||
job = @get('build.jobs').objectAt?(0).get?('id')
|
|
||||||
job
|
|
||||||
).property('job.id', 'build.jobs.firstObject.id', 'build.jobs.length')
|
|
||||||
|
|
||||||
plainTextLogUrl: (->
|
|
||||||
if id = @get('jobIdForLog')
|
|
||||||
url = plainTextLogUrl(id)
|
|
||||||
if config.pro
|
|
||||||
token = @get('job.log.token') || @get('build.jobs.firstObject.log.token')
|
|
||||||
url += "&access_token=#{token}"
|
|
||||||
url
|
|
||||||
).property('jobIdForLog', 'job.log.token', 'build.jobs.firstObject.log.token')
|
|
||||||
|
|
||||||
canRemoveLog: (->
|
|
||||||
@get('displayRemoveLog')
|
|
||||||
).property('displayRemoveLog')
|
|
||||||
|
|
||||||
displayRemoveLog: (->
|
|
||||||
if job = @get('_job')
|
|
||||||
(@get('isJobTab') || (@get('isBuildTab') && @get('build.jobs.length') == 1)) &&
|
|
||||||
job.get('canRemoveLog') && @get('hasPermission')
|
|
||||||
).property('isJobTab', 'isBuildTab', 'build.jobs.length', '_job.canRemoveLog', 'jobIdForLog', 'canRemoveLog', 'hasPermission')
|
|
||||||
|
|
||||||
canCancelBuild: (->
|
|
||||||
@get('displayCancelBuild') && @get('hasPermission')
|
|
||||||
).property('displayCancelBuild', 'hasPermission')
|
|
||||||
|
|
||||||
displayCancelBuild: (->
|
|
||||||
@get('isBuildTab') && @get('build.canCancel')
|
|
||||||
).property('isBuildTab', 'build.canCancel')
|
|
||||||
|
|
||||||
canCancelJob: (->
|
|
||||||
@get('displayCancelJob') && @get('hasPermission')
|
|
||||||
).property('displayCancelJob', 'hasPermission')
|
|
||||||
|
|
||||||
displayCancelJob: (->
|
|
||||||
@get('isJobTab') && @get('job.canCancel')
|
|
||||||
).property('isJobTab', 'job.canCancel')
|
|
||||||
|
|
||||||
isJobTab: (->
|
|
||||||
@get('tab') == 'job'
|
|
||||||
).property('tab', 'repo.id')
|
|
||||||
|
|
||||||
isBuildTab: (->
|
|
||||||
['current', 'build'].indexOf(@get('tab')) > -1
|
|
||||||
).property('tab')
|
|
||||||
|
|
||||||
displayCodeClimate: (->
|
|
||||||
@get('repo.githubLanguage') == 'Ruby'
|
|
||||||
).property('repo.githubLanguage')
|
|
||||||
|
|
||||||
requeueFinished: ->
|
|
||||||
@set('requeueing', false)
|
|
||||||
|
|
||||||
requeue: (thing) ->
|
|
||||||
return if @get('requeueing')
|
|
||||||
@set('requeueing', true)
|
|
||||||
thing.requeue().then(this.requeueFinished.bind(this), this.requeueFinished.bind(this))
|
|
||||||
|
|
||||||
`export default View`
|
|
|
@ -63,5 +63,5 @@ test 'visiting /dashboard', ->
|
||||||
visit '/dashboard'
|
visit '/dashboard'
|
||||||
|
|
||||||
andThen ->
|
andThen ->
|
||||||
equal find('.tiles .repo').length, 1, 'there should be one repo displayed on dashboard'
|
equal find('.dashboard-active .row').length, 1, 'there should be one repo displayed on dashboard'
|
||||||
equal find('.tiles .repo').text(), 'travis-web', 'travis-web repository should be displayed'
|
equal find('.dashboard-active .row h2').text(), 'travis-web', 'travis-web repository should be displayed'
|
||||||
|
|
58
tests/unit/components/build-repo-actions-test.coffee
Normal file
58
tests/unit/components/build-repo-actions-test.coffee
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
`import { test, moduleForComponent } from 'ember-qunit'`
|
||||||
|
|
||||||
|
moduleForComponent 'build-repo-actions', 'BuildRepoActionsComponent', {
|
||||||
|
# specify the other units that are required for this test
|
||||||
|
# needs: ['component:foo', 'helper:bar']
|
||||||
|
}
|
||||||
|
|
||||||
|
test 'it shows cancel button if canCancel is true', ->
|
||||||
|
component = @subject(canCancel: true)
|
||||||
|
@append()
|
||||||
|
|
||||||
|
ok component.$('a[title="Cancel Build"]').length, 'cancel link should be visible'
|
||||||
|
|
||||||
|
test 'it shows restart button if canRestart is true', ->
|
||||||
|
component = @subject(canRestart: true)
|
||||||
|
@append()
|
||||||
|
|
||||||
|
ok component.$('a[title="Restart Build"]').length, 'restart link should be visible'
|
||||||
|
|
||||||
|
test 'user can cancel if she has permissions to a repo and build is cancelable', ->
|
||||||
|
build = Ember.Object.create(canCancel: false, userHasPermissionForRepo: true)
|
||||||
|
|
||||||
|
component = @subject(build: build, userHasPermissionForRepo: false)
|
||||||
|
ok !component.get('canCancel')
|
||||||
|
|
||||||
|
component.set('userHasPermissionForRepo', true)
|
||||||
|
ok !component.get('canCancel')
|
||||||
|
|
||||||
|
build.set('canCancel', true)
|
||||||
|
ok component.get('canCancel')
|
||||||
|
|
||||||
|
test 'user can restart if she has permissions to a repo and job is restartable', ->
|
||||||
|
build = Ember.Object.create(canRestart: false, userHasPermissionForRepo: true)
|
||||||
|
|
||||||
|
component = @subject(build: build, userHasPermissionForRepo: false)
|
||||||
|
ok !component.get('canRestart')
|
||||||
|
|
||||||
|
component.set('userHasPermissionForRepo', true)
|
||||||
|
ok !component.get('canRestart')
|
||||||
|
|
||||||
|
build.set('canRestart', true)
|
||||||
|
ok component.get('canRestart')
|
||||||
|
|
||||||
|
test 'it properly checks for user permissions for a repo', ->
|
||||||
|
expect 3
|
||||||
|
|
||||||
|
repo = Ember.Object.create(id: 44)
|
||||||
|
user = Ember.Object.extend(
|
||||||
|
hasAccessToRepo: (repo) ->
|
||||||
|
ok repo.get('id', 44)
|
||||||
|
ok true, 'hasAccessToRepo was called'
|
||||||
|
|
||||||
|
false
|
||||||
|
).create()
|
||||||
|
|
||||||
|
component = @subject(user: user, repo: repo)
|
||||||
|
|
||||||
|
ok !component.get('userHasPermissionForRepo'), 'user should not have access to a repo'
|
56
tests/unit/components/job-repo-actions-test.coffee
Normal file
56
tests/unit/components/job-repo-actions-test.coffee
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
`import { test, moduleForComponent } from 'ember-qunit'`
|
||||||
|
|
||||||
|
moduleForComponent 'job-repo-actions', 'JobRepoActionsComponent', {
|
||||||
|
}
|
||||||
|
|
||||||
|
test 'it shows cancel button if canCancel is true', ->
|
||||||
|
component = @subject(canCancel: true)
|
||||||
|
@append()
|
||||||
|
|
||||||
|
ok component.$('a[title="Cancel Job"]').length, 'cancel link should be visible'
|
||||||
|
|
||||||
|
test 'it shows restart button if canRestart is true', ->
|
||||||
|
component = @subject(canRestart: true)
|
||||||
|
@append()
|
||||||
|
|
||||||
|
ok component.$('a[title="Restart Job"]').length, 'restart link should be visible'
|
||||||
|
|
||||||
|
test 'user can cancel if she has permissions to a repo and job is cancelable', ->
|
||||||
|
job = Ember.Object.create(canCancel: false, userHasPermissionForRepo: true)
|
||||||
|
|
||||||
|
component = @subject(job: job, userHasPermissionForRepo: false)
|
||||||
|
ok !component.get('canCancel')
|
||||||
|
|
||||||
|
component.set('userHasPermissionForRepo', true)
|
||||||
|
ok !component.get('canCancel')
|
||||||
|
|
||||||
|
job.set('canCancel', true)
|
||||||
|
ok component.get('canCancel')
|
||||||
|
|
||||||
|
test 'user can restart if she has permissions to a repo and job is restartable', ->
|
||||||
|
job = Ember.Object.create(canRestart: false, userHasPermissionForRepo: true)
|
||||||
|
|
||||||
|
component = @subject(job: job, userHasPermissionForRepo: false)
|
||||||
|
ok !component.get('canRestart')
|
||||||
|
|
||||||
|
component.set('userHasPermissionForRepo', true)
|
||||||
|
ok !component.get('canRestart')
|
||||||
|
|
||||||
|
job.set('canRestart', true)
|
||||||
|
ok component.get('canRestart')
|
||||||
|
|
||||||
|
test 'it properly checks for user permissions for a repo', ->
|
||||||
|
expect 3
|
||||||
|
|
||||||
|
repo = Ember.Object.create(id: 44)
|
||||||
|
user = Ember.Object.extend(
|
||||||
|
hasAccessToRepo: (repo) ->
|
||||||
|
ok repo.get('id', 44)
|
||||||
|
ok true, 'hasAccessToRepo was called'
|
||||||
|
|
||||||
|
false
|
||||||
|
).create()
|
||||||
|
|
||||||
|
component = @subject(user: user, repo: repo)
|
||||||
|
|
||||||
|
ok !component.get('userHasPermissionForRepo'), 'user should not have access to a repo'
|
25
tests/unit/components/repo-actions-test.coffee
Normal file
25
tests/unit/components/repo-actions-test.coffee
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
`import { test, moduleForComponent } from 'ember-qunit'`
|
||||||
|
|
||||||
|
moduleForComponent 'repo-actions', 'RepoActionsComponent', {
|
||||||
|
# specify the other units that are required for this test
|
||||||
|
needs: ['component:build-repo-actions', 'component:job-repo-actions']
|
||||||
|
}
|
||||||
|
|
||||||
|
test 'it displays code climate if the repo language is ruby', ->
|
||||||
|
# creates the component instance
|
||||||
|
repo = Ember.Object.create(githubLanguage: 'Ruby')
|
||||||
|
|
||||||
|
component = @subject(repo: repo)
|
||||||
|
@append()
|
||||||
|
|
||||||
|
ok component.get('displayCodeClimate'), 'component should try to display code climate'
|
||||||
|
ok component.$('a[name=code-climate]').length, 'component should render a code climate button'
|
||||||
|
|
||||||
|
test 'it doesn\'t display code climate for other languages', ->
|
||||||
|
repo = Ember.Object.create(githubLanguage: 'Go')
|
||||||
|
|
||||||
|
component = @subject(repo: repo)
|
||||||
|
@append()
|
||||||
|
|
||||||
|
ok !component.get('displayCodeClimate'), 'component should not try to display code climate'
|
||||||
|
ok !component.$('a[name=code-climate]').length, 'component should not render a code climate button'
|
Loading…
Reference in New Issue
Block a user