Skip to content

Commit 628e0e9

Browse files
Merge pull request #1408 from github/robertbrignull/cutoff_repos
Add cutoff repos and counts to error message
2 parents e6a68b3 + 16077f4 commit 628e0e9

File tree

2 files changed

+82
-11
lines changed

2 files changed

+82
-11
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ interface QueriesResponse {
3939
invalid_repositories?: string[],
4040
repositories_without_database?: string[],
4141
private_repositories?: string[],
42+
cutoff_repositories?: string[],
43+
cutoff_repositories_count?: number,
4244
},
4345
repositories_queried: string[],
4446
}
@@ -358,18 +360,31 @@ export function parseResponse(owner: string, repo: string, response: QueriesResp
358360
let logMessage = `Successfully scheduled runs on ${numRepositoriesQueried} repositories. See https://github.com/${owner}/${repo}/actions/runs/${response.workflow_run_id}.`;
359361
logMessage += `${eol2}Repositories queried:${eol}${repositoriesQueried.join(', ')}`;
360362
if (response.errors) {
363+
const { invalid_repositories, repositories_without_database, private_repositories, cutoff_repositories, cutoff_repositories_count } = response.errors;
361364
logMessage += `${eol2}Some repositories could not be scheduled.`;
362-
if (response.errors.invalid_repositories?.length) {
363-
logMessage += `${eol2}Invalid repositories:${eol}${response.errors.invalid_repositories.join(', ')}`;
365+
if (invalid_repositories?.length) {
366+
logMessage += `${eol2}${invalid_repositories.length} repositories were invalid and could not be found:${eol}${invalid_repositories.join(', ')}`;
364367
}
365-
if (response.errors.repositories_without_database?.length) {
366-
logMessage += `${eol2}Repositories without databases:${eol}${response.errors.repositories_without_database.join(', ')}`;
368+
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(', ')}`;
367370
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.`;
368371
}
369-
if (response.errors.private_repositories?.length) {
370-
logMessage += `${eol2}Non-public repositories:${eol}${response.errors.private_repositories.join(', ')}`;
372+
if (private_repositories?.length) {
373+
logMessage += `${eol2}${private_repositories.length} repositories are not public:${eol}${private_repositories.join(', ')}`;
371374
logMessage += `${eol}When using a public controller repository, only public repositories can be queried.`;
372375
}
376+
if (cutoff_repositories_count) {
377+
logMessage += `${eol2}${cutoff_repositories_count} repositories over the limit for a single request`;
378+
if (cutoff_repositories) {
379+
logMessage += `:${eol}${cutoff_repositories.join(', ')}`;
380+
if (cutoff_repositories_count !== cutoff_repositories.length) {
381+
logMessage += `${eol}...${eol}And ${cutoff_repositories_count - cutoff_repositories.length} more repositrories.`;
382+
}
383+
} else {
384+
logMessage += '.';
385+
}
386+
logMessage += `${eol}Repositories were selected based on how recently they had been updated.`;
387+
}
373388
}
374389

375390
return {

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

Lines changed: 61 additions & 5 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-
'Invalid repositories:',
44+
'2 repositories were invalid and could not be found:',
4545
'e/f, g/h'].join(os.EOL)
4646
);
4747
});
@@ -68,7 +68,7 @@ describe('run-remote-query', () => {
6868
'',
6969
'Some repositories could not be scheduled.',
7070
'',
71-
'Repositories without databases:',
71+
'2 repositories did not have a CodeQL database available:',
7272
'e/f, g/h',
7373
'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)
7474
);
@@ -96,12 +96,68 @@ describe('run-remote-query', () => {
9696
'',
9797
'Some repositories could not be scheduled.',
9898
'',
99-
'Non-public repositories:',
99+
'2 repositories are not public:',
100100
'e/f, g/h',
101101
'When using a public controller repository, only public repositories can be queried.'].join(os.EOL)
102102
);
103103
});
104104

105+
it('should parse a response with cutoff repos and cutoff repos count', () => {
106+
const result = parseResponse('org', 'name', {
107+
workflow_run_id: 123,
108+
repositories_queried: ['a/b', 'c/d'],
109+
errors: {
110+
cutoff_repositories: ['e/f', 'g/h'],
111+
cutoff_repositories_count: 2,
112+
}
113+
});
114+
115+
expect(result.popupMessage).to.equal(
116+
['Successfully scheduled runs on 2 repositories. [Click here to see the progress](https://github.com/org/name/actions/runs/123).',
117+
'',
118+
'Some repositories could not be scheduled. See extension log for details.'].join(os.EOL)
119+
);
120+
expect(result.logMessage).to.equal(
121+
['Successfully scheduled runs on 2 repositories. See https://github.com/org/name/actions/runs/123.',
122+
'',
123+
'Repositories queried:',
124+
'a/b, c/d',
125+
'',
126+
'Some repositories could not be scheduled.',
127+
'',
128+
'2 repositories over the limit for a single request:',
129+
'e/f, g/h',
130+
'Repositories were selected based on how recently they had been updated.'].join(os.EOL)
131+
);
132+
});
133+
134+
it('should parse a response with cutoff repos count but not cutoff repos', () => {
135+
const result = parseResponse('org', 'name', {
136+
workflow_run_id: 123,
137+
repositories_queried: ['a/b', 'c/d'],
138+
errors: {
139+
cutoff_repositories_count: 2,
140+
}
141+
});
142+
143+
expect(result.popupMessage).to.equal(
144+
['Successfully scheduled runs on 2 repositories. [Click here to see the progress](https://github.com/org/name/actions/runs/123).',
145+
'',
146+
'Some repositories could not be scheduled. See extension log for details.'].join(os.EOL)
147+
);
148+
expect(result.logMessage).to.equal(
149+
['Successfully scheduled runs on 2 repositories. See https://github.com/org/name/actions/runs/123.',
150+
'',
151+
'Repositories queried:',
152+
'a/b, c/d',
153+
'',
154+
'Some repositories could not be scheduled.',
155+
'',
156+
'2 repositories over the limit for a single request.',
157+
'Repositories were selected based on how recently they had been updated.'].join(os.EOL)
158+
);
159+
});
160+
105161
it('should parse a response with invalid repos and repos w/o databases', () => {
106162
const result = parseResponse('org', 'name', {
107163
workflow_run_id: 123,
@@ -125,10 +181,10 @@ describe('run-remote-query', () => {
125181
'',
126182
'Some repositories could not be scheduled.',
127183
'',
128-
'Invalid repositories:',
184+
'2 repositories were invalid and could not be found:',
129185
'e/f, g/h',
130186
'',
131-
'Repositories without databases:',
187+
'2 repositories did not have a CodeQL database available:',
132188
'i/j, k/l',
133189
'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)
134190
);

0 commit comments

Comments
 (0)