1
1
import 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" ;
3
6
import type { VariantAnalysis } from "./shared/variant-analysis" ;
4
7
import type { Credentials } from "../common/authentication" ;
5
8
import type { NotificationLogger } from "../common/logging" ;
@@ -10,6 +13,13 @@ import { withProgress, progressUpdate } from "../common/vscode/progress";
10
13
import type { ProgressCallback } from "../common/vscode/progress" ;
11
14
import { join , dirname , parse } from "path" ;
12
15
import { 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 ;
13
23
14
24
/**
15
25
* Generates autofixes for the results of a variant analysis.
@@ -40,6 +50,12 @@ export async function viewAutofixesForVariantAnalysisResults(
40
50
progress ( progressUpdate ( 2 , 4 , `Generating query help override` ) ) ;
41
51
await overrideQueryHelp ( variantAnalysis , cliServer , localAutofixPath ) ;
42
52
53
+ // Get the full names (nwos) of the selected repositories.
54
+ const selectedRepoNames = getSelectedRepositoryNames (
55
+ variantAnalysis ,
56
+ filterSort ,
57
+ ) ;
58
+
43
59
// TODO
44
60
} ,
45
61
{
@@ -130,3 +146,38 @@ async function overrideQueryHelp(
130
146
queryHelpOverrideDirectory ,
131
147
) ;
132
148
}
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