Skip to content

Commit bd9776c

Browse files
committed
Variant analysis: Remove handling of invalid repos
This is now done automatically on the API side
1 parent 4f5ca0b commit bd9776c

2 files changed

Lines changed: 2 additions & 131 deletions

File tree

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

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
getOnDiskWorkspaceFolders,
1010
showAndLogErrorMessage,
1111
showAndLogInformationMessage,
12-
showInformationMessageWithAction,
1312
tryGetQueryMetadata,
1413
tmpDir
1514
} from '../helpers';
@@ -22,7 +21,7 @@ import { OctokitResponse } from '@octokit/types/dist-types';
2221
import { RemoteQuery } from './remote-query';
2322
import { RemoteQuerySubmissionResult } from './remote-query-submission-result';
2423
import { QueryMetadata } from '../pure/interface-types';
25-
import { REPO_REGEX } from '../pure/helpers-pure';
24+
import { getErrorMessage, REPO_REGEX } from '../pure/helpers-pure';
2625

2726
export interface QlPack {
2827
name: string;
@@ -367,44 +366,7 @@ async function runRemoteQueriesApiRequest(
367366
void showAndLogInformationMessage(`Successfully scheduled runs. [Click here to see the progress](https://github.com/${owner}/${repo}/actions/runs/${workflowRunId}).`);
368367
return workflowRunId;
369368
} catch (error) {
370-
return await attemptRerun(error, credentials, ref, language, repositories, owner, repo, queryPackBase64, dryRun);
371-
}
372-
}
373-
374-
/** Attempts to rerun the query on only the valid repositories */
375-
export async function attemptRerun(
376-
error: any,
377-
credentials: Credentials,
378-
ref: string,
379-
language: string,
380-
repositories: string[],
381-
owner: string,
382-
repo: string,
383-
queryPackBase64: string,
384-
dryRun = false
385-
) {
386-
if (typeof error.message === 'string' && error.message.includes('Some repositories were invalid')) {
387-
const invalidRepos = error?.response?.data?.invalid_repos || [];
388-
void logger.log('Unable to run query on some of the specified repositories');
389-
if (invalidRepos.length > 0) {
390-
void logger.log(`Invalid repos: ${invalidRepos.join(', ')}`);
391-
}
392-
393-
if (invalidRepos.length === repositories.length) {
394-
// Every repo is invalid in some way
395-
void showAndLogErrorMessage('Unable to run query on any of the specified repositories.');
396-
return;
397-
}
398-
399-
const popupMessage = 'Unable to run query on some of the specified repositories. [See logs for more details](command:codeQL.showLogs).';
400-
const rerunQuery = await showInformationMessageWithAction(popupMessage, 'Rerun on the valid repositories only');
401-
if (rerunQuery) {
402-
const validRepositories = repositories.filter(r => !invalidRepos.includes(r));
403-
void logger.log(`Rerunning query on set of valid repositories: ${JSON.stringify(validRepositories)}`);
404-
return await runRemoteQueriesApiRequest(credentials, ref, language, validRepositories, owner, repo, queryPackBase64, dryRun);
405-
}
406-
} else {
407-
void showAndLogErrorMessage(error);
369+
void showAndLogErrorMessage(getErrorMessage(error));
408370
}
409371
}
410372

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

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -104,95 +104,4 @@ describe('run-remote-query', function() {
104104
});
105105

106106
});
107-
108-
describe('attemptRerun', () => {
109-
let sandbox: sinon.SinonSandbox;
110-
let showAndLogErrorMessageSpy: sinon.SinonStub;
111-
let showInformationMessageWithActionSpy: sinon.SinonStub;
112-
let mockRequest: sinon.SinonStub;
113-
let logSpy: sinon.SinonStub;
114-
let mod: any;
115-
116-
const error = {
117-
message: 'Unable to run query on the specified repositories. Some repositories were invalid.',
118-
response: {
119-
data: {
120-
invalid_repos: ['abc/def', 'ghi/jkl']
121-
}
122-
}
123-
};
124-
const ref = 'main';
125-
const language = 'javascript';
126-
const credentials = getMockCredentials(0);
127-
const query = 'select 1';
128-
const owner = 'owner';
129-
const repo = 'repo';
130-
131-
beforeEach(() => {
132-
sandbox = sinon.createSandbox();
133-
logSpy = sandbox.stub();
134-
showAndLogErrorMessageSpy = sandbox.stub();
135-
showInformationMessageWithActionSpy = sandbox.stub();
136-
mod = proxyquire('../../remote-queries/run-remote-query', {
137-
'../helpers': {
138-
showAndLogErrorMessage: showAndLogErrorMessageSpy,
139-
showInformationMessageWithAction: showInformationMessageWithActionSpy
140-
},
141-
'../logging': {
142-
'logger': {
143-
log: logSpy
144-
}
145-
},
146-
});
147-
});
148-
afterEach(() => {
149-
sandbox.restore();
150-
});
151-
152-
it('should return and log error if it can\'t run on any repos', async () => {
153-
const repositories = ['abc/def', 'ghi/jkl'];
154-
155-
// make the function call
156-
await mod.attemptRerun(error, credentials, ref, language, repositories, query, owner, repo);
157-
158-
// check logging output
159-
expect(logSpy.firstCall.args[0]).to.contain('Unable to run query');
160-
expect(logSpy.secondCall.args[0]).to.contain('Invalid repos: abc/def, ghi/jkl');
161-
expect(showAndLogErrorMessageSpy.firstCall.args[0]).to.contain('Unable to run query on any');
162-
});
163-
164-
it('should list invalid repos and rerun on valid ones', async () => {
165-
const repositories = ['foo/bar', 'abc/def', 'ghi/jkl', 'foo/baz'];
166-
167-
// fake return values
168-
showInformationMessageWithActionSpy.resolves(true);
169-
170-
// make the function call
171-
await mod.attemptRerun(error, credentials, ref, language, repositories, query, owner, repo);
172-
173-
// check logging output
174-
expect(logSpy.firstCall.args[0]).to.contain('Unable to run query');
175-
expect(logSpy.secondCall.args[0]).to.contain('Invalid repos: abc/def, ghi/jkl');
176-
177-
// check that the correct information message is displayed
178-
expect(showInformationMessageWithActionSpy.firstCall.args[0]).to.contain('Unable to run query on some');
179-
expect(showInformationMessageWithActionSpy.firstCall.args[1]).to.contain('Rerun');
180-
181-
// check that API request is made again, with only valid repos
182-
expect(logSpy.lastCall.args[0]).to.contain('valid repositories: ["foo/bar","foo/baz"]');
183-
// test a few values in the octokit request
184-
expect(mockRequest.firstCall.args[1].data.language).to.eq('javascript');
185-
expect(mockRequest.firstCall.args[1].data.repositories).to.deep.eq(['foo/bar', 'foo/baz']);
186-
187-
});
188-
189-
function getMockCredentials(response: any) {
190-
mockRequest = sinon.stub().resolves(response);
191-
return {
192-
getOctokit: () => ({
193-
request: mockRequest
194-
})
195-
};
196-
}
197-
});
198107
});

0 commit comments

Comments
 (0)