Documentation
¶
Overview ¶
Package slugparse provides the canonical parser for source-code repository slugs. It is a leaf package with no dependencies on other internal packages and is consumed by both internal/ingest and internal/forge.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse extracts the canonical "owner/repo" slug from any of the following input forms:
- owner/repo
- github.com/owner/repo[.git]
- gitlab.com/owner/repo[.git]
- https://github.com/owner/repo[.git]
- https://gitlab.com/owner/repo[.git]
- http://github.com/owner/repo[.git]
- git@github.com:owner/repo[.git]
- git@gitlab.com:owner/repo[.git]
It returns an error for:
- Local path prefixes ("/", "./", "../")
- SSH inputs with an unknown host (security: rejects git@evil.com:…)
- Double-suffix inputs (owner/repo.git.git)
- Inputs with wrong segment count (owner alone, owner/repo/extra)
- Segments that don't match [A-Za-z0-9._-]+
Use ParseWithOptions for GitLab subgroup support.
func ParseWithOptions ¶
ParseWithOptions is like Parse but respects the given Options. With Options{AllowSubgroups: true}, paths of the form "group/sub1/sub2/repo" (2+ segments) are accepted and returned verbatim as the slug (e.g. "group/sub/repo"). The minimum of two segments is always required.
func SSHHostKind ¶
SSHHostKind returns the SSH host when input starts with the "git@" SSH prefix, e.g. "git@gitlab.com:group/repo.git" → "gitlab.com", true. Returns ("", false) for any other input form.
This is the single source of truth for SSH-host extraction; both DetectForge and stripPrefix rely on it so that extending knownSSHHosts propagates automatically.
Types ¶
type Options ¶
type Options struct {
// AllowSubgroups, when true, accepts GitLab-style paths with more than two
// segments (e.g. "group/subgroup/repo") and returns the full path as the
// slug. The strict two-segment contract is still enforced when this field
// is false (the default, and the behaviour of Parse).
AllowSubgroups bool
}
Options controls optional behaviour of ParseWithOptions.