Skip to content

Commit d7bc998

Browse files
authored
Merge pull request #70 from advanced-security/juxtin/ghes-fix
Add support for releaseServerUrl
2 parents 421db58 + 32b6a8b commit d7bc998

File tree

8 files changed

+24225
-3541
lines changed

8 files changed

+24225
-3541
lines changed

babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: 'current' } }],
4+
'@babel/preset-typescript',
5+
],
6+
};

componentDetection.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as github from '@actions/github'
22
import * as core from '@actions/core'
3+
import { Octokit, App } from "octokit"
34
import {
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

Comments
 (0)