Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GHES support #291

Merged
merged 6 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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