"use strict";
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const get_contents_1 = __importDefault(require("./get-contents"));
const path_1 = require("path");
async function getPublicPathInfoGithub(url) {
    const segments = url.split("/");
    const githubOrg = segments[1];
    if (!githubOrg) {
        throw Error(`invalid url ${url} -- must include github organization`);
    }
    const githubRepo = segments[2];
    const relativePath = (0, path_1.join)(...segments.slice(3));
    if (!githubRepo) {
        // only getting the repos for a single org.
        const contents = await (0, get_contents_1.default)(githubOrg, "", []);
        const projectTitle = `GitHub Repositories owned by ${githubOrg}`;
        return {
            contents,
            relativePath,
            projectTitle,
            githubOrg,
        };
    }
    const contents = await (0, get_contents_1.default)(githubOrg, githubRepo, segments.slice(3));
    const projectTitle = `GitHub repository ${githubOrg} / ${githubRepo}`;
    return {
        contents,
        relativePath,
        projectTitle,
        githubOrg,
        githubRepo,
        url,
    };
}
exports.default = getPublicPathInfoGithub;
//# sourceMappingURL=get-public-path-info-github.js.map