Skip to content

Commit

Permalink
feat(repository-name): return the name of the created repository as p…
Browse files Browse the repository at this point in the history
…art of vcs results
  • Loading branch information
travi committed Jul 29, 2024
1 parent eea11e0 commit 0b30aeb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@form8ion/repository-settings": "^1.1.3",
"@octokit/rest": "^20.0.0",
"@travi/cli-messages": "^1.1.1",
"deepmerge": "^4.3.1",
"lodash.zip": "^4.2.0",
"octokit-auth-netrc": "^3.1.1"
}
Expand Down
4 changes: 2 additions & 2 deletions src/repository/scaffolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export default async function ({name, owner, visibility, octokit}) {

const {data: {login: authenticatedUser}} = await octokit.users.getAuthenticated();

if (owner === authenticatedUser) return {vcs: await createForUser(octokit, owner, name, visibility)};
if (owner === authenticatedUser) return {vcs: {...await createForUser(octokit, owner, name, visibility), name}};

if (await authenticatedUserIsMemberOfRequestedOrganization(owner, octokit)) {
return {vcs: await createForOrganization(octokit, owner, name, visibility)};
return {vcs: {...await createForOrganization(octokit, owner, name, visibility), name}};
}

throw new Error(`User ${authenticatedUser} does not have access to create a repository in the ${owner} account`);
Expand Down
12 changes: 6 additions & 6 deletions src/repository/scaffolder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('creation', () => {
});

expect(await scaffoldRepository({name, owner: account, visibility: 'Public', octokit: client}))
.toEqual({vcs: {sshUrl, htmlUrl}});
.toEqual({vcs: {sshUrl, htmlUrl, name}});
});

it('should not create the repository when it already exists', async () => {
Expand All @@ -50,7 +50,7 @@ describe('creation', () => {
when(get).calledWith({owner: account, repo: name}).mockResolvedValue(repoDetailsResponse);

expect(await scaffoldRepository({name, owner: account, visibility: 'Public', octokit: client}))
.toEqual({vcs: {sshUrl, htmlUrl}});
.toEqual({vcs: {sshUrl, htmlUrl, name}});
expect(createForAuthenticatedUser).not.toHaveBeenCalled();
});

Expand All @@ -64,7 +64,7 @@ describe('creation', () => {
});

expect(await scaffoldRepository({name, owner: account, visibility: 'Private', octokit: client}))
.toEqual({vcs: {sshUrl, htmlUrl}});
.toEqual({vcs: {sshUrl, htmlUrl, name}});
});

it('should rethrow other errors', async () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('creation', () => {
});

expect(await scaffoldRepository({name, owner: account, visibility: 'Public', octokit: client}))
.toEqual({vcs: {sshUrl, htmlUrl}});
.toEqual({vcs: {sshUrl, htmlUrl, name}});
});

it('should not create the repository when it already exists', async () => {
Expand All @@ -115,7 +115,7 @@ describe('creation', () => {
when(get).calledWith({owner: account, repo: name}).mockResolvedValue(repoDetailsResponse);

expect(await scaffoldRepository({name, owner: account, visibility: 'Public', octokit: client}))
.toEqual({vcs: {sshUrl, htmlUrl}});
.toEqual({vcs: {sshUrl, htmlUrl, name}});
expect(createInOrg).not.toHaveBeenCalled();
});

Expand All @@ -129,7 +129,7 @@ describe('creation', () => {
});

expect(await scaffoldRepository({name, owner: account, visibility: 'Private', octokit: client}))
.toEqual({vcs: {sshUrl, htmlUrl}});
.toEqual({vcs: {sshUrl, htmlUrl, name}});
});

it('should rethrow other errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Given('the project is not versioned on GitHub', async function () {
Then('repository details are returned', async function () {
assert.equal(this.result.vcs.sshUrl, sshUrl);
assert.equal(this.result.vcs.htmlUrl, htmlUrl);
assert.equal(this.result.vcs.name, this.projectName);
});

Then('no repository details are returned', async function () {
Expand Down

0 comments on commit 0b30aeb

Please sign in to comment.