v0.2.0 43088fd

urlorigin.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3// Package urlorigin gives the one canonical form of the origin of an http(s)
4// URL that the host and the executor both compare: the archive token of an
5// action goes only to the origin the host named, so the two sides must agree on
6// what "the same origin" means, whatever the spelling of the URL.
7package urlorigin
8
9import (
10	"net"
11	"net/url"
12	"strings"
13)
14
15// Canonical returns "scheme://host:port" for an absolute http or https URL: the
16// scheme and the host lower-cased, the default port (80, 443) filled in, an IPv6
17// host in brackets (net.JoinHostPort), so that "https://[::1]:8443/x" and
18// "https://[::1:8443]/x" (a different host, without a port) differ, and
19// "https://a.test" and "https://a.test:443" are the same. It returns "" for
20// anything else, including a URL with credentials, which never carries a token.
21func Canonical(raw string) string {
22	u, err := url.Parse(raw)
23	if err != nil || u.Host == "" || u.User != nil {
24		return ""
25	}
26	scheme := strings.ToLower(u.Scheme)
27	port, ok := effectivePort(scheme, u.Port())
28	if !ok || u.Hostname() == "" {
29		return ""
30	}
31	return scheme + "://" + net.JoinHostPort(strings.ToLower(u.Hostname()), port)
32}
33
34func effectivePort(scheme, port string) (string, bool) {
35	switch {
36	case port != "":
37		if scheme != "http" && scheme != "https" {
38			return "", false
39		}
40		return port, true
41	case scheme == "http":
42		return "80", true
43	case scheme == "https":
44		return "443", true
45	}
46	return "", false
47}
48
49// Prefix returns the origin as it is written at the start of a URL: the same
50// as Canonical without the default port, which is how a URL is built from it.
51func Prefix(raw string) string {
52	c := Canonical(raw)
53	switch {
54	case strings.HasPrefix(c, "http://") && strings.HasSuffix(c, ":80"):
55		return strings.TrimSuffix(c, ":80")
56	case strings.HasPrefix(c, "https://") && strings.HasSuffix(c, ":443"):
57		return strings.TrimSuffix(c, ":443")
58	}
59	return c
60}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 11

↑↓ moveenter openesc close