Skip to content

Commit

Permalink
✨ Add GHES support (#291)
Browse files Browse the repository at this point in the history
* Add GHES support

* package

* fix

* rebuild dist

Co-authored-by: BetaHuhn <schiller@mxis.ch>
  • Loading branch information
sorekz and BetaHuhn authored Jan 10, 2023
1 parent 5b81d5f commit 5c87303
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ try {

context = {
GITHUB_TOKEN: token,
GITHUB_SERVER_URL: process.env.GITHUB_SERVER_URL || 'https://github.com',
IS_INSTALLATION_TOKEN: isInstallationToken,
GIT_EMAIL: getInput({
key: 'GIT_EMAIL'
Expand Down Expand Up @@ -144,7 +145,7 @@ try {
}

const parseRepoName = (fullRepo) => {
let host = 'github.com'
let host = new URL(context.GITHUB_SERVER_URL).host

if (fullRepo.startsWith('http')) {
const url = new URL(fullRepo)
Expand Down
12 changes: 8 additions & 4 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import config from './config.js'

const {
GITHUB_TOKEN,
GITHUB_SERVER_URL,
IS_INSTALLATION_TOKEN,
IS_FINE_GRAINED,
GIT_USERNAME,
Expand All @@ -32,6 +33,7 @@ export default class Git {
const Octokit = GitHub.plugin(throttling)

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

if (FORK) {
const forkUrl = `https://${ GITHUB_TOKEN }@github.com/${ FORK }/${ this.repo.name }.git`
const forkUrl = new URL(GITHUB_SERVER_URL)
forkUrl.username = GITHUB_TOKEN
forkUrl.pathname = `${ FORK }/${ this.repo.name }.git`
await this.createFork()
await this.createRemote(forkUrl)
await this.createRemote(forkUrl.toString())

}
}
Expand Down Expand Up @@ -421,15 +425,15 @@ export default class Git {

async createOrUpdatePr(changedFiles, title) {
const body = dedent(`
synced local file(s) with [${ GITHUB_REPOSITORY }](https://github.com/${ GITHUB_REPOSITORY }).
synced local file(s) with [${ GITHUB_REPOSITORY }](${ GITHUB_SERVER_URL }/${ GITHUB_REPOSITORY }).
${ PR_BODY }
${ changedFiles }
---
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 })
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 })
`)

if (this.existingPr) {
Expand Down

0 comments on commit 5c87303

Please sign in to comment.