Skip to content

Commit 7e67080

Browse files
MildCkevinzhu-sa
andauthored
feat: support github server url for pushing to fork (#1315)
Co-authored-by: Kevin Zhu <[email protected]>
1 parent d7db273 commit 7e67080

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/create-pull-request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
7474
// Add a remote for the fork
7575
const remoteUrl = utils.getRemoteUrl(
7676
baseRemote.protocol,
77+
baseRemote.hostname,
7778
branchRepository
7879
)
7980
await git.exec(['remote', 'add', 'fork', remoteUrl])

src/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function getRepoPath(relativePath?: string): string {
3232
}
3333

3434
interface RemoteDetail {
35+
hostname: string
3536
protocol: string
3637
repository: string
3738
}
@@ -46,18 +47,21 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
4647
throw new Error('Could not parse GitHub Server name')
4748
}
4849

50+
const hostname = githubServerMatch[1]
51+
4952
const httpsUrlPattern = new RegExp(
50-
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(\\.git)?$',
53+
'^https?://.*@?' + hostname + '/(.+/.+?)(\\.git)?$',
5154
'i'
5255
)
5356
const sshUrlPattern = new RegExp(
54-
'^git@' + githubServerMatch[1] + ':(.+/.+)\\.git$',
57+
'^git@' + hostname + ':(.+/.+)\\.git$',
5558
'i'
5659
)
5760

5861
const httpsMatch = remoteUrl.match(httpsUrlPattern)
5962
if (httpsMatch) {
6063
return {
64+
hostname,
6165
protocol: 'HTTPS',
6266
repository: httpsMatch[1]
6367
}
@@ -66,6 +70,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
6670
const sshMatch = remoteUrl.match(sshUrlPattern)
6771
if (sshMatch) {
6872
return {
73+
hostname,
6974
protocol: 'SSH',
7075
repository: sshMatch[1]
7176
}
@@ -76,10 +81,10 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
7681
)
7782
}
7883

79-
export function getRemoteUrl(protocol: string, repository: string): string {
84+
export function getRemoteUrl(protocol: string, hostname: string, repository: string): string {
8085
return protocol == 'HTTPS'
81-
? `https://github.com/${repository}`
82-
: `git@github.com:${repository}.git`
86+
? `https://${hostname}/${repository}`
87+
: `git@${hostname}:${repository}.git`
8388
}
8489

8590
export function secondsSinceEpoch(): number {

0 commit comments

Comments
 (0)