Skip to content

Commit 99ff50e

Browse files
committed
chore: Add @types/parse-github-url dependency and update getRepoSlug function for improved remote parsing
1 parent d73ddc1 commit 99ff50e

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"@types/node": "18.19.18",
116116
"@types/node-fetch": "^2.5.12",
117117
"@types/p-limit": "^2.0.0",
118+
"@types/parse-github-url": "^1.0.3",
118119
"@types/prettier": "^1.16.1",
119120
"@types/readline-sync": "^1.4.3",
120121
"@types/voca": "^1.4.0",

source/commands/init/get-repo-slug.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ export const getRepoSlug = () => {
1212
}
1313

1414
const configContent = fs.readFileSync(gitConfigPath, "utf8")
15-
1615
const parsedConfig = ini.parse(configContent)
16+
const remotes: Record<string, any> = {}
1717

18-
const config: Record<string, any> = {}
19-
20-
if (parsedConfig.remote) {
21-
for (const remoteName in parsedConfig.remote) {
22-
config[`remote "${remoteName}"`] = parsedConfig.remote[remoteName]
18+
for (const key in parsedConfig) {
19+
if (key.startsWith('remote "')) {
20+
const remoteName = key.substring(8, key.length - 1)
21+
remotes[remoteName] = parsedConfig[key]
2322
}
2423
}
2524

26-
const possibleRemotes = [config['remote "upstream"'], config['remote "origin"']].filter((f) => f)
25+
const possibleRemoteNames = ["upstream", "origin"]
26+
const possibleRemotes = possibleRemoteNames.map((name) => remotes[name]).filter((remote) => remote && remote.url)
27+
2728
if (possibleRemotes.length === 0) {
2829
return null
2930
}
30-
3131
const ghData = possibleRemotes.map((r) => parseGithubURL(r.url))
32-
return ghData.length ? ghData[0].repo : undefined
32+
return ghData.length && ghData[0] ? ghData[0].repo : undefined
3333
} catch (error) {
3434
console.error("Error reading git config:", error)
3535
return null

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,13 @@
20222022
dependencies:
20232023
p-limit "*"
20242024

2025+
"@types/parse-github-url@^1.0.3":
2026+
version "1.0.3"
2027+
resolved "https://registry.yarnpkg.com/@types/parse-github-url/-/parse-github-url-1.0.3.tgz#a097f26ae1993f1963d4031126dc7965707804aa"
2028+
integrity sha512-7sTbCVmSVzK/iAsHGIxoqiyAnqix9opZm68lOvaU6DBx9EQ9kHMSp0y7Criu2OCsZ9wDllEyCRU+LU4hPRxXUA==
2029+
dependencies:
2030+
"@types/node" "*"
2031+
20252032
"@types/parse-path@^7.0.0":
20262033
version "7.0.3"
20272034
resolved "https://registry.yarnpkg.com/@types/parse-path/-/parse-path-7.0.3.tgz#cec2da2834ab58eb2eb579122d9a1fc13bd7ef36"

0 commit comments

Comments
 (0)