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 Config Options to Override github Host #830

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
add config option to set github host
  • Loading branch information
GABeech committed Jun 15, 2022
commit 2202a283a7caa2ec6437b141bb32760b1716ecc2
2 changes: 1 addition & 1 deletion src/git-auth-helper.ts
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class GitAuthHelper {
this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings)

// Token auth header
const serverUrl = urlHelper.getServerUrl()
const serverUrl = urlHelper.getServerUrl(gitSourceSettings?.setHost)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to

- const serverUrl = urlHelper.getServerUrl()
+ const serverUrl = urlHelper.getServerUrl(this.settings.setHost)

this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT]
const basicCredential = Buffer.from(
`x-access-token:${this.settings.authToken}`,
6 changes: 6 additions & 0 deletions src/git-source-settings.ts
Original file line number Diff line number Diff line change
@@ -83,4 +83,10 @@ export interface IGitSourceSettings {
* Indicates whether to add repositoryPath as safe.directory in git global config
*/
setSafeDirectory: boolean

/**
* Set a host to override the automatic detection. Useful when you need to clone
* from cloud when running an action on an on prem server
*/
setHost: string | undefined
}
8 changes: 6 additions & 2 deletions src/url-helper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as assert from 'assert'
import {IGitSourceSettings} from './git-source-settings'
import {URL} from 'url'
import { settings } from 'cluster'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is useless


export function getFetchUrl(settings: IGitSourceSettings): string {
assert.ok(
settings.repositoryOwner,
'settings.repositoryOwner must be defined'
)
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
const serviceUrl = getServerUrl()
const serviceUrl = getServerUrl(settings.setHost)
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
const encodedName = encodeURIComponent(settings.repositoryName)
if (settings.sshKey) {
@@ -19,7 +20,10 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
}

export function getServerUrl(): URL {
export function getServerUrl(configHost: string|undefined = undefined): URL {
if (configHost) {
return new URL(configHost)
}
// todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
return new URL(
process.env['GITHUB_SERVER_URL'] ||