CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/share/proxy/get-public-path-info-github.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import getContents from "./get-contents";
7
import { join } from "path";
8
9
export default async function getPublicPathInfoGithub(url: string) {
10
const segments = url.split("/");
11
const githubOrg = segments[1];
12
if (!githubOrg) {
13
throw Error(`invalid url ${url} -- must include github organization`);
14
}
15
const githubRepo = segments[2];
16
const relativePath = join(...segments.slice(3));
17
18
if (!githubRepo) {
19
// only getting the repos for a single org.
20
const contents = await getContents(githubOrg, "", []);
21
const projectTitle = `GitHub Repositories owned by ${githubOrg}`;
22
23
return {
24
contents,
25
relativePath,
26
projectTitle,
27
githubOrg,
28
};
29
}
30
31
const contents = await getContents(githubOrg, githubRepo, segments.slice(3));
32
const projectTitle = `GitHub repository ${githubOrg} / ${githubRepo}`;
33
34
return {
35
contents,
36
relativePath,
37
projectTitle,
38
githubOrg,
39
githubRepo,
40
url,
41
};
42
}
43
44