Skip to content

Commit 7f13c04

Browse files
committed
Update GHES URL for listing orgs
1 parent 9ea2fa0 commit 7f13c04

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async function main() {
1818
.option("org", { type: "string", describe: "Single organization login" })
1919
.option("repo", { type: "string", describe: "Single repository name" })
2020
.option("base-url", { type: "string", describe: "GitHub Enterprise Server base URL, e.g. https://github.mycompany.com/api/v3" })
21+
.option("ghes", { type: "boolean", default: false, describe: "Indicates that the provided base URL is for GitHub Enterprise Server" })
2122
.option("concurrency", { type: "number", default: 5 })
2223
.option("sbom-delay", { type: "number", default: 3000, describe: "Delay (ms) between SBOM fetch requests" })
2324
.option("light-delay", { type: "number", default: 100, describe: "Delay (ms) between lightweight metadata requests (org/repo listing, commit head checks)" })
@@ -122,6 +123,7 @@ async function main() {
122123
org: argv.org as string | undefined,
123124
repo: argv.repo as string | undefined,
124125
baseUrl: argv["base-url"] as string | undefined,
126+
ghes: argv.ghes as boolean | undefined,
125127
concurrency: argv.concurrency as number,
126128
delayMsBetweenRepos: argv["sbom-delay"] as number,
127129
lightDelayMs: argv["light-delay"] as number,

src/sbomCollector.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export interface CollectorOptions {
1414
enterprise?: string; // Enterprise slug to enumerate orgs
1515
org?: string; // Single org alternative
1616
repo?: string; // Single repo alternative
17-
baseUrl?: string; // For GHES
17+
baseUrl?: string; // For GHES, EMU and Data Residency
18+
ghes?: boolean; // Is this a GHES instance?
1819
concurrency?: number; // parallel repo SBOM fetches
1920
includePrivate?: boolean;
2021
delayMsBetweenRepos?: number;
@@ -53,6 +54,7 @@ export class SbomCollector {
5354
this.opts = {
5455
token: o.token,
5556
enterprise: o.enterprise,
57+
ghes: o.ghes ?? false,
5658
org: o.org,
5759
repo: o.repo,
5860
baseUrl: o.baseUrl,
@@ -149,7 +151,7 @@ export class SbomCollector {
149151
process.stderr.write(chalk.blue(`Getting list of organizations for enterprise ${this.opts.enterprise}`) + "\n");
150152
}
151153

152-
const orgs = this.opts.org ? [this.opts.org] : this.opts.enterprise ? await this.listEnterpriseOrgs(this.opts.enterprise!) : [this.opts.repo.split("/")[0]];
154+
const orgs = this.opts.org ? [this.opts.org] : this.opts.enterprise ? await this.listEnterpriseOrgs(this.opts.enterprise, this.opts.ghes) : [this.opts.repo.split("/")[0]];
153155
this.summary.orgs = orgs;
154156

155157
// Pre-list all repos if showing progress bar so we know the total upfront
@@ -368,7 +370,7 @@ export class SbomCollector {
368370
return false;
369371
}
370372

371-
private async listEnterpriseOrgs(enterprise: string): Promise<string[]> {
373+
private async listEnterpriseOrgs(enterprise: string, ghes: boolean): Promise<string[]> {
372374
if (!this.octokit) throw new Error("No Octokit instance");
373375
interface Org { login: string }
374376
try {
@@ -377,7 +379,7 @@ export class SbomCollector {
377379
let page = 1;
378380
let done = false;
379381
while (!done) {
380-
const resp = await this.octokit.request("GET /enterprises/{enterprise}/orgs", { enterprise, per_page, page });
382+
const resp = await this.octokit.request(ghes ? "GET /orgs" : "GET /enterprises/{enterprise}/orgs", { enterprise, per_page, page });
381383
const items = resp.data as unknown as Org[];
382384
for (const o of items) orgs.push(o.login);
383385
if (items.length < per_page) done = true; else page++;

0 commit comments

Comments
 (0)