@@ -11,7 +11,12 @@ import {
1111} from "./per-language-bundles" ;
1212import { BundlePlatform } from "./platform" ;
1313import type { CompressionMethod } from "./tar" ;
14- import { ConfigurationError , GITHUB_DOTCOM_URL , GitHubVariant } from "./util" ;
14+ import {
15+ asHTTPError ,
16+ ConfigurationError ,
17+ GITHUB_DOTCOM_URL ,
18+ GitHubVariant ,
19+ } from "./util" ;
1520
1621/** Identifies a release on a GitHub instance. */
1722export interface CodeQLReleaseReference {
@@ -188,6 +193,32 @@ export function getPublicRelease(
188193 } ;
189194}
190195
196+ /** Gets a release requested by URL, looking it up if it's on the current GitHub instance. */
197+ export async function getRequestedRelease (
198+ action : ActionState < [ "Api" ] > ,
199+ requested : RequestedRelease ,
200+ ) : Promise < CodeQLRelease > {
201+ if ( ! requested . isCurrentInstance ) {
202+ // We can't send the token to another instance, so only public releases are usable there, and we
203+ // download them by URL rather than querying that instance's API. On the current instance we use
204+ // the API instead, because release download URLs don't accept tokens and so would fail for
205+ // private and internal repositories. Without the release's asset list, we assume the preferred
206+ // compression is available and take the CLI version from the tag.
207+ return getPublicRelease ( requested ) ;
208+ }
209+ try {
210+ return await getRelease ( action , requested ) ;
211+ } catch ( e ) {
212+ if ( asHTTPError ( e ) ?. status === 404 ) {
213+ throw new ConfigurationError (
214+ `Could not find the CodeQL release ${ getReleasePageURL ( requested ) } . Check that it ` +
215+ "exists and that the token has access to it." ,
216+ ) ;
217+ }
218+ throw e ;
219+ }
220+ }
221+
191222/** Describes the job and runner that we are selecting a bundle for. */
192223export interface BundleSelectionOptions {
193224 /** Explicit `languages` input, which determines whether a per-language bundle is eligible. */
0 commit comments