Skip to content

Commit 5c87303

Browse files
sorekzBetaHuhn
andauthored
✨ Add GHES support (#291)
* Add GHES support * package * fix * rebuild dist Co-authored-by: BetaHuhn <[email protected]>
1 parent 5b81d5f commit 5c87303

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ try {
3030

3131
context = {
3232
GITHUB_TOKEN: token,
33+
GITHUB_SERVER_URL: process.env.GITHUB_SERVER_URL || 'https://github.com',
3334
IS_INSTALLATION_TOKEN: isInstallationToken,
3435
GIT_EMAIL: getInput({
3536
key: 'GIT_EMAIL'
@@ -144,7 +145,7 @@ try {
144145
}
145146

146147
const parseRepoName = (fullRepo) => {
147-
let host = 'github.com'
148+
let host = new URL(context.GITHUB_SERVER_URL).host
148149

149150
if (fullRepo.startsWith('http')) {
150151
const url = new URL(fullRepo)

src/git.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import config from './config.js'
1010

1111
const {
1212
GITHUB_TOKEN,
13+
GITHUB_SERVER_URL,
1314
IS_INSTALLATION_TOKEN,
1415
IS_FINE_GRAINED,
1516
GIT_USERNAME,
@@ -32,6 +33,7 @@ export default class Git {
3233
const Octokit = GitHub.plugin(throttling)
3334

3435
const options = getOctokitOptions(GITHUB_TOKEN, {
36+
baseUrl: process.env.GITHUB_API_URL || 'https://api.github.com',
3537
throttle: {
3638
onRateLimit: (retryAfter) => {
3739
core.debug(`Hit GitHub API rate limit, retrying after ${ retryAfter }s`)
@@ -67,9 +69,11 @@ export default class Git {
6769
await this.getLastCommitSha()
6870

6971
if (FORK) {
70-
const forkUrl = `https://${ GITHUB_TOKEN }@github.com/${ FORK }/${ this.repo.name }.git`
72+
const forkUrl = new URL(GITHUB_SERVER_URL)
73+
forkUrl.username = GITHUB_TOKEN
74+
forkUrl.pathname = `${ FORK }/${ this.repo.name }.git`
7175
await this.createFork()
72-
await this.createRemote(forkUrl)
76+
await this.createRemote(forkUrl.toString())
7377

7478
}
7579
}
@@ -421,15 +425,15 @@ export default class Git {
421425

422426
async createOrUpdatePr(changedFiles, title) {
423427
const body = dedent(`
424-
synced local file(s) with [${ GITHUB_REPOSITORY }](https://github.com/${ GITHUB_REPOSITORY }).
428+
synced local file(s) with [${ GITHUB_REPOSITORY }](${ GITHUB_SERVER_URL }/${ GITHUB_REPOSITORY }).
425429
426430
${ PR_BODY }
427431
428432
${ changedFiles }
429433
430434
---
431435
432-
This PR was created automatically by the [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action) workflow run [#${ process.env.GITHUB_RUN_ID || 0 }](https://github.com/${ GITHUB_REPOSITORY }/actions/runs/${ process.env.GITHUB_RUN_ID || 0 })
436+
This PR was created automatically by the [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action) workflow run [#${ process.env.GITHUB_RUN_ID || 0 }](${ GITHUB_SERVER_URL }/${ GITHUB_REPOSITORY }/actions/runs/${ process.env.GITHUB_RUN_ID || 0 })
433437
`)
434438

435439
if (this.existingPr) {

0 commit comments

Comments
 (0)