11import * as github from '@actions/github'
22import * as core from '@actions/core'
3+ import { Octokit , App } from "octokit"
34import {
45 PackageCache ,
56 BuildTarget ,
@@ -140,14 +141,28 @@ export default class ComponentDetection {
140141 }
141142
142143 private static async getLatestReleaseURL ( ) : Promise < string > {
143- const githubToken = core . getInput ( 'token' ) || process . env . GITHUB_TOKEN || "" ;
144- const octokit = github . getOctokit ( githubToken ) ;
144+ let githubToken = core . getInput ( 'token' ) || process . env . GITHUB_TOKEN || "" ;
145+
146+ const githubAPIURL = 'https://api.github.com'
147+
148+ let ghesMode = github . context . apiUrl != githubAPIURL ;
149+ // If the we're running in GHES, then use an empty string as the token
150+ if ( ghesMode ) {
151+ githubToken = "" ;
152+ }
153+ const octokit = new Octokit ( { auth : githubToken , baseUrl : githubAPIURL , request : { fetch : fetch } , log : {
154+ debug : core . debug ,
155+ info : core . info ,
156+ warn : core . warning ,
157+ error : core . error
158+ } , } ) ;
159+
145160 const owner = "microsoft" ;
146161 const repo = "component-detection" ;
162+ core . debug ( "Attempting to download latest release from " + githubAPIURL ) ;
147163
148- const latestRelease = await octokit . rest . repos . getLatestRelease ( {
149- owner, repo
150- } ) ;
164+ try {
165+ const latestRelease = await octokit . request ( "GET /repos/{owner}/{repo}/releases/latest" , { owner, repo} ) ;
151166
152167 var downloadURL : string = "" ;
153168 const assetName = process . platform === "win32" ? "component-detection-win-x64.exe" : "component-detection-linux-x64" ;
@@ -158,6 +173,12 @@ export default class ComponentDetection {
158173 } ) ;
159174
160175 return downloadURL ;
176+ } catch ( error : any ) {
177+ core . error ( error ) ;
178+ core . debug ( error . message ) ;
179+ core . debug ( error . stack ) ;
180+ throw new Error ( "Failed to download latest release" ) ;
181+ }
161182 }
162183}
163184
0 commit comments