Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/ingest-github/src/githubUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ export interface ParsedRepo {
/**
* Parses `https://github.com/{owner}/{repo}(/tree/{branch})?` → `{owner, repo, branch?}`.
*
* Also accepts `gitlab.com` URLs of the form
* `https://gitlab.com/{owner}/{repo}` so the runner can build a kube-v2
* `RepoLocation` for GitLab knowledges that route through this pipeline via
* an injected `SourceFactory`. The kernel `RepoLocation` only has a `github`
* provider variant today, so GitLab projects share the github path segment.
* Also accepts `gitlab.com` and `bitbucket.org` URLs of the form
* `https://gitlab.com/{owner}/{repo}` / `https://bitbucket.org/{workspace}/{repoSlug}`
* so the runner can build a kube-v2 `RepoLocation` for GitLab + Bitbucket
* knowledges that route through this pipeline via an injected
* `SourceFactory`. The kernel `RepoLocation` only has a `github` provider
* variant today, so non-GitHub projects share the github path segment.
* Subgroup gitlab URLs (`group/sub/project`) collapse to `{ owner: group,
* repo: sub }` here — downstream consumers that need the full namespace
* should derive it themselves; the GitLab source-factory does this.
* should derive it themselves; the GitLab / Bitbucket source-factories do this.
*/
export function parseGithubRepo(repoUrl: string): ParsedRepo | null {
if (!repoUrl) {
return null;
}
try {
const url = new URL(repoUrl);
if (!url.hostname.endsWith("github.com") && !url.hostname.endsWith("gitlab.com")) {
if (
!url.hostname.endsWith("github.com") &&
!url.hostname.endsWith("gitlab.com") &&
!url.hostname.endsWith("bitbucket.org")
) {
return null;
}
const segments = url.pathname.split("/").filter((s) => s.length > 0);
Expand Down
13 changes: 9 additions & 4 deletions packages/types/src/path-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ export function bytebellPathsFor(home: string, loc: RepoLocation): MetaPathsLayo
}

/**
* Pure URL parser for GitHub repo URLs. Extracts owner and repo segments,
* tolerating `.git` suffixes and `tree/branch` paths. Returns `null` on any
* input that isn't a GitHub-hosted URL.
* Pure URL parser for GitHub / GitLab / Bitbucket repo URLs. Extracts owner
* and repo segments, tolerating `.git` suffixes and `tree/branch` paths.
* Returns `null` on any input that isn't a github.com / gitlab.com /
* bitbucket.org URL.
*
* Duplicates the public `parseGithubRepo` from `@bb/ingest-github/githubUrl`
* deliberately — kernel-tier code can't import from Domain. The two
Expand All @@ -116,7 +117,11 @@ export function parseGithubOwnerRepo(repoUrl: string): { owner: string; repo: st
}
try {
const url = new URL(repoUrl);
if (!url.hostname.endsWith("github.com") && !url.hostname.endsWith("gitlab.com")) {
if (
!url.hostname.endsWith("github.com") &&
!url.hostname.endsWith("gitlab.com") &&
!url.hostname.endsWith("bitbucket.org")
) {
return null;
}
const segments = url.pathname.split("/").filter((s) => s.length > 0);
Expand Down
Loading