Skip to content

Commit

Permalink
Add allow config imports for private repositories (travis-ci#2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
weban-pl authored May 9, 2019
1 parent ae497ac commit fbdd979
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export default Controller.extend({
|| settings.hasOwnProperty('auto_cancel_pull_requests');
}),

showAllowConfigImportsSwitch: computed('model.settings', 'repo.private', function () {
let settings = this.get('model.settings');
let isPrivate = this.get('repo.private');
return isPrivate && settings.hasOwnProperty('allow_config_imports');
}),

migratedRepositorySettingsLink: computed('repo.slug', function () {
let slug = this.get('repo.slug');
return this.get('externalLinks').migratedToComSettingsLink(slug);
Expand Down
10 changes: 10 additions & 0 deletions app/templates/settings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
</section>
{{/if}}

{{#if showAllowConfigImportsSwitch}}
<section class="settings-section config-import">
<h2 class="small-title display-inline">Config Import</h2>

<ul class="settings-list--columns">
<li>{{settings-switch active=model.settings.allow_config_imports repo=repo description="Allow importing config files from this repository" key="allow_config_imports"}}</li>
</ul>
</section>
{{/if}}

<section class="settings-section">
<h2 class="small-title">Environment Variables</h2>

Expand Down
25 changes: 25 additions & 0 deletions tests/acceptance/repo/settings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,31 @@ module('Acceptance | repo settings', function (hooks) {
assert.dom('[data-test-settings-disabled-after-migration-modal]').exists();
});

test('when repository is private and allow_config_imports setting is present', async function (assert) {
this.repository.private = true;
this.repository.createSetting({ name: 'allow_config_imports', value: true });

await settingsPage.visit({ organization: 'org-login', repo: 'repository-name' });

assert.ok(settingsPage.configImportsSection.exists, 'expected auto-cancellation section to exist');
assert.ok(settingsPage.allowConfigImports.isActive, 'expected allow_config_imports pushes to be present and enabled');

const settingToRequestBody = {};

server.patch(`/repo/${this.repository.id}/setting/:setting`, function (schema, request) {
settingToRequestBody[request.params.setting] = JSON.parse(request.requestBody);
});

await settingsPage.allowConfigImports.toggle();
assert.notOk(settingsPage.allowConfigImports.isActive, 'expected allow_config_imports to be disabled');
});

test('when repository is private and allow_config_imports setting is not present', async function (assert) {
this.repository.private = true;
await settingsPage.visit({ organization: 'org-login', repo: 'repository-name' });

assert.notOk(settingsPage.configImportsSection.exists, 'expected auto-cancellation section to exist');
});

test('on a repository with auto-cancellation', async function (assert) {
this.repository.createSetting({ name: 'auto_cancel_pushes', value: true });
Expand Down
13 changes: 13 additions & 0 deletions tests/pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export default create({
exists: isVisible()
},

configImportsSection: {
scope: 'section.config-import',
exists: isVisible()
},

autoCancelPushes: {
scope: 'section.settings-section .auto_cancel_pushes.switch',

Expand All @@ -35,6 +40,14 @@ export default create({
toggle: clickable()
},

allowConfigImports: {
scope: 'section.settings-section .allow_config_imports.switch',

exists: isVisible(),
isActive: hasClass('active'),
toggle: clickable()
},

buildPushes: {
scope: 'section.settings-section .build_pushes.switch',

Expand Down

0 comments on commit fbdd979

Please sign in to comment.