MCPcopy
hub / github.com/desktop/desktop / parseCredential

Function parseCredential

app/src/lib/git/credential.ts:3–36  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

1import { exec as git } from 'dugite'
2
3export const parseCredential = (value: string) => {
4 const cred = new Map<string, string>()
5
6 // The credential helper protocol is a simple key=value format but some of its
7 // keys are actually arrays which are represented as multiple key[] entries.
8 // Since we're currently storing credentials as a Map we need to handle this
9 // and expand multiple key[] entries into a key[0], key[1]... key[n] sequence.
10 // We then remove the number from the key when we're formatting the credential
11 for (const line of value.split(/\r?\n/)) {
12 const eqIx = line.indexOf('=')
13 if (eqIx === -1) {
14 continue
15 }
16
17 const k = line.slice(0, eqIx)
18 const v = line.slice(eqIx + 1)
19
20 if (k.endsWith('[]')) {
21 let i = 0
22 let newKey
23
24 do {
25 newKey = `${k.slice(0, -2)}[${i}]`
26 i++
27 } while (cred.has(newKey))
28
29 cred.set(newKey, v)
30 } else {
31 cred.set(k, v)
32 }
33 }
34
35 return cred
36}
37
38export const formatCredential = (credential: Map<string, string>) => {
39 const lines = []

Callers 3

credential-test.tsFile · 0.90
execFunction · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected