Skip to content

Commit b311991

Browse files
authored
MRVA: Fix grammar in pop-up message (#1416)
1 parent f486ccf commit b311991

File tree

2 files changed

+64
-11
lines changed

2 files changed

+64
-11
lines changed

extensions/ql-vscode/src/remote-queries/run-remote-query.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async function findPackRoot(queryFile: string): Promise<string> {
142142
while (!(await fs.pathExists(path.join(dir, 'qlpack.yml')))) {
143143
dir = path.dirname(dir);
144144
if (isFileSystemRoot(dir)) {
145-
// there is no qlpack.yml in this direcory or any parent directory.
145+
// there is no qlpack.yml in this directory or any parent directory.
146146
// just use the query file's directory as the pack root.
147147
return path.dirname(queryFile);
148148
}
@@ -349,36 +349,44 @@ async function runRemoteQueriesApiRequest(
349349
const eol = os.EOL;
350350
const eol2 = os.EOL + os.EOL;
351351

352+
/**
353+
* Returns "N repository" if N is one, "N repositories" otherwise.
354+
*/
355+
function pluralizeRepositories(numRepositories: number) {
356+
return `${numRepositories} ${numRepositories === 1 ? 'repository' : 'repositories'}`;
357+
}
358+
352359
// exported for testing only
353360
export function parseResponse(owner: string, repo: string, response: QueriesResponse) {
354361
const repositoriesQueried = response.repositories_queried;
355362
const numRepositoriesQueried = repositoriesQueried.length;
356363

357-
const popupMessage = `Successfully scheduled runs on ${numRepositoriesQueried} repositories. [Click here to see the progress](https://github.com/${owner}/${repo}/actions/runs/${response.workflow_run_id}).`
364+
const popupMessage = `Successfully scheduled runs on ${pluralizeRepositories(numRepositoriesQueried)}. [Click here to see the progress](https://github.com/${owner}/${repo}/actions/runs/${response.workflow_run_id}).`
358365
+ (response.errors ? `${eol2}Some repositories could not be scheduled. See extension log for details.` : '');
359366

360-
let logMessage = `Successfully scheduled runs on ${numRepositoriesQueried} repositories. See https://github.com/${owner}/${repo}/actions/runs/${response.workflow_run_id}.`;
367+
let logMessage = `Successfully scheduled runs on ${pluralizeRepositories(numRepositoriesQueried)}. See https://github.com/${owner}/${repo}/actions/runs/${response.workflow_run_id}.`;
361368
logMessage += `${eol2}Repositories queried:${eol}${repositoriesQueried.join(', ')}`;
362369
if (response.errors) {
363370
const { invalid_repositories, repositories_without_database, private_repositories, cutoff_repositories, cutoff_repositories_count } = response.errors;
364371
logMessage += `${eol2}Some repositories could not be scheduled.`;
365372
if (invalid_repositories?.length) {
366-
logMessage += `${eol2}${invalid_repositories.length} repositories were invalid and could not be found:${eol}${invalid_repositories.join(', ')}`;
373+
logMessage += `${eol2}${pluralizeRepositories(invalid_repositories.length)} invalid and could not be found:${eol}${invalid_repositories.join(', ')}`;
367374
}
368375
if (repositories_without_database?.length) {
369-
logMessage += `${eol2}${repositories_without_database.length} repositories did not have a CodeQL database available:${eol}${repositories_without_database.join(', ')}`;
376+
logMessage += `${eol2}${pluralizeRepositories(repositories_without_database.length)} did not have a CodeQL database available:${eol}${repositories_without_database.join(', ')}`;
370377
logMessage += `${eol}For each public repository that has not yet been added to the database service, we will try to create a database next time the store is updated.`;
371378
}
372379
if (private_repositories?.length) {
373-
logMessage += `${eol2}${private_repositories.length} repositories are not public:${eol}${private_repositories.join(', ')}`;
380+
logMessage += `${eol2}${pluralizeRepositories(private_repositories.length)} not public:${eol}${private_repositories.join(', ')}`;
374381
logMessage += `${eol}When using a public controller repository, only public repositories can be queried.`;
375382
}
376383
if (cutoff_repositories_count) {
377-
logMessage += `${eol2}${cutoff_repositories_count} repositories over the limit for a single request`;
384+
logMessage += `${eol2}${pluralizeRepositories(cutoff_repositories_count)} over the limit for a single request`;
378385
if (cutoff_repositories) {
379386
logMessage += `:${eol}${cutoff_repositories.join(', ')}`;
380387
if (cutoff_repositories_count !== cutoff_repositories.length) {
381-
logMessage += `${eol}...${eol}And ${cutoff_repositories_count - cutoff_repositories.length} more repositrories.`;
388+
const moreRepositories = cutoff_repositories_count - cutoff_repositories.length;
389+
logMessage += `${eol}...${eol}And another ${pluralizeRepositories(moreRepositories)}.`;
382390
}
383391
} else {
384392
logMessage += '.';

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/run-remote-query.test.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('run-remote-query', () => {
4141
'',
4242
'Some repositories could not be scheduled.',
4343
'',
44-
'2 repositories were invalid and could not be found:',
44+
'2 repositories invalid and could not be found:',
4545
'e/f, g/h'].join(os.EOL)
4646
);
4747
});
@@ -96,7 +96,7 @@ describe('run-remote-query', () => {
9696
'',
9797
'Some repositories could not be scheduled.',
9898
'',
99-
'2 repositories are not public:',
99+
'2 repositories not public:',
100100
'e/f, g/h',
101101
'When using a public controller repository, only public repositories can be queried.'].join(os.EOL)
102102
);
@@ -181,13 +181,58 @@ describe('run-remote-query', () => {
181181
'',
182182
'Some repositories could not be scheduled.',
183183
'',
184-
'2 repositories were invalid and could not be found:',
184+
'2 repositories invalid and could not be found:',
185185
'e/f, g/h',
186186
'',
187187
'2 repositories did not have a CodeQL database available:',
188188
'i/j, k/l',
189189
'For each public repository that has not yet been added to the database service, we will try to create a database next time the store is updated.'].join(os.EOL)
190190
);
191191
});
192+
193+
it('should parse a response with one repo of each category, and not pluralize "repositories"', () => {
194+
const result = parseResponse('org', 'name', {
195+
workflow_run_id: 123,
196+
repositories_queried: ['a/b'],
197+
errors: {
198+
private_repositories: ['e/f'],
199+
cutoff_repositories: ['i/j'],
200+
cutoff_repositories_count: 1,
201+
invalid_repositories: ['m/n'],
202+
repositories_without_database: ['q/r'],
203+
}
204+
});
205+
206+
expect(result.popupMessage).to.equal(
207+
['Successfully scheduled runs on 1 repository. [Click here to see the progress](https://github.com/org/name/actions/runs/123).',
208+
'',
209+
'Some repositories could not be scheduled. See extension log for details.'].join(os.EOL)
210+
);
211+
expect(result.logMessage).to.equal(
212+
[
213+
'Successfully scheduled runs on 1 repository. See https://github.com/org/name/actions/runs/123.',
214+
'',
215+
'Repositories queried:',
216+
'a/b',
217+
'',
218+
'Some repositories could not be scheduled.',
219+
'',
220+
'1 repository invalid and could not be found:',
221+
'm/n',
222+
'',
223+
'1 repository did not have a CodeQL database available:',
224+
'q/r',
225+
'For each public repository that has not yet been added to the database service, we will try to create a database next time the store is updated.',
226+
'',
227+
'1 repository not public:',
228+
'e/f',
229+
'When using a public controller repository, only public repositories can be queried.',
230+
'',
231+
'1 repository over the limit for a single request:',
232+
'i/j',
233+
'Repositories were selected based on how recently they had been updated.',
234+
].join(os.EOL)
235+
);
236+
});
192237
});
193238
});

0 commit comments

Comments
 (0)