diff --git a/dist/index.js b/dist/index.js index c349eb7a..0df0929b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -151,9 +151,11 @@ class DotNetSdkUpdater { }); } } - // TODO Update to support GHE - body += `\n\nThis pull request was auto-generated by [GitHub Actions](https://github.com/${this.options.repo}/actions/runs/${this.options.runId}).`; - const octokit = github.getOctokit(this.options.accessToken); + body += `\n\nThis pull request was auto-generated by [GitHub Actions](${this.options.serverUrl}/${this.options.repo}/actions/runs/${this.options.runId}).`; + const options = { + baseUrl: this.options.apiUrl + }; + const octokit = github.getOctokit(this.options.accessToken, options); const split = ((_a = this.options.repo) !== null && _a !== void 0 ? _a : "/").split("/"); const owner = split[0]; const repo = split[1]; @@ -320,8 +322,7 @@ class DotNetSdkUpdater { core.info(`Updated git user email to '${this.options.userEmail}'`); } if (this.options.repo) { - // TODO Update to support GHE - await this.execGit(["remote", "set-url", "origin", `https://github.com/${this.options.repo}.git`]); + await this.execGit(["remote", "set-url", "origin", `${this.options.serverUrl}/${this.options.repo}.git`]); await this.execGit(["fetch", "origin"], true); } core.debug(`Branch: ${this.options.branch}`); @@ -398,7 +399,7 @@ const fs = __importStar(__webpack_require__(5747)); const path = __importStar(__webpack_require__(5622)); const DotNetSdkUpdater_1 = __webpack_require__(424); async function run() { - var _a; + var _a, _b, _c; try { const accessToken = core.getInput("repo-token", { required: true }); const globalJsonFileName = core.getInput("global-json-file", { required: true }); @@ -409,14 +410,16 @@ async function run() { } const options = { accessToken: accessToken, + apiUrl: (_a = process.env.GITHUB_API_URL) !== null && _a !== void 0 ? _a : "https://api.github.com", branch: core.getInput("branch-name", { required: false }), channel: core.getInput("channel", { required: false }), commitMessage: core.getInput("commit-message", { required: false }), dryRun: core.getInput("dry-run", { required: false }) === "true", globalJsonPath: globalJsonPath, - labels: (_a = core.getInput("labels", { required: false })) !== null && _a !== void 0 ? _a : "", + labels: (_b = core.getInput("labels", { required: false })) !== null && _b !== void 0 ? _b : "", repo: process.env.GITHUB_REPOSITORY, runId: process.env.GITHUB_RUN_ID, + serverUrl: (_c = process.env.GITHUB_SERVER_URL) !== null && _c !== void 0 ? _c : "https://github.com", userEmail: core.getInput("user-email", { required: false }), userName: core.getInput("user-name", { required: false }) }; diff --git a/src/DotNetSdkUpdater.ts b/src/DotNetSdkUpdater.ts index ab5d553c..15f2d055 100644 --- a/src/DotNetSdkUpdater.ts +++ b/src/DotNetSdkUpdater.ts @@ -155,10 +155,13 @@ export class DotNetSdkUpdater { } } - // TODO Update to support GHE - body += `\n\nThis pull request was auto-generated by [GitHub Actions](https://github.com/${this.options.repo}/actions/runs/${this.options.runId}).` + body += `\n\nThis pull request was auto-generated by [GitHub Actions](${this.options.serverUrl}/${this.options.repo}/actions/runs/${this.options.runId}).` - const octokit = github.getOctokit(this.options.accessToken); + const options = { + baseUrl: this.options.apiUrl + }; + + const octokit = github.getOctokit(this.options.accessToken, options); const split = (this.options.repo ?? "/").split("/"); const owner = split[0]; @@ -381,8 +384,7 @@ export class DotNetSdkUpdater { } if (this.options.repo) { - // TODO Update to support GHE - await this.execGit([ "remote", "set-url", "origin", `https://github.com/${this.options.repo}.git` ]); + await this.execGit([ "remote", "set-url", "origin", `${this.options.serverUrl}/${this.options.repo}.git` ]); await this.execGit([ "fetch", "origin" ], true); } diff --git a/src/UpdateOptions.ts b/src/UpdateOptions.ts index 4eddf239..a579b627 100644 --- a/src/UpdateOptions.ts +++ b/src/UpdateOptions.ts @@ -5,6 +5,8 @@ export interface UpdateOptions { accessToken: string; + apiUrl?: string; + branch: string; channel: string; @@ -21,6 +23,8 @@ export interface UpdateOptions { runId?: string; + serverUrl?: string; + userEmail: string; userName: string; diff --git a/src/update-dotnet-sdk.ts b/src/update-dotnet-sdk.ts index 150c60cd..de86804b 100644 --- a/src/update-dotnet-sdk.ts +++ b/src/update-dotnet-sdk.ts @@ -23,6 +23,7 @@ export async function run() { const options: UpdateOptions = { accessToken: accessToken, + apiUrl: process.env.GITHUB_API_URL ?? "https://api.github.com", branch: core.getInput("branch-name", { required: false }), channel: core.getInput("channel", { required: false }), commitMessage: core.getInput("commit-message", { required: false }), @@ -31,6 +32,7 @@ export async function run() { labels: core.getInput("labels", { required: false }) ?? "", repo: process.env.GITHUB_REPOSITORY, runId: process.env.GITHUB_RUN_ID, + serverUrl: process.env.GITHUB_SERVER_URL ?? "https://github.com", userEmail: core.getInput("user-email", { required: false }), userName: core.getInput("user-name", { required: false }) }; diff --git a/tests/update-dotnet-sdk.test.ts b/tests/update-dotnet-sdk.test.ts index 2f9409e0..f9175c07 100644 --- a/tests/update-dotnet-sdk.test.ts +++ b/tests/update-dotnet-sdk.test.ts @@ -18,7 +18,9 @@ const globalJsonPath = path.join(tempDir, "global.json"); describe("update-dotnet-sdk tests", () => { const inputs = { + "GITHUB_API_URL": "https://github.local/api/v3", "GITHUB_REPOSITORY": "", + "GITHUB_SERVER_URL": "https://github.local", "INPUT_GLOBAL-JSON-FILE": globalJsonPath, "INPUT_LABELS": "foo,bar", "INPUT_REPO-TOKEN": "my-token", @@ -61,7 +63,7 @@ describe("update-dotnet-sdk tests", () => { create: () => Promise.resolve({ data: { number: "42", - html_url: "https://github.com/martincostello/update-dotnet-sdk/pull/42" + html_url: "https://github.local/martincostello/update-dotnet-sdk/pull/42" } }) } @@ -73,7 +75,7 @@ describe("update-dotnet-sdk tests", () => { expect(core.error).toHaveBeenCalledTimes(0); expect(core.setFailed).toHaveBeenCalledTimes(0); - assertWriteCalled(`::set-output name=pull-request-html-url::https://github.com/martincostello/update-dotnet-sdk/pull/42${os.EOL}`); + assertWriteCalled(`::set-output name=pull-request-html-url::https://github.local/martincostello/update-dotnet-sdk/pull/42${os.EOL}`); assertWriteCalled(`::set-output name=pull-request-number::42${os.EOL}`); assertWriteCalled(`::set-output name=sdk-updated::true${os.EOL}`);