Skip to content

Commit 17f1478

Browse files
henrymercerCopilot
andcommitted
Extract the default bundle sources from selectDefaultBundle
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 0e574bc commit 17f1478

2 files changed

Lines changed: 36 additions & 25 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/setup-codeql.ts‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@ export function getCodeQLActionRepository(logger: Logger): string {
9393
return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY");
9494
}
9595

96+
/** Returns the repositories that release the default bundles, most preferred first. */
97+
function getDefaultBundleSources(
98+
apiDetails: api.GitHubApiDetails,
99+
logger: Logger,
100+
): Array<[serverURL: string, repository: string]> {
101+
const codeQLActionRepository = getCodeQLActionRepository(logger);
102+
const potentialDownloadSources: Array<[string, string]> = [
103+
// This GitHub instance, and this Action.
104+
[apiDetails.url, codeQLActionRepository],
105+
// This GitHub instance, and the canonical Action.
106+
[apiDetails.url, CODEQL_DEFAULT_ACTION_REPOSITORY],
107+
// GitHub.com, and the canonical Action.
108+
[util.GITHUB_DOTCOM_URL, CODEQL_DEFAULT_ACTION_REPOSITORY],
109+
];
110+
// We now filter out any duplicates.
111+
// Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
112+
return potentialDownloadSources.filter((source, index, self) => {
113+
return !self.slice(0, index).some((other) => deepEqual(source, other));
114+
});
115+
}
116+
96117
/**
97118
* Selects a bundle from the first release tagged `tagName` that has a compatible bundle, trying the
98119
* Action repositories on this GitHub instance before the canonical Action on GitHub.com. If we
@@ -106,23 +127,10 @@ async function selectDefaultBundle(
106127
options: BundleSelectionOptions,
107128
): Promise<BundleSelection> {
108129
const { logger } = action;
109-
const codeQLActionRepository = getCodeQLActionRepository(logger);
110-
const potentialDownloadSources = [
111-
// This GitHub instance, and this Action.
112-
[apiDetails.url, codeQLActionRepository],
113-
// This GitHub instance, and the canonical Action.
114-
[apiDetails.url, CODEQL_DEFAULT_ACTION_REPOSITORY],
115-
// GitHub.com, and the canonical Action.
116-
[util.GITHUB_DOTCOM_URL, CODEQL_DEFAULT_ACTION_REPOSITORY],
117-
];
118-
// We now filter out any duplicates.
119-
// Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
120-
const uniqueDownloadSources = potentialDownloadSources.filter(
121-
(source, index, self) => {
122-
return !self.slice(0, index).some((other) => deepEqual(source, other));
123-
},
124-
);
125-
for (const [serverURL, repository] of uniqueDownloadSources) {
130+
for (const [serverURL, repository] of getDefaultBundleSources(
131+
apiDetails,
132+
logger,
133+
)) {
126134
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
127135
if (
128136
serverURL === util.GITHUB_DOTCOM_URL &&

0 commit comments

Comments
 (0)