v0.28.0 fca9155

ci_workflow.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain
4
5import (
6	"errors"
7	"fmt"
8	"path"
9	"strings"
10	"unicode"
11)
12
13// WorkflowDir is the only directory the workflows of a repository are read
14// from (ADR 0019: no ermite dialect).
15const WorkflowDir = ".github/workflows"
16
17// maxWorkflowFileName bounds the file name of a workflow, as a file name of
18// Git trees is bounded on the usual file systems.
19const maxWorkflowFileName = 255
20
21// ErrWorkflowDisabled is returned by the store when a run is created for a
22// workflow the repository disabled. It is checked in the very transaction that
23// creates the run, so no disable can slip in between a check and the creation.
24var ErrWorkflowDisabled = errors.New("workflow is disabled")
25
26// ParseWorkflowPath normalizes the name of a workflow file, as `gh workflow`
27// takes it: either its file name ("release.yml") or its path
28// (".github/workflows/release.yml"). It returns the canonical path, and
29// refuses every other spelling of it ("./.github/workflows/x.yml",
30// ".github/workflows//x.yml", ".github/workflows/sub/../x.yml"), so one file has
31// one key. Only the shape is checked, never whether the file exists: the state
32// of a workflow can be set on a repository that is empty or that does not hold
33// the file yet. A file in a subdirectory, a name that does not end in .yml or
34// .yaml, and a name with a control character or a backslash are ErrInvalid.
35func ParseWorkflowPath(s string) (string, error) {
36	s = strings.TrimSpace(s)
37	if s == "" {
38		return "", fmt.Errorf("%w: the workflow file is required", ErrInvalid)
39	}
40	if !strings.Contains(s, "/") {
41		s = WorkflowDir + "/" + s
42	}
43	name, ok := strings.CutPrefix(s, WorkflowDir+"/")
44	ext := strings.ToLower(path.Ext(name))
45	switch {
46	case !ok,
47		strings.Contains(name, "/"),
48		ext != ".yml" && ext != ".yaml",
49		strings.TrimSuffix(name, path.Ext(name)) == "",
50		len(name) > maxWorkflowFileName,
51		strings.ContainsFunc(name, func(r rune) bool { return unicode.IsControl(r) || r == '\\' }):
52		return "", fmt.Errorf("%w: %q is not a workflow file of %s (a file name or the path %s/<file>, ending in .yml or .yaml)", ErrInvalid, s, WorkflowDir, WorkflowDir)
53	}
54	return s, nil
55}

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 3

Tags 43

↑↓ moveenter openesc close