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

Commit

Permalink
feat(create): created the repo for the authenticated user
Browse files Browse the repository at this point in the history
for #1
  • Loading branch information
travi committed Jan 31, 2019
1 parent 20fe65b commit a5c485a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {factory} from './github-client-factory';

export default function (name, visibility) {
factory().repos.createForAuthenticatedUser({name, private: 'Private' === visibility});
}
6 changes: 5 additions & 1 deletion src/scaffolder.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import chalk from 'chalk';
import scaffoldSettings from './settings-scaffolder';
import create from './create';

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

return scaffoldSettings(projectRoot, name, description, homepage, visibility, projectType);
return Promise.all([
scaffoldSettings(projectRoot, name, description, homepage, visibility, projectType),
create(name, visibility)
]);
}
41 changes: 41 additions & 0 deletions test/unit/create-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sinon from 'sinon';
import {assert} from 'chai';
import any from '@travi/any';
import * as clientFactory from '../../src/github-client-factory';
import create from '../../src/create';

suite('creation', () => {
let sandbox;

setup(() => {
sandbox = sinon.createSandbox();

sandbox.stub(clientFactory, 'factory');
});

teardown(() => sandbox.restore());

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

create(name, 'Public');

assert.calledWith(createForAuthenticatedUser, {name, private: false});
});

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

create(name, 'Private');

assert.calledWith(createForAuthenticatedUser, {name, private: true});
});
});
});
7 changes: 6 additions & 1 deletion test/unit/scaffolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {assert} from 'chai';
import sinon from 'sinon';
import any from '@travi/any';
import * as settingsSecaffolder from '../../src/settings-scaffolder';
import * as creator from '../../src/create';
import {scaffold} from '../../src/scaffolder';

suite('github', () => {
Expand All @@ -13,16 +14,18 @@ suite('github', () => {
sandbox = sinon.createSandbox();

sandbox.stub(settingsSecaffolder, 'default');
sandbox.stub(creator, 'default');
});

teardown(() => sandbox.restore());

test('that the settings file is produced', async () => {
test('that the settings file is produced and the repository is created', async () => {
const description = any.sentence();
const homepage = any.url();
const projectType = any.word();
const visibility = any.word();
settingsSecaffolder.default.resolves();
creator.default.resolves();

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

Expand All @@ -35,5 +38,7 @@ suite('github', () => {
visibility,
projectType
);

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

0 comments on commit a5c485a

Please sign in to comment.