Allow multiple analyses for same repo to be downloaded
Removes the limitation specified in #1089 where analyses for the same repo and different queries will overwrite each other.
This commit is contained in:
@@ -10,15 +10,16 @@ import * as os from 'os';
|
||||
import { sarifParser } from '../sarif-parser';
|
||||
|
||||
export class AnalysesResultsManager {
|
||||
// Store for the results of various analyses for a single remote query.
|
||||
private readonly analysesResults: AnalysisResults[];
|
||||
// Store for the results of various analyses for each remote query.
|
||||
// The key is the queryId and is also the name of the directory where results are stored.
|
||||
private readonly analysesResults: Map<string, AnalysisResults[]>;
|
||||
|
||||
constructor(
|
||||
private readonly ctx: ExtensionContext,
|
||||
readonly storagePath: string,
|
||||
private readonly logger: Logger,
|
||||
) {
|
||||
this.analysesResults = [];
|
||||
this.analysesResults = new Map();
|
||||
}
|
||||
|
||||
public async downloadAnalysisResults(
|
||||
@@ -78,8 +79,12 @@ export class AnalysesResultsManager {
|
||||
}
|
||||
}
|
||||
|
||||
public getAnalysesResults(): AnalysisResults[] {
|
||||
return [...this.analysesResults];
|
||||
public getAnalysesResults(queryId: string): AnalysisResults[] {
|
||||
return [...(this.analysesResults.get(queryId) || [])];
|
||||
}
|
||||
|
||||
public removeAnalysesResults(queryId: string) {
|
||||
this.analysesResults.delete(queryId);
|
||||
}
|
||||
|
||||
private async downloadSingleAnalysisResults(
|
||||
@@ -92,9 +97,11 @@ export class AnalysesResultsManager {
|
||||
status: 'InProgress',
|
||||
results: []
|
||||
};
|
||||
|
||||
this.analysesResults.push(analysisResults);
|
||||
void publishResults(this.analysesResults);
|
||||
const queryId = analysis.downloadLink.queryId;
|
||||
const resultsForQuery = this.analysesResults.get(queryId) || [];
|
||||
resultsForQuery.push(analysisResults);
|
||||
this.analysesResults.set(queryId, resultsForQuery);
|
||||
void publishResults(resultsForQuery);
|
||||
|
||||
let artifactPath;
|
||||
try {
|
||||
@@ -113,7 +120,7 @@ export class AnalysesResultsManager {
|
||||
analysisResults.status = 'Failed';
|
||||
}
|
||||
|
||||
void publishResults(this.analysesResults);
|
||||
void publishResults(resultsForQuery);
|
||||
}
|
||||
|
||||
private async readResults(filePath: string): Promise<QueryResult[]> {
|
||||
@@ -139,6 +146,6 @@ export class AnalysesResultsManager {
|
||||
}
|
||||
|
||||
private isAnalysisDownloaded(analysis: AnalysisSummary): boolean {
|
||||
return this.analysesResults.some(x => x.nwo === analysis.nwo);
|
||||
return (this.analysesResults.get(analysis.downloadLink.queryId) || []).some(x => x.nwo === analysis.nwo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export class RemoteQueriesInterfaceManager {
|
||||
queryResult: this.buildViewModel(query, queryResult)
|
||||
});
|
||||
|
||||
await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults());
|
||||
await this.setAnalysisResults(this.analysesResultsManager.getAnalysesResults(queryResult.queryId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,6 +67,7 @@ export class RemoteQueriesManager extends DisposableObject {
|
||||
|
||||
private async handleRemoveQueryItem(queryItem: QueryHistoryInfo) {
|
||||
if (queryItem?.t === 'remote') {
|
||||
this.analysesResultsManager.removeAnalysesResults(queryItem.queryId);
|
||||
await this.removeStorageDirectory(queryItem);
|
||||
}
|
||||
}
|
||||
@@ -211,7 +212,8 @@ export class RemoteQueriesManager extends DisposableObject {
|
||||
return {
|
||||
executionEndTime,
|
||||
analysisSummaries,
|
||||
analysisFailures
|
||||
analysisFailures,
|
||||
queryId
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface RemoteQueryResult {
|
||||
executionEndTime: number; // Can't use a Date here since it needs to be serialized and desserialized.
|
||||
analysisSummaries: AnalysisSummary[];
|
||||
analysisFailures: AnalysisFailure[];
|
||||
queryId: string;
|
||||
}
|
||||
|
||||
export interface AnalysisSummary {
|
||||
|
||||
@@ -302,7 +302,7 @@ export async function runRemoteQuery(
|
||||
message: 'Sending request'
|
||||
});
|
||||
|
||||
const workflowRunId = await runRemoteQueriesApiRequest(credentials, 'main', language, repositories, owner, repo, base64Pack, dryRun);
|
||||
const workflowRunId = await runRemoteQueriesApiRequest(credentials, 'better-errors', language, repositories, owner, repo, base64Pack, dryRun);
|
||||
const queryStartTime = Date.now();
|
||||
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ export const sampleRemoteQuery: RemoteQuery = {
|
||||
};
|
||||
|
||||
export const sampleRemoteQueryResult: RemoteQueryResult = {
|
||||
queryId: 'query123',
|
||||
executionEndTime: new Date('2022-01-06T17:04:37.026Z').getTime(),
|
||||
analysisSummaries: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user