Skip to content

Commit

Permalink
fix: move server url to entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
goatwu1993 committed Nov 11, 2024
1 parent e2bd1ca commit 3e659c2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
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
4 changes: 2 additions & 2 deletions src/changelog-notes/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import {
BuildNotesOptions,
} from '../changelog-notes';
import {ConventionalCommit} from '../commit';
import { DEFAULT_GITHUB_SERVER_URL } from '../util/github-server';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const conventionalChangelogWriter = require('conventional-changelog-writer');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const presetFactory = require('conventional-changelog-conventionalcommits');
const DEFAULT_HOST = 'https://github.com';

interface DefaultChangelogNotesOptions {
commitPartial?: string;
Expand Down Expand Up @@ -53,7 +53,7 @@ export class DefaultChangelogNotes implements ChangelogNotes {
options: BuildNotesOptions
): Promise<string> {
const context = {
host: options.host || DEFAULT_GITHUB_SERVER_URL,
host: options.host || DEFAULT_HOST,
owner: options.owner,
repository: options.repository,
version: options.version,
Expand Down
10 changes: 8 additions & 2 deletions 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 All @@ -50,7 +51,6 @@ import {Logger} from 'code-suggester/build/src/types';
import {HttpsProxyAgent} from 'https-proxy-agent';
import {HttpProxyAgent} from 'http-proxy-agent';
import {PullRequestOverflowHandler} from './util/pull-request-overflow-handler';
import {DEFAULT_GITHUB_SERVER_URL} from './util/github-server';

// Extract some types from the `request` package.
type RequestBuilderType = typeof request;
Expand All @@ -63,6 +63,7 @@ export interface OctokitAPIs {
}

export interface GitHubOptions {
serverUrl: string;
repository: Repository;
octokitAPIs: OctokitAPIs;
logger?: Logger;
Expand All @@ -77,6 +78,7 @@ interface GitHubCreateOptions {
owner: string;
repo: string;
defaultBranch?: string;
serverUrl?: string;
apiUrl?: string;
graphqlUrl?: string;
octokitAPIs?: OctokitAPIs;
Expand Down Expand Up @@ -209,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 @@ -247,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 @@ -278,6 +283,7 @@ export class GitHub {
}),
};
const opts = {
serverUrl,
repository: {
owner: options.owner,
repo: options.repo,
Expand Down Expand Up @@ -1431,7 +1437,7 @@ export class GitHub {
commentOnIssue = wrapAsync(
async (comment: string, number: number): Promise<string> => {
this.logger.debug(
`adding comment to ${DEFAULT_GITHUB_SERVER_URL}/${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
5 changes: 2 additions & 3 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
} from './util/pull-request-overflow-handler';
import {signoffCommitMessage} from './util/signoff-commit-message';
import {CommitExclude} from './util/commit-exclude';
import {DEFAULT_GITHUB_SERVER_URL} from './util/github-server';

type ExtraGenericFile = {
type: 'generic';
Expand Down Expand Up @@ -1052,7 +1051,7 @@ export class Manifest {
// If unchanged, no need to push updates
if (existing.body === pullRequest.body.toString()) {
this.logger.info(
`PR ${DEFAULT_GITHUB_SERVER_URL}/${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 @@ -1077,7 +1076,7 @@ export class Manifest {
// If unchanged, no need to push updates
if (snoozed.body === pullRequest.body.toString()) {
this.logger.info(
`PR ${DEFAULT_GITHUB_SERVER_URL}/${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
1 change: 0 additions & 1 deletion src/util/github-server.ts

This file was deleted.

0 comments on commit 3e659c2

Please sign in to comment.