Skip to content

Commit f992679

Browse files
MRVA: Include more info in query history label (#1427)
Co-authored-by: Elena Tanasoiu <elenatanasoiu@github.com>
1 parent ffe1704 commit f992679

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

extensions/ql-vscode/src/history-item-label-provider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ export class HistoryItemLabelProvider {
6565
}
6666

6767
private getRemoteInterpolateReplacements(item: RemoteQueryHistoryItem): InterpolateReplacements {
68+
const numRepositoriesQueried = item.remoteQuery.numRepositoriesQueried;
69+
const numRepositoriesLabel = `${numRepositoriesQueried} ${numRepositoriesQueried === 1 ? 'repository' : 'repositories'}`;
6870
return {
6971
t: new Date(item.remoteQuery.executionStartTime).toLocaleString(env.language),
70-
q: item.remoteQuery.queryName,
72+
q: `${item.remoteQuery.queryName} (${item.remoteQuery.language})`,
7173

72-
// There is no database name for remote queries. Instead use the controller repository name.
73-
d: `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`,
74+
// Return the number of repositories queried if available. Otherwise, use the controller repository name.
75+
d: numRepositoriesQueried ? numRepositoriesLabel : `${item.remoteQuery.controllerRepository.owner}/${item.remoteQuery.controllerRepository.name}`,
7476

7577
// There is no synchronous way to get the results count.
7678
r: '',

extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface UpdatedQueryStatusEvent {
4141
queryId: string;
4242
status: QueryStatus;
4343
failureReason?: string;
44+
numRepositoriesQueried?: number;
4445
}
4546

4647
export class RemoteQueriesManager extends DisposableObject {
@@ -314,9 +315,13 @@ export class RemoteQueriesManager extends DisposableObject {
314315
): Promise<void> {
315316
const resultIndex = await getRemoteQueryIndex(credentials, remoteQuery);
316317
if (resultIndex) {
317-
this.remoteQueryStatusUpdateEventEmitter.fire({ queryId, status: QueryStatus.Completed });
318318
const metadata = await this.getRepositoriesMetadata(resultIndex, credentials);
319319
const queryResult = this.mapQueryResult(executionEndTime, resultIndex, queryId, metadata);
320+
this.remoteQueryStatusUpdateEventEmitter.fire({
321+
queryId,
322+
status: QueryStatus.Completed,
323+
numRepositoriesQueried: queryResult.analysisSummaries.length,
324+
});
320325

321326
await this.storeJsonFile(queryId, 'query-result.json', queryResult);
322327

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export interface RemoteQuery {
88
controllerRepository: Repository;
99
executionStartTime: number; // Use number here since it needs to be serialized and desserialized.
1010
actionsWorkflowRunId: number;
11+
numRepositoriesQueried: number;
1112
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,25 +258,28 @@ export async function runRemoteQuery(
258258
});
259259

260260
const actionBranch = getActionBranch();
261-
const workflowRunId = await runRemoteQueriesApiRequest(credentials, actionBranch, language, repoSelection, owner, repo, base64Pack, dryRun);
261+
const apiResponse = await runRemoteQueriesApiRequest(credentials, actionBranch, language, repoSelection, owner, repo, base64Pack, dryRun);
262262
const queryStartTime = Date.now();
263263
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
264264

265265
if (dryRun) {
266266
return { queryDirPath: remoteQueryDir.path };
267267
} else {
268-
if (!workflowRunId) {
268+
if (!apiResponse) {
269269
return;
270270
}
271271

272+
const workflowRunId = apiResponse.workflow_run_id;
273+
const numRepositoriesQueried = apiResponse.repositories_queried.length;
272274
const remoteQuery = await buildRemoteQueryEntity(
273275
queryFile,
274276
queryMetadata,
275277
owner,
276278
repo,
277279
queryStartTime,
278280
workflowRunId,
279-
language);
281+
language,
282+
numRepositoriesQueried);
280283

281284
// don't return the path because it has been deleted
282285
return { query: remoteQuery };
@@ -301,7 +304,7 @@ async function runRemoteQueriesApiRequest(
301304
repo: string,
302305
queryPackBase64: string,
303306
dryRun = false
304-
): Promise<void | number> {
307+
): Promise<void | QueriesResponse> {
305308
const data = {
306309
ref,
307310
language,
@@ -336,7 +339,7 @@ async function runRemoteQueriesApiRequest(
336339
);
337340
const { popupMessage, logMessage } = parseResponse(owner, repo, response.data);
338341
void showAndLogInformationMessage(popupMessage, { fullMessage: logMessage });
339-
return response.data.workflow_run_id;
342+
return response.data;
340343
} catch (error: any) {
341344
if (error.status === 404) {
342345
void showAndLogErrorMessage(`Controller repository was not found. Please make sure it's a valid repo name.${eol}`);
@@ -432,7 +435,8 @@ async function buildRemoteQueryEntity(
432435
controllerRepoName: string,
433436
queryStartTime: number,
434437
workflowRunId: number,
435-
language: string
438+
language: string,
439+
numRepositoriesQueried: number
436440
): Promise<RemoteQuery> {
437441
// The query name is either the name as specified in the query metadata, or the file name.
438442
const queryName = queryMetadata?.name ?? path.basename(queryFilePath);
@@ -449,6 +453,7 @@ async function buildRemoteQueryEntity(
449453
name: controllerRepoName,
450454
},
451455
executionStartTime: queryStartTime,
452-
actionsWorkflowRunId: workflowRunId
456+
actionsWorkflowRunId: workflowRunId,
457+
numRepositoriesQueried: numRepositoriesQueried,
453458
};
454459
}

extensions/ql-vscode/src/vscode-tests/no-workspace/history-item-label-provider.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,30 @@ describe('HistoryItemLabelProvider', () => {
8989
expect(labelProvider.getLabel(fqi)).to.eq('xxx');
9090

9191
fqi.userSpecifiedLabel = '%t %q %d %s %%';
92-
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name github/vscode-codeql-integration-tests in progress %`);
92+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) github/vscode-codeql-integration-tests in progress %`);
9393

9494
fqi.userSpecifiedLabel = '%t %q %d %s %%::%t %q %d %s %%';
95-
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name github/vscode-codeql-integration-tests in progress %::${dateStr} query-name github/vscode-codeql-integration-tests in progress %`);
95+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) github/vscode-codeql-integration-tests in progress %::${dateStr} query-name (javascript) github/vscode-codeql-integration-tests in progress %`);
9696
});
9797

9898
it('should interpolate query when not user specified', () => {
9999
const fqi = createMockRemoteQueryInfo();
100100

101-
expect(labelProvider.getLabel(fqi)).to.eq('xxx query-name xxx');
101+
expect(labelProvider.getLabel(fqi)).to.eq('xxx query-name (javascript) xxx');
102102

103103

104104
config.format = '%t %q %d %s %f %r %%';
105-
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name github/vscode-codeql-integration-tests in progress query-file.ql %`);
105+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) github/vscode-codeql-integration-tests in progress query-file.ql %`);
106106

107107
config.format = '%t %q %d %s %f %r %%::%t %q %d %s %f %r %%';
108-
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name github/vscode-codeql-integration-tests in progress query-file.ql %::${dateStr} query-name github/vscode-codeql-integration-tests in progress query-file.ql %`);
108+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) github/vscode-codeql-integration-tests in progress query-file.ql %::${dateStr} query-name (javascript) github/vscode-codeql-integration-tests in progress query-file.ql %`);
109+
});
110+
111+
it('should use number of repositories instead of controller repo if available', () => {
112+
const fqi = createMockRemoteQueryInfo(undefined, 2);
113+
114+
config.format = '%t %q %d %s %f %r %%';
115+
expect(labelProvider.getLabel(fqi)).to.eq(`${dateStr} query-name (javascript) 2 repositories in progress query-file.ql %`);
109116
});
110117

111118
it('should get query short label', () => {
@@ -119,7 +126,7 @@ describe('HistoryItemLabelProvider', () => {
119126
expect(labelProvider.getShortLabel(fqi)).to.eq('query-name');
120127
});
121128

122-
function createMockRemoteQueryInfo(userSpecifiedLabel?: string) {
129+
function createMockRemoteQueryInfo(userSpecifiedLabel?: string, numRepositoriesQueried?: number) {
123130
return {
124131
t: 'remote',
125132
userSpecifiedLabel,
@@ -130,7 +137,9 @@ describe('HistoryItemLabelProvider', () => {
130137
controllerRepository: {
131138
owner: 'github',
132139
name: 'vscode-codeql-integration-tests'
133-
}
140+
},
141+
language: 'javascript',
142+
numRepositoriesQueried,
134143
},
135144
status: 'in progress',
136145
} as unknown as RemoteQueryHistoryItem;

0 commit comments

Comments
 (0)