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

feat: support github server url for pushing to fork #1315

Merged
merged 1 commit into from Nov 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/create-pull-request.ts
Expand Up @@ -74,6 +74,7 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
// Add a remote for the fork
const remoteUrl = utils.getRemoteUrl(
baseRemote.protocol,
baseRemote.hostname,
branchRepository
)
await git.exec(['remote', 'add', 'fork', remoteUrl])
Expand Down
15 changes: 10 additions & 5 deletions src/utils.ts
Expand Up @@ -32,6 +32,7 @@ export function getRepoPath(relativePath?: string): string {
}

interface RemoteDetail {
hostname: string
protocol: string
repository: string
}
Expand All @@ -46,18 +47,21 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
throw new Error('Could not parse GitHub Server name')
}

const hostname = githubServerMatch[1]

const httpsUrlPattern = new RegExp(
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(\\.git)?$',
'^https?://.*@?' + hostname + '/(.+/.+?)(\\.git)?$',
'i'
)
const sshUrlPattern = new RegExp(
'^git@' + githubServerMatch[1] + ':(.+/.+)\\.git$',
'^git@' + hostname + ':(.+/.+)\\.git$',
'i'
)

const httpsMatch = remoteUrl.match(httpsUrlPattern)
if (httpsMatch) {
return {
hostname,
protocol: 'HTTPS',
repository: httpsMatch[1]
}
Expand All @@ -66,6 +70,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
const sshMatch = remoteUrl.match(sshUrlPattern)
if (sshMatch) {
return {
hostname,
protocol: 'SSH',
repository: sshMatch[1]
}
Expand All @@ -76,10 +81,10 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
)
}

export function getRemoteUrl(protocol: string, repository: string): string {
export function getRemoteUrl(protocol: string, hostname: string, repository: string): string {
return protocol == 'HTTPS'
? `https://github.com/${repository}`
: `git@github.com:${repository}.git`
? `https://${hostname}/${repository}`
: `git@${hostname}:${repository}.git`
}

export function secondsSinceEpoch(): number {
Expand Down