MCPcopy
hub / github.com/peter-evans/create-pull-request / parseGitRemote

Method parseGitRemote

src/git-config-helper.ts:82–120  ·  view source on GitHub ↗
(remoteUrl: string)

Source from the content-addressed store, hash-verified

80 }
81
82 static parseGitRemote(remoteUrl: string): GitRemote {
83 const httpsUrlPattern = new RegExp(
84 '^(https?)://(?:.+@)?(.+?)/(.+/.+?)(\\.git)?$',
85 'i'
86 )
87 const httpsMatch = remoteUrl.match(httpsUrlPattern)
88 if (httpsMatch) {
89 return {
90 hostname: httpsMatch[2],
91 protocol: 'HTTPS',
92 repository: httpsMatch[3]
93 }
94 }
95
96 const sshUrlPattern = new RegExp('^git@(.+?):(.+/.+)\\.git$', 'i')
97 const sshMatch = remoteUrl.match(sshUrlPattern)
98 if (sshMatch) {
99 return {
100 hostname: sshMatch[1],
101 protocol: 'SSH',
102 repository: sshMatch[2]
103 }
104 }
105
106 // Unauthenticated git protocol for integration tests only
107 const gitUrlPattern = new RegExp('^git://(.+?)/(.+/.+)\\.git$', 'i')
108 const gitMatch = remoteUrl.match(gitUrlPattern)
109 if (gitMatch) {
110 return {
111 hostname: gitMatch[1],
112 protocol: 'GIT',
113 repository: gitMatch[2]
114 }
115 }
116
117 throw new Error(
118 `The format of '${remoteUrl}' is not a valid GitHub repository URL`
119 )
120 }
121
122 async savePersistedAuth(): Promise<void> {
123 const serverUrl = new URL(`https://${this.getGitRemote().hostname}`)

Callers 2

getGitRemoteMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected