route

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package route holds the Githome web front's URL-space rules: the reserved top-level names that a user or organization login may not take, and the ref-versus-path split that the tree and blob URLs need. These are pure functions with no dependency on the router or the domain, so the route fidelity oracle tests them directly. See implementation/02 and implementation/07.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountSettings

func AccountSettings() string

AccountSettings is the account settings root, /settings. It redirects to the first backed section so a bookmark of the bare root keeps working.

func Appearance

func Appearance() string

Appearance is the account appearance preference, /settings/appearance, where a viewer picks their color mode and the light and dark themes. It is the one account section Githome backs, since the preference rides cookies the color-mode middleware already reads.

func Blob

func Blob(owner, name, ref, path string) string

Blob is a file at a ref, /{owner}/{repo}/blob/{ref}/{path}.

func Branches

func Branches(owner, name string) string

Branches is the branch overview, /{owner}/{repo}/branches.

func Checks

func Checks(owner, name, ref string) string

Checks is the commit checks page, /{owner}/{repo}/checks/{ref}. ref is a branch, tag, or sha; its segments are escaped and rejoined with literal slashes so a branch with slashes round-trips through the same ref split the code views use.

func CommentDelete

func CommentDelete(owner, name string, number, commentID int64) string

CommentDelete is the delete POST target for a comment, /{owner}/{repo}/issues/{number}/comments/{id}/delete (a POST, since an HTML form cannot issue DELETE without JavaScript).

func CommentEdit

func CommentEdit(owner, name string, number, commentID int64) string

CommentEdit is the edit POST target for a comment, /{owner}/{repo}/issues/{number}/comments/{id}.

func CommentReactions

func CommentReactions(owner, name string, number, commentID int64) string

CommentReactions is the reaction-toggle POST target for a comment, /{owner}/{repo}/issues/{number}/comments/{id}/reactions.

func Commits

func Commits(owner, name, ref, path string) string

Commits is the history view, /{owner}/{repo}/commits/{ref}/{path}. The path is an optional history filter, so an empty path lists the whole ref history.

func Find

func Find(owner, name, ref string) string

Find is the file finder at a ref, /{owner}/{repo}/find/{ref}.

func FirstSegment

func FirstSegment(p string) (head, rest string)

FirstSegment returns the first path segment of p and the remainder, both without leading or trailing slashes. It is the small helper the top-level dispatcher uses to peel "/{owner}/..." without allocating a full split when only the head matters.

func IsReservedTop

func IsReservedTop(name string) bool

IsReservedTop reports whether name is a reserved first path segment. The check is case-insensitive because logins are compared case-insensitively, so a reserved name cannot be taken by changing case.

func Issue

func Issue(owner, name string, number int64) string

Issue is one issue's detail page, /{owner}/{repo}/issues/{number}.

func IssueComment

func IssueComment(owner, name string, number, commentID int64) string

IssueComment is the permalink to a comment on an issue, /{owner}/{repo}/issues/{number}#issuecomment-{id}. The fragment is what the no-JS comment POST redirects to so a reload lands on the appended comment.

func IssueComments

func IssueComments(owner, name string, number int64) string

IssueComments is the new-comment POST target, /{owner}/{repo}/issues/{number}/comments.

func IssueEdit

func IssueEdit(owner, name string, number int64) string

IssueEdit is the sidebar edit POST target, /{owner}/{repo}/issues/{number}/edit, which replaces the labels, assignees, or milestone through the EditIssue patch.

func IssueReactions

func IssueReactions(owner, name string, number int64) string

IssueReactions is the reaction-toggle POST target for the issue body, /{owner}/{repo}/issues/{number}/reactions. The form carries the reaction content.

func IssueState

func IssueState(owner, name string, number int64) string

IssueState is the close/reopen POST target, /{owner}/{repo}/issues/{number}/state. The form carries the target state and an optional comment body so a viewer can close with a comment in one submit.

func IssueTitle

func IssueTitle(owner, name string, number int64) string

IssueTitle is the edit-title POST target, /{owner}/{repo}/issues/{number}/title.

func Issues

func Issues(owner, name, rawQuery string) string

Issues is the issues index, /{owner}/{repo}/issues. The optional rawQuery is the already-encoded ?q=/?page= filter string; an empty rawQuery yields the bare index URL the default-filter view canonicalizes to.

func IssuesQuery

func IssuesQuery(owner, name, q string) string

IssuesQuery builds the index URL for a literal ?q= filter value, encoding the query string itself so a value with spaces or quotes stays a single q parameter. It is the canonical target the filter tabs and label chips link to.

func NewIssue

func NewIssue(owner, name string) string

NewIssue is the blank new-issue form, /{owner}/{repo}/issues/new.

func Profile

func Profile(login string) string

Profile is a user or organization profile, /{owner}. It is the overview tab by default; the repositories tab adds the ?tab= facet through ProfileTab.

func ProfileTab

func ProfileTab(login, tab string) string

ProfileTab is a profile at a named tab, /{owner}?tab={tab}. The overview tab is the bare profile with no query, so passing "overview" (or an empty tab) yields the canonical URL rather than a redundant ?tab=overview.

func Pull

func Pull(owner, name string, number int64) string

Pull is the pull-request Conversation tab, /{owner}/{repo}/pull/{number}, the canonical PR page the four tabs hang off.

func PullComment

func PullComment(owner, name string, number, commentID int64) string

PullComment is the permalink to a comment on a PR's Conversation timeline, /{owner}/{repo}/pull/{number}#issuecomment-{id}. A PR shares the issue number space, so its conversation comments carry the same issuecomment anchor the issues timeline uses; the no-JS comment POST redirects here.

func PullComments

func PullComments(owner, name string, number int64) string

PullComments is the new-comment POST target on the Conversation tab, /{owner}/{repo}/pull/{number}/comments.

func PullCommits

func PullCommits(owner, name string, number int64) string

PullCommits is the Commits tab, /{owner}/{repo}/pull/{number}/commits.

func PullFiles

func PullFiles(owner, name string, number int64) string

PullFiles is the Files-changed tab, /{owner}/{repo}/pull/{number}/files, the code-review surface where the shared diff component renders.

func PullMerge

func PullMerge(owner, name string, number int64) string

PullMerge is the merge POST target, /{owner}/{repo}/pull/{number}/merge. The form carries the merge method, the optional commit title and message, and the expected head SHA for optimistic concurrency.

func PullMergeBox

func PullMergeBox(owner, name string, number int64) string

PullMergeBox is the merge-box poll fragment GET target, /{owner}/{repo}/pull/{number}/partials/merge-box. While the box is computing mergeability the component re-fetches this on a backoff; with JS off it is just the same partial the full page already shows.

func PullReviewComment

func PullReviewComment(owner, name string, number, commentID int64) string

PullReviewComment is the permalink to an inline review comment on the Files tab, /{owner}/{repo}/pull/{number}/files#discussion_r{id}.

func PullReviewComments

func PullReviewComments(owner, name string, number int64) string

PullReviewComments is the new-inline-comment POST target, /{owner}/{repo}/pull/{number}/review-comments. The form carries the anchor (path, side, line) and the head commit id the comment pins to; the domain validates the anchor against that commit's diff.

func PullReviewReply

func PullReviewReply(owner, name string, number, rootID int64) string

PullReviewReply is the reply POST target for an existing thread, /{owner}/{repo}/pull/{number}/review-comments/{root}/replies, where root is the thread's first comment.

func PullReviewSummary

func PullReviewSummary(owner, name string, number, reviewID int64) string

PullReviewSummary is the permalink to a submitted review in the Conversation timeline, /{owner}/{repo}/pull/{number}#pullrequestreview-{id}.

func PullReviewThreadResolve

func PullReviewThreadResolve(owner, name string, number, rootID int64) string

PullReviewThreadResolve is the resolve/unresolve toggle POST target for a thread, /{owner}/{repo}/pull/{number}/review-threads/{root}/resolve. The handler reads the thread's current state and flips it, so the one endpoint resolves and unresolves.

func PullReviews

func PullReviews(owner, name string, number int64) string

PullReviews is the submit-a-review POST target, /{owner}/{repo}/pull/{number}/reviews. The form carries the verdict event (approve, request changes, comment) and an optional body.

func PullState

func PullState(owner, name string, number int64) string

PullState is the close/reopen POST target on the Conversation tab, /{owner}/{repo}/pull/{number}/state. It is the PR's own state toggle rather than the issue's, so closing or reopening a pull request lands back on the PR page, not the issue view of the same number.

func Pulls

func Pulls(owner, name, rawQuery string) string

Pulls is the pull-request index, /{owner}/{repo}/pulls. The optional rawQuery is the already-encoded ?q=/?page= filter string; an empty rawQuery yields the bare index URL the default filter canonicalizes to.

func PullsQuery

func PullsQuery(owner, name, q string) string

PullsQuery builds the index URL for a literal ?q= filter value, encoding the query string itself so a value with spaces or quotes stays a single q parameter. It is the canonical target the state tabs link to.

func Raw

func Raw(owner, name, ref, path string) string

Raw is the raw bytes of a file at a ref, /{owner}/{repo}/raw/{ref}/{path}.

func Repo

func Repo(owner, name string) string

Repo is the repository home, /{owner}/{repo}.

func RepoHook

func RepoHook(owner, name string, hookID int64) string

RepoHook is one webhook's edit page, /{owner}/{repo}/settings/hooks/{hook}, keyed by its public id.

func RepoHookDelete

func RepoHookDelete(owner, name string, hookID int64) string

RepoHookDelete is the delete-webhook POST target, /{owner}/{repo}/settings/hooks/{hook}/delete. Deleting is a POST, never a GET, so a crawler or a prefetch cannot remove a hook.

func RepoHookDelivery

func RepoHookDelivery(owner, name string, hookID, deliveryID int64) string

RepoHookDelivery is one recorded delivery's detail page, /{owner}/{repo}/settings/hooks/{hook}/deliveries/{delivery}.

func RepoHookNew

func RepoHookNew(owner, name string) string

RepoHookNew is the new-webhook form, /{owner}/{repo}/settings/hooks/new. It is a literal segment registered before the {hook} id route, so "new" is never read as an id.

func RepoHookRedeliver

func RepoHookRedeliver(owner, name string, hookID, deliveryID int64) string

RepoHookRedeliver is the replay-delivery POST target, /{owner}/{repo}/settings/hooks/{hook}/deliveries/{delivery}/redeliver.

func RepoHooks

func RepoHooks(owner, name string) string

RepoHooks is a repository's webhooks list, /{owner}/{repo}/settings/hooks.

func RepoSearch

func RepoSearch(owner, name, rawQuery string) string

RepoSearch is the in-repo results page, /{owner}/{repo}/search. The repo scope is implicit in the path, so the builder injects repo:{owner}/{name} before it runs the query; rawQuery carries only the viewer's own ?q= and the facets.

func RepoSettings

func RepoSettings(owner, name string) string

RepoSettings is a repository's settings root, /{owner}/{repo}/settings. It redirects to the first backed section (the webhooks list).

func ReservedTopNames

func ReservedTopNames() []string

ReservedTopNames returns the reserved names in no guaranteed order, for tests and for an admin tool that validates a requested login.

func Search(rawQuery string) string

Search is the global results page, /search. rawQuery is the already-encoded ?q=/?type=/?sort= string; an empty rawQuery yields the bare search landing.

func SplitRefPath

func SplitRefPath(tail string, exists func(ref string) bool) (ref, path string, ok bool)

SplitRefPath separates a "<ref>/<path>" tail into its git ref and the file path within that ref. A ref can contain slashes (refs/heads/feature/x, or a branch named release/1.0), so the tail is ambiguous on its own: "main/cmd/foo" could be ref "main" path "cmd/foo", or a branch "main/cmd" path "foo". Git resolves this by preferring the longest leading segment sequence that names an existing ref. exists reports whether a candidate ref resolves; the caller backs it with the repository's ref set (and the commit-ish forms it accepts, such as a full or abbreviated SHA).

It tries the whole tail as a ref first (a path-less ref URL), then peels one trailing segment at a time into the path. ok is false when no leading sequence names a ref, which the handler renders as a 404. See implementation/07 section 4.

func Tags

func Tags(owner, name string) string

Tags is the tag overview, /{owner}/{repo}/tags.

func Tree

func Tree(owner, name, ref, path string) string

Tree is a directory at a ref, /{owner}/{repo}/tree/{ref}/{path}. An empty path addresses the ref root. The ref and each path segment are escaped, but the slashes between them stay literal so the longest-ref split (SplitRefPath) sees the same boundaries the builder wrote.

Types

type RefKind

type RefKind int

RefKind names which code-browsing view a URL addresses. The ref picker keeps a viewer on the same kind when they switch refs (a tree stays a tree, a blob stays a blob), so the kind travels with the resolved ref. See implementation/07 section 10.3.

const (
	// KindTree is a directory listing under /tree.
	KindTree RefKind = iota
	// KindBlob is a single file under /blob.
	KindBlob
	// KindCommits is the history view under /commits.
	KindCommits
	// KindRaw is the raw byte view under /raw.
	KindRaw
)

Jump to

Keyboard shortcuts

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