-
Notifications
You must be signed in to change notification settings - Fork 0
Simplify CLI: Accept URLs directly for indexing #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
richhankins
wants to merge
3
commits into
main
Choose a base branch
from
simplify-cli-arguments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { parseSourceUrl } from "./url-parser.js"; | ||
|
|
||
| describe("parseSourceUrl", () => { | ||
| describe("GitHub URLs", () => { | ||
| it("parses basic github.com URL", () => { | ||
| const result = parseSourceUrl("https://github.com/owner/repo"); | ||
| expect(result.type).toBe("github"); | ||
| expect(result.config).toEqual({ owner: "owner", repo: "repo", ref: "HEAD" }); | ||
| expect(result.defaultIndexName).toBe("repo"); | ||
| }); | ||
|
|
||
| it("parses GitHub URL with tree/branch", () => { | ||
| const result = parseSourceUrl("https://github.com/owner/repo/tree/main"); | ||
| expect(result.type).toBe("github"); | ||
| expect(result.config).toEqual({ owner: "owner", repo: "repo", ref: "main" }); | ||
| expect(result.defaultIndexName).toBe("repo"); | ||
| }); | ||
|
|
||
| it("parses GitHub URL with tree/feature/branch (slashes in branch name)", () => { | ||
| const result = parseSourceUrl("https://github.com/owner/repo/tree/feature/branch"); | ||
| expect(result.type).toBe("github"); | ||
| expect(result.config).toEqual({ owner: "owner", repo: "repo", ref: "feature/branch" }); | ||
| expect(result.defaultIndexName).toBe("repo"); | ||
| }); | ||
|
|
||
| it("parses GitHub URL with commit SHA", () => { | ||
| const result = parseSourceUrl("https://github.com/owner/repo/commit/abc123def456"); | ||
| expect(result.type).toBe("github"); | ||
| expect(result.config).toEqual({ owner: "owner", repo: "repo", ref: "abc123def456" }); | ||
| expect(result.defaultIndexName).toBe("repo"); | ||
| }); | ||
|
|
||
| it("throws on invalid GitHub URL without repo", () => { | ||
| expect(() => parseSourceUrl("https://github.com/owner")).toThrow("Invalid GitHub URL"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("GitLab URLs", () => { | ||
| it("parses basic gitlab.com URL", () => { | ||
| const result = parseSourceUrl("https://gitlab.com/group/project"); | ||
| expect(result.type).toBe("gitlab"); | ||
| expect(result.config).toEqual({ projectId: "group/project", ref: "HEAD", baseUrl: undefined }); | ||
| expect(result.defaultIndexName).toBe("project"); | ||
| }); | ||
|
|
||
| it("parses GitLab URL with subgroups", () => { | ||
| const result = parseSourceUrl("https://gitlab.com/group/subgroup/project"); | ||
| expect(result.type).toBe("gitlab"); | ||
| expect(result.config).toEqual({ | ||
| projectId: "group/subgroup/project", | ||
| ref: "HEAD", | ||
| baseUrl: undefined, | ||
| }); | ||
| expect(result.defaultIndexName).toBe("project"); | ||
| }); | ||
|
|
||
| it("parses GitLab URL with /-/tree/branch", () => { | ||
| const result = parseSourceUrl("https://gitlab.com/group/project/-/tree/main"); | ||
| expect(result.type).toBe("gitlab"); | ||
| expect(result.config).toEqual({ projectId: "group/project", ref: "main", baseUrl: undefined }); | ||
| expect(result.defaultIndexName).toBe("project"); | ||
| }); | ||
|
|
||
| it("parses GitLab URL with /-/tree/feature/branch", () => { | ||
| const result = parseSourceUrl("https://gitlab.com/group/project/-/tree/feature/branch"); | ||
| expect(result.type).toBe("gitlab"); | ||
| expect(result.config).toEqual({ | ||
| projectId: "group/project", | ||
| ref: "feature/branch", | ||
| baseUrl: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it("parses self-hosted GitLab URL", () => { | ||
| const result = parseSourceUrl("https://gitlab.mycompany.com/team/project"); | ||
| expect(result.type).toBe("gitlab"); | ||
| expect(result.config).toEqual({ | ||
| projectId: "team/project", | ||
| ref: "HEAD", | ||
| baseUrl: "https://gitlab.mycompany.com", | ||
| }); | ||
| expect(result.defaultIndexName).toBe("project"); | ||
| }); | ||
|
|
||
| it("throws on invalid GitLab URL", () => { | ||
| expect(() => parseSourceUrl("https://gitlab.com/group")).toThrow("Invalid GitLab URL"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Bitbucket URLs", () => { | ||
| it("parses basic bitbucket.org URL", () => { | ||
| const result = parseSourceUrl("https://bitbucket.org/workspace/repo"); | ||
| expect(result.type).toBe("bitbucket"); | ||
| expect(result.config).toEqual({ | ||
| workspace: "workspace", | ||
| repo: "repo", | ||
| ref: "HEAD", | ||
| baseUrl: undefined, | ||
| }); | ||
| expect(result.defaultIndexName).toBe("repo"); | ||
| }); | ||
|
|
||
| it("parses Bitbucket URL with /src/branch", () => { | ||
| const result = parseSourceUrl("https://bitbucket.org/workspace/repo/src/main"); | ||
| expect(result.type).toBe("bitbucket"); | ||
| expect(result.config).toEqual({ | ||
| workspace: "workspace", | ||
| repo: "repo", | ||
| ref: "main", | ||
| baseUrl: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it("parses Bitbucket URL with /branch/feature", () => { | ||
| const result = parseSourceUrl("https://bitbucket.org/workspace/repo/branch/feature"); | ||
| expect(result.type).toBe("bitbucket"); | ||
| expect(result.config).toEqual({ | ||
| workspace: "workspace", | ||
| repo: "repo", | ||
| ref: "feature", | ||
| baseUrl: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it("parses self-hosted Bitbucket URL", () => { | ||
| const result = parseSourceUrl("https://bitbucket.mycompany.com/workspace/repo"); | ||
| expect(result.type).toBe("bitbucket"); | ||
| expect(result.config).toEqual({ | ||
| workspace: "workspace", | ||
| repo: "repo", | ||
| ref: "HEAD", | ||
| baseUrl: "https://bitbucket.mycompany.com", | ||
| }); | ||
| }); | ||
|
|
||
| it("throws on invalid Bitbucket URL", () => { | ||
| expect(() => parseSourceUrl("https://bitbucket.org/workspace")).toThrow("Invalid Bitbucket URL"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Website URLs (fallback)", () => { | ||
| it("parses unknown URL as website", () => { | ||
| const result = parseSourceUrl("https://docs.example.com/api/v2"); | ||
| expect(result.type).toBe("website"); | ||
| expect(result.config).toEqual({ url: "https://docs.example.com/api/v2" }); | ||
| expect(result.defaultIndexName).toBe("docs.example.com"); | ||
| }); | ||
|
|
||
| it("uses hostname as default index name for website", () => { | ||
| const result = parseSourceUrl("https://react.dev/learn/thinking-in-react"); | ||
| expect(result.type).toBe("website"); | ||
| expect(result.defaultIndexName).toBe("react.dev"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Invalid URLs", () => { | ||
| it("throws on invalid URL format", () => { | ||
| expect(() => parseSourceUrl("not-a-url")).toThrow(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL auto-rewrite only triggers when the URL is the first argument after
index, soctxc index -i myidx https://…won’t be rewritten and will likely error. Is that limitation intentional, or should the rewrite scan forward for the first non-option arg?🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.