Skip to content

Commit 5463230

Browse files
committed
fix(account): only ask for organization selection when the chosen account type is organization
1 parent 32a8b32 commit 5463230

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {constants} from '../prompt/index.js';
2+
3+
export function accountTypeIsOrganization({
4+
[constants.questionNames[constants.ids.GITHUB_DETAILS].ACCOUNT_TYPE]: accountType
5+
}) {
6+
return 'organization' === accountType;
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {describe, expect, it} from 'vitest';
2+
import any from '@travi/any';
3+
4+
import {constants} from '../prompt/index.js';
5+
import {accountTypeIsOrganization} from './prompt-conditionals.js';
6+
7+
describe('prompt conditionals', () => {
8+
it('should return `true` when the chosen account type is `organization`', async () => {
9+
expect(
10+
accountTypeIsOrganization({[constants.questionNames[constants.ids.GITHUB_DETAILS].ACCOUNT_TYPE]: 'organization'})
11+
).toBe(true);
12+
});
13+
14+
it('should return `false` when the chosen account type is not `organization`', async () => {
15+
expect(
16+
accountTypeIsOrganization({[constants.questionNames[constants.ids.GITHUB_DETAILS].ACCOUNT_TYPE]: any.word()})
17+
).toBe(false);
18+
});
19+
});

src/repository/prompt.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {constants} from '../prompt/index.js';
2+
import {accountTypeIsOrganization} from './prompt-conditionals.js';
23

34
function determineAccountName(accountType, authenticatedUser, organizations, organizationId) {
45
if ('user' === accountType) {
@@ -47,6 +48,7 @@ export default async function promptForRepositoryOwner({prompt, octokit}) {
4748
name: organizationQuestionName,
4849
type: 'select',
4950
message: 'Which of your GitHub organizations should the repository be hosted within?',
51+
when: accountTypeIsOrganization,
5052
choices: organizations.map(({id, login}) => ({name: login, short: login, value: id}))
5153
}
5254
]

src/repository/prompt.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import any from '@travi/any';
44
import zip from 'lodash.zip';
55

66
import {constants} from '../prompt/index.js';
7+
import {accountTypeIsOrganization} from './prompt-conditionals.js';
78
import promptForRepositoryOwner from './prompt.js';
89

910
describe('GitHub details prompt', () => {
@@ -37,6 +38,7 @@ describe('GitHub details prompt', () => {
3738
name: organizationQuestionName,
3839
type: 'select',
3940
message: 'Which of your GitHub organizations should the repository be hosted within?',
41+
when: accountTypeIsOrganization,
4042
choices: zip(organizationNames, organizationIds).map(([name, id]) => ({name, short: name, value: id}))
4143
}
4244
];

0 commit comments

Comments
 (0)