diff --git a/src/bin/release-please.ts b/src/bin/release-please.ts index 4baf2c626..ab7c7cb08 100644 --- a/src/bin/release-please.ts +++ b/src/bin/release-please.ts @@ -16,7 +16,7 @@ import {coerceOption} from '../util/coerce-option'; import * as yargs from 'yargs'; -import {GitHub, GH_API_URL, GH_GRAPHQL_URL} from '../github'; +import {GitHub, GH_API_URL, GH_GRAPHQL_URL, GH_SERVER_URL} from '../github'; import {Manifest, ManifestOptions, ROOT_PROJECT_PATH} from '../manifest'; import {ChangelogSection, buildChangelogSections} from '../changelog-notes'; import {logger, setLogger, CheckpointLogger} from '../util/logger'; @@ -44,6 +44,7 @@ interface ErrorObject { interface GitHubArgs { dryRun?: boolean; trace?: boolean; + serverUrl?: string; repoUrl?: string; token?: string; apiUrl?: string; @@ -162,6 +163,11 @@ function gitHubOptions(yargs: yargs.Argv): yargs.Argv { default: GH_API_URL, type: 'string', }) + .option('server-url', { + describe: 'URL of the GitHub server', + default: GH_SERVER_URL, + type: 'string', + }) .option('graphql-url', { describe: 'URL to use when making GraphQL requests', default: GH_GRAPHQL_URL, @@ -190,6 +196,7 @@ function gitHubOptions(yargs: yargs.Argv): yargs.Argv { // allow secrets to be loaded from file path // rather than being passed directly to the bin. if (argv.token) argv.token = coerceOption(argv.token); + if (argv.serverUrl) argv.serverUrl = coerceOption(argv.serverUrl); if (argv.apiUrl) argv.apiUrl = coerceOption(argv.apiUrl); if (argv.graphqlUrl) argv.graphqlUrl = coerceOption(argv.graphqlUrl); }); @@ -803,6 +810,7 @@ async function buildGitHub(argv: GitHubArgs): Promise { owner, repo, token: argv.token!, + serverUrl: argv.serverUrl, apiUrl: argv.apiUrl, graphqlUrl: argv.graphqlUrl, }); diff --git a/src/github.ts b/src/github.ts index 0b581b646..ca4e0d6af 100644 --- a/src/github.ts +++ b/src/github.ts @@ -29,6 +29,7 @@ import { const MAX_ISSUE_BODY_SIZE = 65536; const MAX_SLEEP_SECONDS = 20; +export const GH_SERVER_URL = 'https://github.com'; export const GH_API_URL = 'https://api.github.com'; export const GH_GRAPHQL_URL = 'https://api.github.com'; type OctokitType = InstanceType; @@ -62,6 +63,7 @@ export interface OctokitAPIs { } export interface GitHubOptions { + serverUrl: string; repository: Repository; octokitAPIs: OctokitAPIs; logger?: Logger; @@ -76,6 +78,7 @@ interface GitHubCreateOptions { owner: string; repo: string; defaultBranch?: string; + serverUrl?: string; apiUrl?: string; graphqlUrl?: string; octokitAPIs?: OctokitAPIs; @@ -208,8 +211,10 @@ export class GitHub { private graphql: Function; private fileCache: RepositoryFileCache; private logger: Logger; + readonly serverUrl: string; private constructor(options: GitHubOptions) { + this.serverUrl = options.serverUrl; this.repository = options.repository; this.octokit = options.octokitAPIs.octokit; this.request = options.octokitAPIs.request; @@ -246,6 +251,7 @@ export class GitHub { * @param {string} token Optional. A GitHub API token used for authentication. */ static async create(options: GitHubCreateOptions): Promise { + const serverUrl = options.serverUrl ?? GH_SERVER_URL; const apiUrl = options.apiUrl ?? GH_API_URL; const graphqlUrl = options.graphqlUrl ?? GH_GRAPHQL_URL; const releasePleaseVersion = require('../../package.json').version; @@ -277,6 +283,7 @@ export class GitHub { }), }; const opts = { + serverUrl, repository: { owner: options.owner, repo: options.repo, @@ -1430,7 +1437,7 @@ export class GitHub { commentOnIssue = wrapAsync( async (comment: string, number: number): Promise => { this.logger.debug( - `adding comment to https://github.com/${this.repository.owner}/${this.repository.repo}/issues/${number}` + `adding comment to ${this.serverUrl}/${this.repository.owner}/${this.repository.repo}/issues/${number}` ); const resp = await this.octokit.issues.createComment({ owner: this.repository.owner, diff --git a/src/manifest.ts b/src/manifest.ts index 10ac85748..fb93b2c0f 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -1051,7 +1051,7 @@ export class Manifest { // If unchanged, no need to push updates if (existing.body === pullRequest.body.toString()) { this.logger.info( - `PR https://github.com/${this.repository.owner}/${this.repository.repo}/pull/${existing.number} remained the same` + `PR ${this.github.serverUrl}/${this.repository.owner}/${this.repository.repo}/pull/${existing.number} remained the same` ); return undefined; } @@ -1076,7 +1076,7 @@ export class Manifest { // If unchanged, no need to push updates if (snoozed.body === pullRequest.body.toString()) { this.logger.info( - `PR https://github.com/${this.repository.owner}/${this.repository.repo}/pull/${snoozed.number} remained the same` + `PR ${this.github.serverUrl}/${this.repository.owner}/${this.repository.repo}/pull/${snoozed.number} remained the same` ); return undefined; }