Add ability to flag user repositories as private

This commit is contained in:
Taras Mankovski
2020-09-16 08:53:18 -04:00
parent 9ad2b8186b
commit f5702ddc8e
2 changed files with 42 additions and 2 deletions
@@ -112,6 +112,7 @@ describe('GitHub Publisher', () => {
mockGithubClient.repos.createForAuthenticatedUser,
).toHaveBeenCalledWith({
name: 'test',
private: false,
});
});
});
@@ -231,7 +232,7 @@ describe('GitHub Publisher', () => {
repoVisibility: 'internal',
});
it('creates a repo in an organisation if the organisation with private visibility', async () => {
it('creates a private repository in the organization with visibility set to internal', async () => {
mockGithubClient.repos.createInOrg.mockResolvedValue({
data: {
clone_url: 'mockclone',
@@ -260,4 +261,40 @@ describe('GitHub Publisher', () => {
});
});
});
describe('private visibility in a user account', () => {
const publisher = new GithubPublisher({
client: new Octokit(),
token: 'abc',
repoVisibility: 'private',
});
it('creates a private repository', async () => {
mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({
data: {
clone_url: 'mockclone',
},
} as OctokitResponse<ReposCreateInOrgResponseData>);
mockGithubClient.users.getByUsername.mockResolvedValue({
data: {
type: 'User',
},
} as OctokitResponse<UsersGetByUsernameResponseData>);
await publisher.publish({
values: {
storePath: 'blam/test',
owner: 'bob',
},
directory: '/tmp/test',
});
expect(
mockGithubClient.repos.createForAuthenticatedUser,
).toHaveBeenCalledWith({
name: 'test',
private: true,
});
});
});
});
@@ -72,7 +72,10 @@ export class GithubPublisher implements PublisherBase {
private: this.repoVisibility !== 'public',
visibility: this.repoVisibility,
})
: this.client.repos.createForAuthenticatedUser({ name });
: this.client.repos.createForAuthenticatedUser({
name,
private: this.repoVisibility === 'private',
});
const { data } = await repoCreationPromise;