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

Commit

Permalink
feat(repo-urls): passed urls for created repo back from scaffolder
Browse files Browse the repository at this point in the history
so that the project scaffolder can handle further tasks, like configuring the local remote

for #1
  • Loading branch information
travi committed Feb 3, 2019
1 parent f3f806b commit 846fa12
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
13 changes: 10 additions & 3 deletions src/create.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import chalk from 'chalk';
import {factory} from './github-client-factory';

export default function (name, visibility) {
console.error(chalk.grey('Creating repository on GitHub')); // eslint-disable-line no-console
export default async function (name, visibility) {
console.error(chalk.grey('Creating repository on GitHub')); // eslint-disable-line no-console

return factory().repos.createForAuthenticatedUser({name, private: 'Private' === visibility});
const {ssh_url: sshUrl, html_url: htmlUrl} = await factory().repos.createForAuthenticatedUser({
name,
private: 'Private' === visibility
});

console.error(chalk.grey(`Repository created at ${htmlUrl}`)); // eslint-disable-line no-console

return {sshUrl, htmlUrl};
}
6 changes: 4 additions & 2 deletions src/scaffolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import chalk from 'chalk';
import scaffoldSettings from './settings-scaffolder';
import create from './create';

export function scaffold({name, projectRoot, projectType, description, homepage, visibility}) {
export async function scaffold({name, projectRoot, projectType, description, homepage, visibility}) {
console.error(chalk.blue('Generating GitHub')); // eslint-disable-line no-console

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

return creationResult;
}
4 changes: 4 additions & 0 deletions test/mocha-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ import sinon from 'sinon';
import chai from 'chai';

sinon.assert.expose(chai.assert, {prefix: ''});

process.on('unhandledRejection', reason => {
throw reason;
});
17 changes: 9 additions & 8 deletions test/unit/create-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import create from '../../src/create';

suite('creation', () => {
let sandbox;
const sshUrl = any.url();
const htmlUrl = any.url();
const creationResponse = {ssh_url: sshUrl, html_url: htmlUrl};

setup(() => {
sandbox = sinon.createSandbox();
Expand All @@ -16,26 +19,24 @@ suite('creation', () => {
teardown(() => sandbox.restore());

suite('for user', () => {
test('that the repository is created for the provided user account', () => {
test('that the repository is created for the provided user account', async () => {
const name = any.word();
const createForAuthenticatedUser = sinon.stub();
const client = {repos: {createForAuthenticatedUser}};
clientFactory.factory.returns(client);
createForAuthenticatedUser.withArgs({name, private: false}).resolves(creationResponse);

create(name, 'Public');

assert.calledWith(createForAuthenticatedUser, {name, private: false});
assert.deepEqual(await create(name, 'Public'), {sshUrl, htmlUrl});
});

test('that the repository is created as private when visibility is `Privage`', () => {
test('that the repository is created as private when visibility is `Private`', async () => {
const name = any.word();
const createForAuthenticatedUser = sinon.stub();
const client = {repos: {createForAuthenticatedUser}};
clientFactory.factory.returns(client);
createForAuthenticatedUser.withArgs({name, private: true}).resolves(creationResponse);

create(name, 'Private');

assert.calledWith(createForAuthenticatedUser, {name, private: true});
assert.deepEqual(await create(name, 'Private'), {sshUrl, htmlUrl});
});
});
});
10 changes: 6 additions & 4 deletions test/unit/scaffolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ suite('github', () => {
const homepage = any.url();
const projectType = any.word();
const visibility = any.word();
const creationResult = any.simpleObject();
settingsSecaffolder.default.resolves();
creator.default.resolves();
creator.default.withArgs(projectName, visibility).resolves(creationResult);

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

assert.calledWith(
settingsSecaffolder.default,
Expand All @@ -38,7 +42,5 @@ suite('github', () => {
visibility,
projectType
);

assert.calledWith(creator.default, projectName, visibility);
});
});

0 comments on commit 846fa12

Please sign in to comment.