{"size": 1098, "ext": "js", "max_stars_repo_path": "connection/parser.js", "max_stars_repo_name": "venkat085/le-git-imate", "max_stars_repo_stars_event_min_datetime": "2021-11-03T16:35:53.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-03T16:35:53.000Z", "max_issues_repo_path": "connection/parser.js", "max_issues_repo_name": "le-git-imate/le-git-imate", "max_issues_repo_issues_event_min_datetime": "2019-08-14T22:18:40.000Z", "max_issues_repo_issues_event_max_datetime": "2020-06-18T17:07:01.000Z", "max_forks_repo_path": "connection/parser.js", "max_forks_repo_name": "venkat085/le-git-imate", "max_forks_repo_forks_event_min_datetime": "2019-07-22T19:43:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T22:10:34.000Z"}
{"max_stars_count": 1, "max_issues_count": 48, "max_forks_count": 5, "avg_line_length": 26.7804878049, "max_line_length": 86, "alphanum_fraction": 0.5892531876}
//Parse git-receive-pack response
function parseGetResponse(res, service) {
    var lines = res.toString('utf8').trim().split('\n')
    // Parse the header
    var resHead = lines.shift()
    if (!(resHead.toString('utf8').includes(`service=${service}`))) {
        throw new Error(
            `Expected '# service=${service}\\n' but got '${resHead.toString('utf8')}'`
        )
    }

    lines.pop()

    let [refLine, capLine] = lines[0].split('\0')
    var capabilities = capLine.split(' ')
    lines[0] = refLine;

    // Remove the caps from the first line
    const refs = new Map();
    // Get refs, TODO: get symlinks
    for (let line of lines) {
        let [ref, name] = line.split(' ')
            // Remove the length from the beginning
        if (ref.length > 40) ref = ref.slice(-40)
        refs.set(name, ref)
    }

    return {
        capabilities,
        refs
    }
}

// Parse the server's response
// TODO: interpret the response more precisely
var parsePostResponse = function(response) {
    if (response.includes('unpack ok'))
        return true;
    return false;
}
