diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts index 2c47fa1a2f..5411602a21 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.test.ts @@ -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); + mockGithubClient.users.getByUsername.mockResolvedValue({ + data: { + type: 'User', + }, + } as OctokitResponse); + + await publisher.publish({ + values: { + storePath: 'blam/test', + owner: 'bob', + }, + directory: '/tmp/test', + }); + + expect( + mockGithubClient.repos.createForAuthenticatedUser, + ).toHaveBeenCalledWith({ + name: 'test', + private: true, + }); + }); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 671c3472bc..a8f3eaaa02 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -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;