slugparse

package
v1.39.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

func Parse(input string) (string, error)

Parse extracts the canonical "owner/repo" slug from any of the following input forms:

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

func ParseWithOptions(input string, opts Options) (string, error)

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

func SSHHostKind(input string) (host string, ok bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL