Skip to content

Commit b829187

Browse files
authored
Merge pull request #1486 from kantivekariya/replace-parse-git-config
fix: Replace parse-git-config with ini + fs
2 parents da77ef1 + c6a0bb9 commit b829187

File tree

5 files changed

+54
-66
lines changed

5 files changed

+54
-66
lines changed
File renamed without changes.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"docs:cp_defs": "mkdir docs/docs_generate; cp source/danger.d.ts docs/docs_generate; cp node_modules/@octokit/rest/index.d.ts docs/docs_generate/github.d.ts",
7373
"docs": "yarn run docs:cp_defs; yarn typedoc --ignoreCompilerErrors --mode modules --json docs/js_ref_dsl_docs.json --includeDeclarations source",
7474
"dts-lint": "yarn run declarations && yarn dtslint types",
75-
"danger:prepush": "yarn build:fast; yarn test:fixtures; node distribution/commands/danger.js local --base main --dangerfile dangerfile.lite.ts"
75+
"danger:prepush": "yarn build:fast && yarn test:fixtures && node distribution/commands/danger.js local --base main --dangerfile dangerfile.lite.ts"
7676
},
7777
"repository": {
7878
"type": "git",
@@ -103,6 +103,7 @@
103103
"@types/async-retry": "^1.4.1",
104104
"@types/debug": "0.0.30",
105105
"@types/get-stdin": "^5.0.1",
106+
"@types/ini": "^4.1.1",
106107
"@types/jest": "^28.0.0",
107108
"@types/json5": "^2.2.0",
108109
"@types/jsonpointer": "^4.0.0",
@@ -114,6 +115,7 @@
114115
"@types/node": "18.19.18",
115116
"@types/node-fetch": "^2.5.12",
116117
"@types/p-limit": "^2.0.0",
118+
"@types/parse-github-url": "^1.0.3",
117119
"@types/prettier": "^1.16.1",
118120
"@types/readline-sync": "^1.4.3",
119121
"@types/voca": "^1.4.0",
@@ -156,6 +158,7 @@
156158
"http-proxy-agent": "^5.0.0",
157159
"https-proxy-agent": "^5.0.1",
158160
"hyperlinker": "^1.0.0",
161+
"ini": "^5.0.0",
159162
"json5": "^2.2.3",
160163
"jsonpointer": "^5.0.0",
161164
"jsonwebtoken": "^9.0.0",
@@ -172,7 +175,6 @@
172175
"override-require": "^1.1.1",
173176
"p-limit": "^2.1.0",
174177
"parse-diff": "^0.7.0",
175-
"parse-git-config": "^2.0.3",
176178
"parse-github-url": "^1.0.2",
177179
"parse-link-header": "^2.0.0",
178180
"pinpoint": "^1.1.0",
@@ -185,7 +187,7 @@
185187
"husky": {
186188
"hooks": {
187189
"pre-commit": "lint-staged",
188-
"pre-push": "yarn build; yarn danger:prepush"
190+
"pre-push": "yarn build && yarn danger:prepush"
189191
}
190192
}
191193
}

source/ambient.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ declare module "supports-hyperlinks"
3939
// export default function(code: string, filename?: string, opts?: Partial<RequireOptions>): any
4040
// }
4141

42-
declare module "parse-git-config"
4342
declare module "parse-github-url"
4443
// Basically does one thing
4544
declare module "override-require"

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
import parseGitConfig from "parse-git-config"
1+
import fs from "fs"
2+
import path from "path"
3+
import ini from "ini"
24
import parseGithubURL from "parse-github-url"
35

46
export const getRepoSlug = () => {
5-
const config = parseGitConfig.sync()
6-
const possibleRemotes = [config['remote "upstream"'], config['remote "origin"']].filter((f) => f)
7-
if (possibleRemotes.length === 0) {
7+
try {
8+
const gitConfigPath = path.join(process.cwd(), ".git", "config")
9+
10+
if (!fs.existsSync(gitConfigPath)) {
11+
return null
12+
}
13+
14+
const configContent = fs.readFileSync(gitConfigPath, "utf8")
15+
const parsedConfig = ini.parse(configContent)
16+
const remotes: Record<string, any> = {}
17+
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]
22+
}
23+
}
24+
25+
const possibleRemoteNames = ["upstream", "origin"]
26+
const possibleRemotes = possibleRemoteNames.map((name) => remotes[name]).filter((remote) => remote && remote.url)
27+
28+
if (possibleRemotes.length === 0) {
29+
return null
30+
}
31+
const ghData = possibleRemotes.map((r) => parseGithubURL(r.url))
32+
return ghData.length && ghData[0] ? ghData[0].repo : undefined
33+
} catch (error) {
34+
console.error("Error reading git config:", error)
835
return null
936
}
10-
11-
const ghData = possibleRemotes.map((r) => parseGithubURL(r.url))
12-
return ghData.length ? ghData[0].repo : undefined
1337
}

yarn.lock

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,11 @@
18731873
resolved "https://registry.yarnpkg.com/@types/highlight.js/-/highlight.js-9.1.8.tgz#d227f18bcb8f3f187e16965f2444859a04689758"
18741874
integrity sha512-dPqwDerUWRYT5Ek6ozB/Hbwrm876WaRZNmXwE+uCTJlGfZlTBF3ubPAAd0hwjoO3ELBhsdL0NAXGoiKHIeTu3A==
18751875

1876+
"@types/ini@^4.1.1":
1877+
version "4.1.1"
1878+
resolved "https://registry.yarnpkg.com/@types/ini/-/ini-4.1.1.tgz#6984664a8cc74c3348f4049d0bf2b1ab2d061ca3"
1879+
integrity sha512-MIyNUZipBTbyUNnhvuXJTY7B6qNI78meck9Jbv3wk0OgNwRyOOVEKDutAkOs1snB/tx0FafyR6/SN4Ps0hZPeg==
1880+
18761881
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
18771882
version "2.0.6"
18781883
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7"
@@ -2017,6 +2022,13 @@
20172022
dependencies:
20182023
p-limit "*"
20192024

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+
20202032
"@types/parse-path@^7.0.0":
20212033
version "7.0.3"
20222034
resolved "https://registry.yarnpkg.com/@types/parse-path/-/parse-path-7.0.3.tgz#cec2da2834ab58eb2eb579122d9a1fc13bd7ef36"
@@ -3651,13 +3663,6 @@ expand-template@^2.0.3:
36513663
resolved "https://registry.yarnpkg.com/expand-template/-/expand-template-2.0.3.tgz#6e14b3fcee0f3a6340ecb57d2e8918692052a47c"
36523664
integrity sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==
36533665

3654-
expand-tilde@^2.0.2:
3655-
version "2.0.2"
3656-
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
3657-
integrity sha512-A5EmesHW6rfnZ9ysHQjPdJRni0SRar0tjtG5MNtm9n5TUvsYU8oozprtRD4AqHxcZWWlVuAmQo2nWKfN9oyjTw==
3658-
dependencies:
3659-
homedir-polyfill "^1.0.1"
3660-
36613666
expect@^28.0.0, expect@^28.1.3:
36623667
version "28.1.3"
36633668
resolved "https://registry.yarnpkg.com/expect/-/expect-28.1.3.tgz#90a7c1a124f1824133dd4533cce2d2bdcb6603ec"
@@ -3669,13 +3674,6 @@ expect@^28.0.0, expect@^28.1.3:
36693674
jest-message-util "^28.1.3"
36703675
jest-util "^28.1.3"
36713676

3672-
extend-shallow@^2.0.1:
3673-
version "2.0.1"
3674-
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f"
3675-
integrity sha512-zCnTtlxNoAiDc3gqY2aYAWFx7XWWiasuF2K8Me5WbN8otHKTUKBwjPtNpRs/rbUZm7KxWAaNj7P1a/p52GbVug==
3676-
dependencies:
3677-
is-extendable "^0.1.0"
3678-
36793677
external-editor@^3.1.0:
36803678
version "3.1.0"
36813679
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495"
@@ -3845,11 +3843,6 @@ fs-constants@^1.0.0:
38453843
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
38463844
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
38473845

3848-
fs-exists-sync@^0.1.0:
3849-
version "0.1.0"
3850-
resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add"
3851-
integrity sha512-cR/vflFyPZtrN6b38ZyWxpWdhlXrzZEBawlpBQMq7033xVY7/kg0GDMBK5jg8lDYQckdJ5x/YC88lM3C7VMsLg==
3852-
38533846
fs-extra@^4.0.0:
38543847
version "4.0.3"
38553848
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
@@ -3993,15 +3986,6 @@ get-uri@^6.0.1:
39933986
data-uri-to-buffer "^6.0.2"
39943987
debug "^4.3.4"
39953988

3996-
git-config-path@^1.0.1:
3997-
version "1.0.1"
3998-
resolved "https://registry.yarnpkg.com/git-config-path/-/git-config-path-1.0.1.tgz#6d33f7ed63db0d0e118131503bab3aca47d54664"
3999-
integrity sha512-KcJ2dlrrP5DbBnYIZ2nlikALfRhKzNSX0stvv3ImJ+fvC4hXKoV+U+74SV0upg+jlQZbrtQzc0bu6/Zh+7aQbg==
4000-
dependencies:
4001-
extend-shallow "^2.0.1"
4002-
fs-exists-sync "^0.1.0"
4003-
homedir-polyfill "^1.0.0"
4004-
40053989
git-up@^8.0.0:
40063990
version "8.0.1"
40073991
resolved "https://registry.yarnpkg.com/git-up/-/git-up-8.0.1.tgz#2a82cfbc77b5eb04074ab1e48593911981654fc7"
@@ -4174,13 +4158,6 @@ highlight.js@^9.0.0:
41744158
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.5.tgz#d18a359867f378c138d6819edfc2a8acd5f29825"
41754159
integrity sha512-a5bFyofd/BHCX52/8i8uJkjr9DYwXIPnM/plwI6W7ezItLGqzt7X2G2nXuYSfsIJdkwwj/g9DG1LkcGJI/dDoA==
41764160

4177-
homedir-polyfill@^1.0.0, homedir-polyfill@^1.0.1:
4178-
version "1.0.3"
4179-
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz#743298cef4e5af3e194161fbadcc2151d3a058e8"
4180-
integrity sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==
4181-
dependencies:
4182-
parse-passwd "^1.0.0"
4183-
41844161
hosted-git-info@^2.1.4:
41854162
version "2.8.9"
41864163
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
@@ -4334,11 +4311,16 @@ [email protected]:
43344311
resolved "https://registry.yarnpkg.com/ini/-/ini-4.1.1.tgz#d95b3d843b1e906e56d6747d5447904ff50ce7a1"
43354312
integrity sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==
43364313

4337-
ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
4314+
ini@^1.3.4, ini@~1.3.0:
43384315
version "1.3.8"
43394316
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
43404317
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
43414318

4319+
ini@^5.0.0:
4320+
version "5.0.0"
4321+
resolved "https://registry.yarnpkg.com/ini/-/ini-5.0.0.tgz#a7a4615339843d9a8ccc2d85c9d81cf93ffbc638"
4322+
integrity sha512-+N0ngpO3e7cRUWOJAS7qw0IZIVc6XPrW4MlFBdD066F2L4k1L6ker3hLqSq7iXxU5tgS4WGkIUElWn5vogAEnw==
4323+
43424324
43434325
version "12.3.0"
43444326
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-12.3.0.tgz#c5142f49362f1347aa49a18e652db460f14092e6"
@@ -4416,11 +4398,6 @@ is-docker@^3.0.0:
44164398
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-3.0.0.tgz#90093aa3106277d8a77a5910dbae71747e15a200"
44174399
integrity sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==
44184400

4419-
is-extendable@^0.1.0:
4420-
version "0.1.1"
4421-
resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89"
4422-
integrity sha512-5BMULNob1vgFX6EjQw5izWDxrecWK9AM72rugNr0TFldMOi0fj6Jk+zeKIt0xGj4cEfQIJth4w3OKWOJ4f+AFw==
4423-
44244401
is-extglob@^2.1.1:
44254402
version "2.1.1"
44264403
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
@@ -5930,15 +5907,6 @@ parse-diff@^0.7.0:
59305907
resolved "https://registry.yarnpkg.com/parse-diff/-/parse-diff-0.7.1.tgz#9b7a2451c3725baf2c87c831ba192d40ee2237d4"
59315908
integrity sha512-1j3l8IKcy4yRK2W4o9EYvJLSzpAVwz4DXqCewYyx2vEwk2gcf3DBPqc8Fj4XV3K33OYJ08A8fWwyu/ykD/HUSg==
59325909

5933-
parse-git-config@^2.0.3:
5934-
version "2.0.3"
5935-
resolved "https://registry.yarnpkg.com/parse-git-config/-/parse-git-config-2.0.3.tgz#6fb840d4a956e28b971c97b33a5deb73a6d5b6bb"
5936-
integrity sha512-Js7ueMZOVSZ3tP8C7E3KZiHv6QQl7lnJ+OkbxoaFazzSa2KyEHqApfGbU3XboUgUnq4ZuUmskUpYKTNx01fm5A==
5937-
dependencies:
5938-
expand-tilde "^2.0.2"
5939-
git-config-path "^1.0.1"
5940-
ini "^1.3.5"
5941-
59425910
parse-github-url@^1.0.2:
59435911
version "1.0.3"
59445912
resolved "https://registry.yarnpkg.com/parse-github-url/-/parse-github-url-1.0.3.tgz#2ab55642c8685b63fbe2a196f5abe4ae9bd68abc"
@@ -5994,11 +5962,6 @@ parse-ms@^4.0.0:
59945962
resolved "https://registry.yarnpkg.com/parse-ms/-/parse-ms-4.0.0.tgz#c0c058edd47c2a590151a718990533fd62803df4"
59955963
integrity sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==
59965964

5997-
parse-passwd@^1.0.0:
5998-
version "1.0.0"
5999-
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
6000-
integrity sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==
6001-
60025965
parse-path@^7.0.0:
60035966
version "7.0.1"
60045967
resolved "https://registry.yarnpkg.com/parse-path/-/parse-path-7.0.1.tgz#ae548cd36315fd8881a3610eae99fa08123ee0e2"

0 commit comments

Comments
 (0)