Skip to content

Commit 4e5df87

Browse files
committed
refactor: use URL object for more robust GitHub URL parsing
1 parent bf2b3ba commit 4e5df87

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/ui/modules/urlExport.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,27 @@ const urlExport = (parent, exportSettings: urlExportSettings, requestBody: urlEx
126126
}
127127

128128
if (exportSettings.authType === config.key.authType.githubCommit) {
129+
let owner: string, repo: string
130+
131+
if (exportSettings.url.includes('github.com')) {
132+
const urlParts = exportSettings.url.split('/')
133+
const reposIndex = urlParts.indexOf('repos')
134+
if (reposIndex !== -1 && urlParts.length > reposIndex + 2) {
135+
owner = urlParts[reposIndex + 1]
136+
repo = urlParts[reposIndex + 2]
137+
} else {
138+
// Try to parse from github.com/owner/repo format
139+
owner = urlParts[urlParts.length - 2]
140+
repo = urlParts[urlParts.length - 1]
141+
}
142+
} else {
143+
// Format: owner/repo
144+
[owner, repo] = exportSettings.url.split('/')
145+
}
146+
129147
const githubRepo = new GithubRepository({
130-
owner: exportSettings.url.split('/')[3],
131-
repo: exportSettings.url.split('/')[4],
148+
owner,
149+
repo,
132150
token: exportSettings.accessToken
133151
})
134152
githubRepo.upload(requestBody, exportSettings, {

0 commit comments

Comments
 (0)