1
1
import * as github from '@actions/github'
2
2
import * as core from '@actions/core'
3
+ import { Octokit , App } from "octokit"
3
4
import {
4
5
PackageCache ,
5
6
BuildTarget ,
@@ -140,14 +141,28 @@ export default class ComponentDetection {
140
141
}
141
142
142
143
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
+
145
160
const owner = "microsoft" ;
146
161
const repo = "component-detection" ;
162
+ core . debug ( "Attempting to download latest release from " + githubAPIURL ) ;
147
163
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} ) ;
151
166
152
167
var downloadURL : string = "" ;
153
168
const assetName = process . platform === "win32" ? "component-detection-win-x64.exe" : "component-detection-linux-x64" ;
@@ -158,6 +173,12 @@ export default class ComponentDetection {
158
173
} ) ;
159
174
160
175
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
+ }
161
182
}
162
183
}
163
184
0 commit comments