Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix links error when using GitHub Enterprise #2350

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,6 +44,7 @@ interface ErrorObject {
interface GitHubArgs {
dryRun?: boolean;
trace?: boolean;
serverUrl?: string;
repoUrl?: string;
token?: string;
apiUrl?: string;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -803,6 +810,7 @@ async function buildGitHub(argv: GitHubArgs): Promise<GitHub> {
owner,
repo,
token: argv.token!,
serverUrl: argv.serverUrl,
apiUrl: argv.apiUrl,
graphqlUrl: argv.graphqlUrl,
});
Expand Down
9 changes: 8 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Octokit>;
Expand Down Expand Up @@ -62,6 +63,7 @@ export interface OctokitAPIs {
}

export interface GitHubOptions {
serverUrl: string;
repository: Repository;
octokitAPIs: OctokitAPIs;
logger?: Logger;
Expand All @@ -76,6 +78,7 @@ interface GitHubCreateOptions {
owner: string;
repo: string;
defaultBranch?: string;
serverUrl?: string;
apiUrl?: string;
graphqlUrl?: string;
octokitAPIs?: OctokitAPIs;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -246,6 +251,7 @@ export class GitHub {
* @param {string} token Optional. A GitHub API token used for authentication.
*/
static async create(options: GitHubCreateOptions): Promise<GitHub> {
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;
Expand Down Expand Up @@ -277,6 +283,7 @@ export class GitHub {
}),
};
const opts = {
serverUrl,
repository: {
owner: options.owner,
repo: options.repo,
Expand Down Expand Up @@ -1430,7 +1437,7 @@ export class GitHub {
commentOnIssue = wrapAsync(
async (comment: string, number: number): Promise<string> => {
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,
Expand Down
4 changes: 2 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down