Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
feat(settings): simplified repo settings by extending org level settings
Browse files Browse the repository at this point in the history
BREAKING CHANGE: it is now assumed that there is an account level settings definition, so fewer
details are defined per project. if settings are not defined in a .github repo, most of the config
will no longer be applied

closes #4
  • Loading branch information
travi committed May 2, 2019
1 parent ee83dee commit d4f774a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 122 deletions.
4 changes: 2 additions & 2 deletions src/scaffolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import scaffoldSettings from './settings-scaffolder';
import create from './create';
import {factory} from './github-client-factory';

export async function scaffold({name, owner, projectRoot, projectType, description, homepage, visibility}) {
export async function scaffold({name, owner, projectRoot, description, homepage, visibility}) {
info('Generating GitHub');

const octokit = factory();

const [, creationResult] = await Promise.all([
scaffoldSettings(projectRoot, name, description, homepage, visibility, projectType),
scaffoldSettings(projectRoot, name, description, homepage, visibility),
...octokit ? [create(name, owner, visibility, octokit)] : []
]);

Expand Down
42 changes: 5 additions & 37 deletions src/settings-scaffolder.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
import {info} from '@travi/cli-messages';
import writeYaml from '../third-party-wrappers/write-yaml';

export default function scaffoldSettings(projectRoot, name, description, homepage, visibility, projectType) {
export default function scaffoldSettings(projectRoot, name, description, homepage, visibility) {
info('Writing settings file', {level: 'secondary'});

return writeYaml(`${projectRoot}/.github/settings.yml`, {
repository: {
name,
description,
homepage,
private: 'Public' !== visibility,
has_wiki: false,
has_projects: false,
has_downloads: false,
allow_squash_merge: false,
allow_merge_commit: true,
allow_rebase_merge: true
},
labels: [
{name: 'bug', color: 'ee0701'},
{name: 'duplicate', color: 'cccccc'},
{name: 'enhancement', color: '84b6eb'},
{name: 'help wanted', color: '128A0C'},
{name: 'invalid', color: 'e6e6e6'},
{name: 'question', color: 'cc317c'},
{name: 'wontfix', color: 'ffffff'},
{name: 'breaking change', color: 'e0fc28'},
('JavaScript' === projectType) ? {name: 'greenkeeper', color: '00c775'} : undefined
].filter(Boolean),
branches: [
{
name: 'master',
protection: {
required_pull_request_reviews: null,
required_status_checks: null,
restrictions: null,
enforce_admins: true
}
}
]
});
return writeYaml(
`${projectRoot}/.github/settings.yml`,
{_extends: '.github', repository: {name, description, homepage, private: 'Public' !== visibility}}
);
}
23 changes: 2 additions & 21 deletions test/unit/scaffolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ suite('github', () => {
const projectName = any.string();
const description = any.sentence();
const homepage = any.url();
const projectType = any.word();
const projectOwner = any.word();
const visibility = any.word();

Expand All @@ -34,27 +33,10 @@ suite('github', () => {
clientFactory.factory.returns(octokitClient);

assert.deepEqual(
await scaffold({
projectRoot,
name: projectName,
owner: projectOwner,
description,
homepage,
projectType,
visibility
}),
await scaffold({projectRoot, name: projectName, owner: projectOwner, description, homepage, visibility}),
creationResult
);

assert.calledWith(
settingsScaffolder.default,
projectRoot,
projectName,
description,
homepage,
visibility,
projectType
);
assert.calledWith(settingsScaffolder.default, projectRoot, projectName, description, homepage, visibility);
});

test('that the repo is not created if an octokit client is not available', async () => {
Expand All @@ -67,7 +49,6 @@ suite('github', () => {
owner: projectOwner,
description,
homepage,
projectType,
visibility
}),
{}
Expand Down
66 changes: 4 additions & 62 deletions test/unit/settings-scaffolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,72 +27,14 @@ suite('settings', () => {
assert.calledWith(
yamlWriter.default,
`${projectRoot}/.github/settings.yml`,
{
repository: {
name: projectName,
description,
homepage,
private: true,
has_wiki: false,
has_projects: false,
has_downloads: false,
allow_squash_merge: false,
allow_merge_commit: true,
allow_rebase_merge: true
},
labels: [
{name: 'bug', color: 'ee0701'},
{name: 'duplicate', color: 'cccccc'},
{name: 'enhancement', color: '84b6eb'},
{name: 'help wanted', color: '128A0C'},
{name: 'invalid', color: 'e6e6e6'},
{name: 'question', color: 'cc317c'},
{name: 'wontfix', color: 'ffffff'},
{name: 'breaking change', color: 'e0fc28'}
],
branches: [
{
name: 'master',
protection: {
required_pull_request_reviews: null,
required_status_checks: null,
restrictions: null,
enforce_admins: true
}
}
]
}
);
});

test('that the greenkeeper label is defined for javascript projects', async () => {
yamlWriter.default.resolves();

await scaffoldSettings(projectRoot, {}, null, null, null, 'JavaScript');

assert.calledWith(
yamlWriter.default,
`${projectRoot}/.github/settings.yml`,
sinon.match({
labels: [
{name: 'bug', color: 'ee0701'},
{name: 'duplicate', color: 'cccccc'},
{name: 'enhancement', color: '84b6eb'},
{name: 'help wanted', color: '128A0C'},
{name: 'invalid', color: 'e6e6e6'},
{name: 'question', color: 'cc317c'},
{name: 'wontfix', color: 'ffffff'},
{name: 'breaking change', color: 'e0fc28'},
{name: 'greenkeeper', color: '00c775'}
]
})
{_extends: '.github', repository: {name: projectName, description, homepage, private: true}}
);
});

test('that the repository is marked as private when the visibility is `Private`', async () => {
yamlWriter.default.resolves();

await scaffoldSettings(projectRoot, {}, null, null, 'Private', any.word());
await scaffoldSettings(projectRoot, {}, null, null, 'Private');

assert.calledWith(
yamlWriter.default,
Expand All @@ -104,7 +46,7 @@ suite('settings', () => {
test('that the repository is marked as not private when the visibility is `Public`', async () => {
yamlWriter.default.resolves();

await scaffoldSettings(projectRoot, {}, null, null, 'Public', any.word());
await scaffoldSettings(projectRoot, {}, null, null, 'Public');

assert.calledWith(
yamlWriter.default,
Expand All @@ -116,7 +58,7 @@ suite('settings', () => {
test('that the repository is marked as private when the visibility is not specified', async () => {
yamlWriter.default.resolves();

await scaffoldSettings(projectRoot, {}, null, null, null, any.word());
await scaffoldSettings(projectRoot, {});

assert.calledWith(
yamlWriter.default,
Expand Down

0 comments on commit d4f774a

Please sign in to comment.