11import type { RepositoriesFilterSortStateWithIds } from "./shared/variant-analysis-filter-sort" ;
2- import { defaultFilterSortState } from "./shared/variant-analysis-filter-sort" ;
2+ import {
3+ defaultFilterSortState ,
4+ filterAndSortRepositoriesWithResults ,
5+ } from "./shared/variant-analysis-filter-sort" ;
36import type { VariantAnalysis } from "./shared/variant-analysis" ;
47import type { Credentials } from "../common/authentication" ;
58import type { NotificationLogger } from "../common/logging" ;
@@ -10,6 +13,13 @@ import { withProgress, progressUpdate } from "../common/vscode/progress";
1013import type { ProgressCallback } from "../common/vscode/progress" ;
1114import { join , dirname , parse } from "path" ;
1215import { tryGetQueryMetadata } from "../codeql-cli/query-metadata" ;
16+ import { window as Window } from "vscode" ;
17+
18+ // Limit to three repos when generating autofixes so not sending
19+ // too many requests to autofix. Since we only need to validate
20+ // a handle of autofixes for each query, this should be sufficient.
21+ // Consider increasing this in the future if needed.
22+ const MAX_NUM_REPOS : number = 3 ;
1323
1424/**
1525 * Generates autofixes for the results of a variant analysis.
@@ -40,6 +50,12 @@ export async function viewAutofixesForVariantAnalysisResults(
4050 progress ( progressUpdate ( 2 , 4 , `Generating query help override` ) ) ;
4151 await overrideQueryHelp ( variantAnalysis , cliServer , localAutofixPath ) ;
4252
53+ // Get the full names (nwos) of the selected repositories.
54+ const selectedRepoNames = getSelectedRepositoryNames (
55+ variantAnalysis ,
56+ filterSort ,
57+ ) ;
58+
4359 // TODO
4460 } ,
4561 {
@@ -130,3 +146,38 @@ async function overrideQueryHelp(
130146 queryHelpOverrideDirectory ,
131147 ) ;
132148}
149+
150+ /**
151+ * Gets the full names (owner/repo) of the selected
152+ * repositories from the given variant analysis while
153+ * limiting the number of repositories to `MAX_NUM_REPOS`.
154+ */
155+ function getSelectedRepositoryNames (
156+ variantAnalysis : VariantAnalysis ,
157+ filterSort : RepositoriesFilterSortStateWithIds ,
158+ ) : string [ ] {
159+ // Get the repositories that were selected by the user.
160+ const filteredRepositories = filterAndSortRepositoriesWithResults (
161+ variantAnalysis . scannedRepos ,
162+ filterSort ,
163+ ) ;
164+
165+ // Get the full names (owner/repo = nwo) of the selected repos.
166+ let fullNames = filteredRepositories
167+ ?. filter ( ( a ) => a . resultCount && a . resultCount > 0 )
168+ . map ( ( a ) => a . repository . fullName ) ;
169+ if ( ! fullNames || fullNames . length === 0 ) {
170+ throw new Error ( "No repositories with results found." ) ;
171+ }
172+
173+ // Limit to MAX_NUM_REPOS by slicing the array,
174+ // and inform the user about the limit.
175+ if ( fullNames . length > MAX_NUM_REPOS ) {
176+ fullNames = fullNames . slice ( 0 , MAX_NUM_REPOS ) ;
177+ void Window . showInformationMessage (
178+ `Only the first ${ MAX_NUM_REPOS } repos (${ fullNames . join ( ", " ) } ) will be included in the Autofix results.` ,
179+ ) ;
180+ }
181+
182+ return fullNames ;
183+ }
0 commit comments