Skip to content

Commit

Permalink
Merge pull request #155 from martincostello/support-github-enterprise
Browse files Browse the repository at this point in the history
Support GitHub Enterprise Server
  • Loading branch information
martincostello authored Jun 8, 2022
2 parents ec2e882 + 0ccb573 commit e338756
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
17 changes: 10 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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 });
Expand All @@ -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 })
};
Expand Down
12 changes: 7 additions & 5 deletions src/DotNetSdkUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions src/UpdateOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export interface UpdateOptions {

accessToken: string;

apiUrl?: string;

branch: string;

channel: string;
Expand All @@ -21,6 +23,8 @@ export interface UpdateOptions {

runId?: string;

serverUrl?: string;

userEmail: string;

userName: string;
Expand Down
2 changes: 2 additions & 0 deletions src/update-dotnet-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand All @@ -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 })
};
Expand Down
6 changes: 4 additions & 2 deletions tests/update-dotnet-sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
})
}
Expand All @@ -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}`);

Expand Down

0 comments on commit e338756

Please sign in to comment.