Skip to content

Commit 55110e1

Browse files
committed
fix(visibility): set repo visibility based on provided value
rather than always defaulting to `Private`
1 parent abc9e11 commit 55110e1

File tree

8 files changed

+50
-10
lines changed

8 files changed

+50
-10
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ to leverage the GitHub API integration benefits of this plugin.
6262

6363
```javascript
6464
import {scaffold} from '@form8ion/github';
65+
import any from '@travi/any';
6566
```
6667

6768
#### Execute
@@ -70,7 +71,8 @@ import {scaffold} from '@form8ion/github';
7071
await scaffold({
7172
projectRoot: process.cwd(),
7273
name: 'foo',
73-
owner: 'travi'
74+
owner: 'travi',
75+
visibility: any.fromList(['Public', 'Private'])
7476
});
7577
```
7678

example.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {resolve} from 'path';
44
import stubbedFs from 'mock-fs';
55
import {scaffold} from './lib/index.js';
6+
import any from '@travi/any';
67

78
// remark-usage-ignore-next
89
stubbedFs({node_modules: stubbedFs.load(resolve('node_modules'))});
@@ -12,5 +13,6 @@ stubbedFs({node_modules: stubbedFs.load(resolve('node_modules'))});
1213
await scaffold({
1314
projectRoot: process.cwd(),
1415
name: 'foo',
15-
owner: 'travi'
16+
owner: 'travi',
17+
visibility: any.fromList(['Public', 'Private'])
1618
});

src/scaffolder.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {info} from '@travi/cli-messages';
33
import {factory as getAuthenticatedOctokit} from './octokit/factory.js';
44
import {scaffold as scaffoldRepository} from './repository/index.js';
55

6-
export default async function ({name, owner}) {
6+
export default async function ({name, owner, visibility}) {
77
info('Initializing GitHub');
88

99
const octokit = getAuthenticatedOctokit();
1010

11-
const repositoryResult = await scaffoldRepository({octokit, name, owner});
11+
const repositoryResult = await scaffoldRepository({octokit, name, owner, visibility});
1212

1313
return {...repositoryResult};
1414
}

src/scaffolder.test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ describe('scaffolder', () => {
1515
const repositoryResult = any.simpleObject();
1616
const name = any.word();
1717
const owner = any.word();
18+
const visibility = any.word();
1819
octokitFactory.mockReturnValue(octokitClient);
19-
when(scaffoldRepository).calledWith({octokit: octokitClient, name, owner}).mockResolvedValue(repositoryResult);
20+
when(scaffoldRepository)
21+
.calledWith({octokit: octokitClient, name, owner, visibility})
22+
.mockResolvedValue(repositoryResult);
2023

21-
expect(await scaffold({name, owner})).toEqual({...repositoryResult});
24+
expect(await scaffold({name, owner, visibility})).toEqual({...repositoryResult});
2225
});
2326
});

test/integration/features/scaffold.feature

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
Feature: Scaffolder
22

3-
Scenario: new repository
3+
Scenario: new public repository
44
Given netrc contains a GitHub token
55
And no repository exists for the "user" on GitHub
6+
And the visibility of the repository should be "Public"
7+
# And next steps are provided
8+
When the project is scaffolded
9+
Then a repository is created on GitHub
10+
# And issues are created for next-steps
11+
# And repository settings are configured
12+
And repository details are returned
13+
14+
Scenario: new private repository
15+
Given netrc contains a GitHub token
16+
And no repository exists for the "user" on GitHub
17+
And the visibility of the repository should be "Private"
618
# And next steps are provided
719
When the project is scaffolded
820
Then a repository is created on GitHub
@@ -34,11 +46,23 @@ Feature: Scaffolder
3446
# But repository settings are configured
3547
And no repository details are returned
3648

37-
Scenario: user is a member of an organization and the project is new
49+
Scenario: user is a member of an organization and the public project is new
3850
Given netrc contains a GitHub token
3951
And the user is a member of an organization
4052
And no repository exists for the "organization" on GitHub
53+
And the visibility of the repository should be "Public"
4154
When the project is scaffolded
55+
Then a repository is created on GitHub
56+
# And repository settings are configured
57+
And repository details are returned
58+
59+
Scenario: user is a member of an organization and the private project is new
60+
Given netrc contains a GitHub token
61+
And the user is a member of an organization
62+
And no repository exists for the "organization" on GitHub
63+
And the visibility of the repository should be "Private"
64+
When the project is scaffolded
65+
Then a repository is created on GitHub
4266
# And repository settings are configured
4367
And repository details are returned
4468

test/integration/features/step_definitions/common-steps.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ When('the project is scaffolded', async function () {
3535
this.result = await scaffold({
3636
projectRoot: this.projectRoot,
3737
name: this.projectName,
38-
owner: this.githubUser
38+
owner: this.githubUser,
39+
visibility: this.projectVisibility
3940
});
4041
} catch (err) {
4142
debug(err);

test/integration/features/step_definitions/repository-steps.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ Given('no repository exists for the {string} on GitHub', async function (account
6666
);
6767

6868
server.use(
69-
http.post(`https://api.github.com/orgs/${organizationAccount}/repos`, ({request}) => {
69+
http.post(`https://api.github.com/orgs/${organizationAccount}/repos`, async ({request}) => {
7070
if (authorizationHeaderIncludesToken(request)) {
71+
this.createdRepositoryDetails = await request.clone().json();
72+
7173
return HttpResponse.json({
7274
ssh_url: sshUrl,
7375
html_url: htmlUrl
@@ -128,4 +130,5 @@ Then('no repository is created on GitHub', async function () {
128130

129131
Then('a repository is created on GitHub', async function () {
130132
assert.equal(this.createdRepositoryDetails.name, this.projectName);
133+
assert.equal(this.createdRepositoryDetails.private, 'Public' !== this.projectVisibility);
131134
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {Given} from '@cucumber/cucumber';
2+
3+
Given('the visibility of the repository should be {string}', async function (visibility) {
4+
this.projectVisibility = visibility;
5+
});

0 commit comments

Comments
 (0)