Skip to content

Commit 8e4ec1e

Browse files
committed
refactor
1 parent a834e17 commit 8e4ec1e

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/github.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const githubContext = vi.hoisted(() => ({
1515
owner: "changesets",
1616
repo: "action",
1717
},
18-
serverUrl: "http://127.0.0.1",
1918
sha: "base-sha",
2019
}));
2120

@@ -74,7 +73,6 @@ describe("GitHub", () => {
7473
const repository = repositoryFixture.path;
7574

7675
const serverUrl = new URL(remote.url).origin;
77-
githubContext.serverUrl = serverUrl;
7876
await git(repository, ["remote", "set-url", "origin", remote.url]);
7977
await git(repository, [
8078
"config",
@@ -87,6 +85,7 @@ describe("GitHub", () => {
8785
cwd: repository,
8886
githubToken: actionToken,
8987
pushWithGitCli: true,
88+
serverUrl,
9089
});
9190

9291
await github.pushChanges({
@@ -122,7 +121,6 @@ describe("GitHub", () => {
122121
const repository = repositoryFixture.path;
123122

124123
const remoteUrl = new URL(remote.url);
125-
githubContext.serverUrl = remoteUrl.origin;
126124
remoteUrl.username = "x-access-token";
127125
remoteUrl.password = "checkout-token";
128126
await git(repository, ["remote", "set-url", "origin", remoteUrl.href]);
@@ -139,6 +137,7 @@ describe("GitHub", () => {
139137
cwd: repository,
140138
githubToken: actionToken,
141139
pushWithGitCli: true,
140+
serverUrl: remoteUrl.origin,
142141
});
143142

144143
await github.pushChanges({

src/github.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,23 @@ export class GitHub {
7272
readonly octokit: Octokit;
7373
readonly cwd: string;
7474
readonly pushWithGitCli: boolean;
75+
readonly serverUrl: string;
7576

7677
constructor(options: {
7778
githubToken: string;
7879
cwd: string;
7980
pushWithGitCli?: boolean;
81+
serverUrl?: string;
8082
}) {
8183
this.#githubToken = options.githubToken;
8284
this.cwd = options.cwd;
8385
this.pushWithGitCli = options.pushWithGitCli ?? false;
86+
this.serverUrl = (
87+
options.serverUrl ??
88+
context.serverUrl ??
89+
process.env.GITHUB_SERVER_URL ??
90+
"https://github.com"
91+
).replace(/\/+$/, "");
8492
this.octokit = setupOctokit(options.githubToken);
8593
}
8694

@@ -92,11 +100,6 @@ export class GitHub {
92100
const basic = Buffer.from(`x-access-token:${this.#githubToken}`).toString(
93101
"base64",
94102
);
95-
const serverUrl = (
96-
context.serverUrl ??
97-
process.env.GITHUB_SERVER_URL ??
98-
"https://github.com"
99-
).replace(/\/+$/, "");
100103
const gitConfigCount = Number(process.env.GIT_CONFIG_COUNT ?? 0);
101104
if (!Number.isInteger(gitConfigCount) || gitConfigCount < 0) {
102105
throw new Error(
@@ -121,7 +124,7 @@ export class GitHub {
121124
// extraheader normally installed by actions/checkout, while an exact push
122125
// URL also outranks any inherited path-specific extraheader. Only the most
123126
// specific matching subsection contributes, so these do not duplicate it.
124-
const extraHeaderKeys = new Set([`http.${serverUrl}/.extraheader`]);
127+
const extraHeaderKeys = new Set([`http.${this.serverUrl}/.extraheader`]);
125128
for (const remoteUrl of stdout.split(/\r?\n/)) {
126129
const httpUrl = getHttpUrl(remoteUrl);
127130
if (httpUrl !== undefined) {

0 commit comments

Comments
 (0)