mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
feat: support github server url for pushing to fork (#1315)
Co-authored-by: Kevin Zhu <kevin.zhu@sap.com>
This commit is contained in:
parent
d7db273d6c
commit
7e67080f47
2 changed files with 11 additions and 5 deletions
|
@ -74,6 +74,7 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||||
// Add a remote for the fork
|
// Add a remote for the fork
|
||||||
const remoteUrl = utils.getRemoteUrl(
|
const remoteUrl = utils.getRemoteUrl(
|
||||||
baseRemote.protocol,
|
baseRemote.protocol,
|
||||||
|
baseRemote.hostname,
|
||||||
branchRepository
|
branchRepository
|
||||||
)
|
)
|
||||||
await git.exec(['remote', 'add', 'fork', remoteUrl])
|
await git.exec(['remote', 'add', 'fork', remoteUrl])
|
||||||
|
|
15
src/utils.ts
15
src/utils.ts
|
@ -32,6 +32,7 @@ export function getRepoPath(relativePath?: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RemoteDetail {
|
interface RemoteDetail {
|
||||||
|
hostname: string
|
||||||
protocol: string
|
protocol: string
|
||||||
repository: string
|
repository: string
|
||||||
}
|
}
|
||||||
|
@ -46,18 +47,21 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
|
||||||
throw new Error('Could not parse GitHub Server name')
|
throw new Error('Could not parse GitHub Server name')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hostname = githubServerMatch[1]
|
||||||
|
|
||||||
const httpsUrlPattern = new RegExp(
|
const httpsUrlPattern = new RegExp(
|
||||||
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(\\.git)?$',
|
'^https?://.*@?' + hostname + '/(.+/.+?)(\\.git)?$',
|
||||||
'i'
|
'i'
|
||||||
)
|
)
|
||||||
const sshUrlPattern = new RegExp(
|
const sshUrlPattern = new RegExp(
|
||||||
'^git@' + githubServerMatch[1] + ':(.+/.+)\\.git$',
|
'^git@' + hostname + ':(.+/.+)\\.git$',
|
||||||
'i'
|
'i'
|
||||||
)
|
)
|
||||||
|
|
||||||
const httpsMatch = remoteUrl.match(httpsUrlPattern)
|
const httpsMatch = remoteUrl.match(httpsUrlPattern)
|
||||||
if (httpsMatch) {
|
if (httpsMatch) {
|
||||||
return {
|
return {
|
||||||
|
hostname,
|
||||||
protocol: 'HTTPS',
|
protocol: 'HTTPS',
|
||||||
repository: httpsMatch[1]
|
repository: httpsMatch[1]
|
||||||
}
|
}
|
||||||
|
@ -66,6 +70,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
|
||||||
const sshMatch = remoteUrl.match(sshUrlPattern)
|
const sshMatch = remoteUrl.match(sshUrlPattern)
|
||||||
if (sshMatch) {
|
if (sshMatch) {
|
||||||
return {
|
return {
|
||||||
|
hostname,
|
||||||
protocol: 'SSH',
|
protocol: 'SSH',
|
||||||
repository: sshMatch[1]
|
repository: sshMatch[1]
|
||||||
}
|
}
|
||||||
|
@ -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'
|
return protocol == 'HTTPS'
|
||||||
? `https://github.com/${repository}`
|
? `https://${hostname}/${repository}`
|
||||||
: `git@github.com:${repository}.git`
|
: `git@${hostname}:${repository}.git`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function secondsSinceEpoch(): number {
|
export function secondsSinceEpoch(): number {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue