Documentation
¶
Overview ¶
Package render turns the server's model into the readable half of a tool result, and prepares text other people wrote before anything shows it (docs/architecture.md §4.1, §4.8).
The preparation is the part that matters for safety: hidden text is removed and counted, links show where they go, long text is cut at a budget that is stated, and everything someone else wrote is rendered inside a boundary whose token is drawn per call, so the content cannot close it.
Index ¶
- Constants
- func ApprovalWrite(w model.ApprovalWrite, _ Boundary) string
- func Artifact(a model.Artifact, bd Boundary) string
- func Artifacts(l model.Artifacts, _ Boundary) string
- func AutoMergeCancel(w model.AutoMergeCancel, _ Boundary) string
- func Blame(bl model.Blame, bd Boundary) string
- func Boards(l model.Boards, bd Boundary) string
- func BranchDelete(w model.BranchDelete, _ Boundary) string
- func BranchWrite(w model.BranchWrite, _ Boundary) string
- func Branches(l model.Branches, bd Boundary) string
- func Code(s string) (string, int)
- func CommentDelete(w model.CommentDelete, _ Boundary) string
- func CommentUpdate(w model.CommentUpdate, _ Boundary) string
- func CommentWrite(w model.CommentWrite, _ Boundary) string
- func Commit(c model.Commit, bd Boundary) string
- func CommitWrite(w model.CommitWrite, _ Boundary) string
- func Commits(l model.Commits, bd Boundary) string
- func Compare(c model.Compare, bd Boundary) string
- func ContentType(b []byte) string
- func Cut(text string, offset, budget int) (string, model.Budget)
- func Deployments(l model.Deployments, _ Boundary) string
- func DiscussionWrite(w model.DiscussionWrite, _ Boundary) string
- func Discussions(d model.Discussions, bd Boundary) string
- func DraftDelete(w model.DraftDelete, _ Boundary) string
- func DraftNotes(d model.DraftNotes, bd Boundary) string
- func DraftPublish(w model.DraftPublish, bd Boundary) string
- func DraftUpdate(w model.DraftUpdate, _ Boundary) string
- func Environments(l model.Environments, _ Boundary) string
- func Events(l model.Events, bd Boundary) string
- func File(f model.File, bd Boundary) string
- func Ident(s string) string
- func Invisible(s string) []rune
- func IsBinary(b []byte) bool
- func Issue(is model.Issue, bd Boundary) string
- func IssueLinkWrite(w model.IssueLinkWrite, _ Boundary) string
- func IssueMove(w model.IssueMove, _ Boundary) string
- func IssueWrite(w model.IssueWrite, _ Boundary) string
- func ItemEvents(l model.ItemEvents, bd Boundary) string
- func ItemList(l model.ItemList, noun string, bd Boundary) string
- func JobLog(l model.JobLog, bd Boundary) string
- func JobWrite(w model.JobWrite, _ Boundary) string
- func Jobs(l model.Jobs, _ Boundary) string
- func LabelWrite(w model.LabelWrite, bd Boundary) string
- func Labels(l model.Labels, bd Boundary) string
- func Line(s string, max int) (string, int)
- func Links(s, self string) string
- func Lint(l model.Lint, bd Boundary) string
- func Log(raw []byte) string
- func MRCommits(c model.MRCommits, bd Boundary) string
- func MRDiff(d model.MRDiff, bd Boundary) string
- func MRFiles(f model.MRFiles, _ Boundary) string
- func MRVersionChanges(c model.MRVersionChanges, bd Boundary) string
- func MRVersions(v model.MRVersions, _ Boundary) string
- func Markdown(s string, self string) (string, int)
- func Me(m model.Me, _ Boundary) string
- func Members(l model.Members, _ Boundary) string
- func MergeRequest(mr model.MergeRequest, bd Boundary) string
- func MergeRequestPipelineWrite(w model.MergeRequestPipelineWrite, _ Boundary) string
- func MergeRequestWrite(w model.MergeRequestWrite, _ Boundary) string
- func MergeWrite(w model.MergeWrite, _ Boundary) string
- func MilestoneWrite(w model.MilestoneWrite, bd Boundary) string
- func Milestones(m model.Milestones, bd Boundary) string
- func PickWrite(w model.PickWrite, bd Boundary) string
- func Pipeline(p model.PipelineDetail, bd Boundary) string
- func PipelineWrite(w model.PipelineWrite, _ Boundary) string
- func Pipelines(l model.Pipelines, _ Boundary) string
- func Project(p model.Project, bd Boundary) string
- func ProjectList(l model.ProjectList, bd Boundary) string
- func ReactionWrite(w model.ReactionWrite, _ Boundary) string
- func RebaseWrite(w model.RebaseWrite, bd Boundary) string
- func Release(r model.Release, bd Boundary) string
- func ReleaseWrite(w model.ReleaseWrite, _ Boundary) string
- func Releases(l model.Releases, bd Boundary) string
- func Resolved(r model.Resolved, _ Boundary) string
- func ReviewSubmit(w model.ReviewSubmit, _ Boundary) string
- func Search(s model.Search, bd Boundary) string
- func Snippet(s model.Snippet, bd Boundary) string
- func SnippetDelete(w model.SnippetDelete, _ Boundary) string
- func SnippetUpdate(w model.SnippetUpdate, _ Boundary) string
- func SnippetWrite(w model.SnippetWrite, _ Boundary) string
- func Snippets(l model.Snippets, bd Boundary) string
- func StripANSI(s string) string
- func SubscriptionWrite(w model.SubscriptionWrite, _ Boundary) string
- func SuggestionText(from, to string) (fromShown, toShown string, cut bool, hidden int)
- func SuggestionsApply(w model.SuggestionsApply, bd Boundary) string
- func TagWrite(w model.TagWrite, _ Boundary) string
- func Tags(t model.Tags, bd Boundary) string
- func TestReport(r model.TestReport, bd Boundary) string
- func TimeWrite(w model.TimeWrite, _ Boundary) string
- func TodoWrite(w model.TodoWrite, _ Boundary) string
- func Todos(l model.Todos, bd Boundary) string
- func TodosDone(w model.TodosDone, _ Boundary) string
- func Tree(t model.Tree, _ Boundary) string
- func UploadWrite(w model.UploadWrite, _ Boundary) string
- func Users(l model.Users, _ Boundary) string
- func WikiDelete(w model.WikiDelete, _ Boundary) string
- func WikiPage(p model.WikiPage, bd Boundary) string
- func WikiPages(l model.WikiPages, bd Boundary) string
- func WikiWrite(w model.WikiWrite, _ Boundary) string
- type AskedSuggestion
- type Boundary
- type LogSection
- type Origin
- type Question
- func AskApplySuggestions(project string, iid int64, source, sha string, sgs []AskedSuggestion) Question
- func AskApprove(project string, iid int64, title, sha string) Question
- func AskCreateRelease(project, tag, name, ref string, tagExists bool, links int) Question
- func AskCreateTag(project, name, ref string) Question
- func AskDeleteBranch(project, branch, sha string, merged bool) Question
- func AskDeleteComment(project, kind string, iid int64, author, body string) Question
- func AskDeleteLabel(project, name string, openIssues *int) Question
- func AskDeleteMilestone(project, title string) Question
- func AskDeleteSnippet(project string, id int64, title string, files []string) Question
- func AskDeleteTag(project, name, sha string, release bool) Question
- func AskDeleteWikiPage(project, title, slug string) Question
- func AskMerge(project string, iid int64, title, source, target, sha string, autoMerge bool, ...) Question
- func AskPlayJob(project string, jobID int64, name, stage string, pipelineID int64, ...) Question
- func AskPublishIssue(project string, iid int64, title string) Question
- func AskRunMergeRequestPipeline(project string, iid int64, title, source, target, sha string, ...) Question
- func AskRunPipeline(project, ref string, kind RefKind, variables, inputs []string) Question
- func AskUploadFile(project, name, contentType string, notes []string, data []byte) Question
- type RefKind
Constants ¶
const ( // DescriptionBudget bounds an issue or merge request description. DescriptionBudget = 20000 // FileBudget bounds the text of one file. FileBudget = 60000 // DiscussionBudget bounds the comment text of one page of threads. DiscussionBudget = 30000 // NoteBudget bounds one comment within that. NoteBudget = 6000 // DiffBudget bounds the diffs of one commit. DiffBudget = 40000 // CommitMessageBudget bounds a commit message. CommitMessageBudget = 8000 // TestReportBudget bounds the failed cases of one test report // result, and TestOutputBudget one case's output within that. TestReportBudget = 40000 TestOutputBudget = 4000 // BoardsBudget bounds one page of list_boards, by an estimate of // each board's lists. BoardsBudget = 30000 // BoardsRead is how many boards one list_boards call reads, the // first by id. BoardsRead = 1000 // TitleChars bounds a one-line title. TitleChars = 200 )
Budgets in characters (§4.8). A result states the one it used, so a cut text is never mistaken for a short one.
const ( JobLogBytes = 40000 MaxJobLogBytes = 100000 )
JobLogBytes is the default window of a job log, in bytes of the stored log, and MaxJobLogBytes the most one call reads (§4.8).
const SuggestionLen = 2000
SuggestionLen caps each text of a suggestion a result shows.
const TimestampPrefix = `[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?Z [0-9a-fA-F]{2}[OE](\+| ?)`
TimestampPrefix matches a runner's per-line timestamp and stream marker; group 1 is "+" on a line that continues the one before.
Variables ¶
This section is empty.
Functions ¶
func ApprovalWrite ¶
func ApprovalWrite(w model.ApprovalWrite, _ Boundary) string
ApprovalWrite renders approve_merge_request and unapprove_merge_request.
func AutoMergeCancel ¶ added in v2.2.0
func AutoMergeCancel(w model.AutoMergeCancel, _ Boundary) string
AutoMergeCancel renders cancel_auto_merge.
func BranchDelete ¶
func BranchDelete(w model.BranchDelete, _ Boundary) string
BranchDelete renders delete_branch.
func BranchWrite ¶
func BranchWrite(w model.BranchWrite, _ Boundary) string
BranchWrite renders create_branch.
func Code ¶
Code prepares text that is not rendered as Markdown — file contents, diffs, commit messages. Nothing is dropped, because the text may be edited later on the strength of what was shown; each hidden character is written out as <U+202E> instead, which is also how a reviewer would want to see it. It returns the text and how many were made visible.
func CommentDelete ¶
func CommentDelete(w model.CommentDelete, _ Boundary) string
CommentDelete renders delete_comment.
func CommentUpdate ¶
func CommentUpdate(w model.CommentUpdate, _ Boundary) string
CommentUpdate renders update_comment.
func CommentWrite ¶
func CommentWrite(w model.CommentWrite, _ Boundary) string
CommentWrite renders add_comment and add_review_comment.
func CommitWrite ¶
func CommitWrite(w model.CommitWrite, _ Boundary) string
CommitWrite renders create_commit.
func ContentType ¶
ContentType guesses a media type from the first bytes.
func Cut ¶
Cut returns the part of text that starts at offset and fits budget, ending at a paragraph boundary when one falls in the second half of the window, else at a line boundary there, else at the budget. Offsets and counts are in characters (runes), never bytes, so a continue offset never lands inside one.
An offset past the end yields nothing and a budget whose ContinueOffset is null; the caller decides whether that is an error.
func Deployments ¶
func Deployments(l model.Deployments, _ Boundary) string
Deployments renders list_deployments.
func DiscussionWrite ¶
func DiscussionWrite(w model.DiscussionWrite, _ Boundary) string
DiscussionWrite renders resolve_discussion.
func Discussions ¶
func Discussions(d model.Discussions, bd Boundary) string
Discussions renders list_discussions.
func DraftDelete ¶
func DraftDelete(w model.DraftDelete, _ Boundary) string
DraftDelete renders delete_review_comment.
func DraftNotes ¶
func DraftNotes(d model.DraftNotes, bd Boundary) string
DraftNotes renders list_review_comments.
func DraftPublish ¶ added in v2.2.0
func DraftPublish(w model.DraftPublish, bd Boundary) string
DraftPublish renders publish_review_comment. A lost draft's text is shown in a boundary: a draft may quote anyone.
func DraftUpdate ¶ added in v2.2.0
func DraftUpdate(w model.DraftUpdate, _ Boundary) string
DraftUpdate renders update_review_comment.
func Environments ¶
func Environments(l model.Environments, _ Boundary) string
Environments renders list_environments.
func Ident ¶
Ident prepares a name someone else chose — a file path, a branch, a label, a topic — for one line of text. Nothing is dropped, folded or cut, since the name may be passed back to a tool; each control or hidden character is written out as <U+000A> instead, so a newline in a file name cannot start a line that reads as the server's.
func Invisible ¶ added in v2.2.0
Invisible lists the characters of s a reader would not see, each once, in order: hidden and bidirectional ones, characters drawn as blank space, and controls other than tab, line feed and carriage return. Unicode's other default-ignorable characters, the Hangul fillers among them, and the variation selectors are included: a filler is an identifier that reads as nothing, and a selector makes two names that read the same (\u00A74.12).
func IsBinary ¶
IsBinary reports content that is not text: a NUL byte, or bytes that are not UTF-8, in the first 8,000. Binary content is described by its metadata, never shown as lossy text (§4.8).
func IssueLinkWrite ¶
func IssueLinkWrite(w model.IssueLinkWrite, _ Boundary) string
IssueLinkWrite renders link_issues and unlink_issues.
func IssueWrite ¶
func IssueWrite(w model.IssueWrite, _ Boundary) string
IssueWrite renders create_issue and update_issue.
func ItemEvents ¶ added in v2.1.0
func ItemEvents(l model.ItemEvents, bd Boundary) string
ItemEvents renders list_item_events.
func ItemList ¶
ItemList renders search_issues and search_merge_requests. noun is "issues" or "merge requests".
func LabelWrite ¶
func LabelWrite(w model.LabelWrite, bd Boundary) string
LabelWrite renders create_label, update_label and delete_label.
func Line ¶
Line prepares a one-line field someone else wrote, such as a title: hidden characters dropped, runs of spaces and control characters (line and paragraph separators included) folded to one space, and the result cut to max characters. It returns the line and how many characters were dropped.
func Links ¶
Links rewrites Markdown links so the text shows where they go (§4.1.3). A link whose text says one thing and whose destination is another is the cheapest deception there is, and nothing is ever fetched, so what the reader needs is the host. A link on the configured instance, self, keeps its path, because that is how an issue points at another issue.
func Log ¶
Log turns a window of a stored log into the text GitLab's job page shows (see above). It does not mask secrets or make hidden characters visible; the caller does both, on what this returns.
func MRVersionChanges ¶ added in v2.2.0
func MRVersionChanges(c model.MRVersionChanges, bd Boundary) string
MRVersionChanges renders compare_mr_versions.
func MRVersions ¶ added in v2.2.0
func MRVersions(v model.MRVersions, _ Boundary) string
MRVersions renders list_mr_versions.
func Markdown ¶
Markdown prepares Markdown someone else wrote for display: HTML comments and reference definitions no link uses, outside code fences, are dropped, hidden characters are dropped everywhere, and links show their destination. It returns the text and how many characters were dropped.
Comments inside a fence are left, because there they are visible: the rule is to remove what a person reading the page would not see and the model would.
func MergeRequest ¶
func MergeRequest(mr model.MergeRequest, bd Boundary) string
MergeRequest renders get_merge_request.
func MergeRequestPipelineWrite ¶ added in v2.1.0
func MergeRequestPipelineWrite(w model.MergeRequestPipelineWrite, _ Boundary) string
MergeRequestPipelineWrite renders run_merge_request_pipeline.
func MergeRequestWrite ¶
func MergeRequestWrite(w model.MergeRequestWrite, _ Boundary) string
MergeRequestWrite renders create_merge_request and update_merge_request.
func MergeWrite ¶
func MergeWrite(w model.MergeWrite, _ Boundary) string
MergeWrite renders merge_merge_request.
func MilestoneWrite ¶
func MilestoneWrite(w model.MilestoneWrite, bd Boundary) string
MilestoneWrite renders create_milestone, update_milestone and delete_milestone.
func Milestones ¶
func Milestones(m model.Milestones, bd Boundary) string
Milestones renders list_milestones.
func Pipeline ¶
func Pipeline(p model.PipelineDetail, bd Boundary) string
Pipeline renders get_pipeline.
func PipelineWrite ¶
func PipelineWrite(w model.PipelineWrite, _ Boundary) string
PipelineWrite renders run_pipeline, retry_pipeline and cancel_pipeline.
func ProjectList ¶
func ProjectList(l model.ProjectList, bd Boundary) string
ProjectList renders search_projects.
func ReactionWrite ¶ added in v2.2.0
func ReactionWrite(w model.ReactionWrite, _ Boundary) string
ReactionWrite renders react.
func RebaseWrite ¶
func RebaseWrite(w model.RebaseWrite, bd Boundary) string
RebaseWrite renders rebase_merge_request.
func ReleaseWrite ¶
func ReleaseWrite(w model.ReleaseWrite, _ Boundary) string
ReleaseWrite renders create_release.
func ReviewSubmit ¶
func ReviewSubmit(w model.ReviewSubmit, _ Boundary) string
ReviewSubmit renders submit_review.
func SnippetDelete ¶ added in v2.1.0
func SnippetDelete(w model.SnippetDelete, _ Boundary) string
SnippetDelete renders delete_snippet.
func SnippetUpdate ¶ added in v2.1.0
func SnippetUpdate(w model.SnippetUpdate, _ Boundary) string
SnippetUpdate renders update_snippet.
func SnippetWrite ¶
func SnippetWrite(w model.SnippetWrite, _ Boundary) string
SnippetWrite renders create_snippet.
func StripANSI ¶
StripANSI removes terminal escapes, which also hide a secret from the masks: a color code before a token leaves no word boundary to match.
func SubscriptionWrite ¶ added in v2.1.0
func SubscriptionWrite(w model.SubscriptionWrite, _ Boundary) string
SubscriptionWrite renders subscribe.
func SuggestionText ¶ added in v2.2.0
SuggestionText prepares a suggestion's two texts as Code prepares code, each cut at SuggestionLen characters: what a reader sees is what applying it commits.
func SuggestionsApply ¶ added in v2.2.0
func SuggestionsApply(w model.SuggestionsApply, bd Boundary) string
SuggestionsApply renders apply_suggestions.
func TestReport ¶ added in v2.1.0
func TestReport(r model.TestReport, bd Boundary) string
TestReport renders get_test_report.
func UploadWrite ¶ added in v2.3.0
func UploadWrite(w model.UploadWrite, _ Boundary) string
UploadWrite renders upload_file. The Markdown is GitLab's, built from a name the server made safe, and stands in a code span so a client shows it rather than drawing the image.
func WikiDelete ¶
func WikiDelete(w model.WikiDelete, _ Boundary) string
WikiDelete renders delete_wiki_page.
Types ¶
type AskedSuggestion ¶ added in v2.2.0
AskedSuggestion is one suggestion AskApplySuggestions shows: where it goes and the text it commits.
type Boundary ¶
type Boundary struct {
// contains filtered or unexported fields
}
Boundary marks text someone else wrote (§4.1.1). Its token is drawn per tool call, so text written before the call cannot know it and cannot close the block early: a forged end marker carries the wrong token. Markers are also defused inside the text, so a forgery does not even look like one.
func (Boundary) Block ¶
Block wraps multi-line text:
<<<UNTRUSTED 0123abcd kind=description project=group/project item=#12 author=@alice>>> text <<<END 0123abcd>>>
type LogSection ¶
LogSection is one section of a stored log, by byte offsets: Start is where its start marker begins, or -1 when it began before the stretch read; End is where its end marker ends, or -1 when the stretch has no end marker for it.
func LogSections ¶
func LogSections(raw []byte) []LogSection
LogSections finds the sections of a stretch of a stored log, in the order their markers appear. A section whose end marker is in the stretch and whose start is not began before it.
type Origin ¶
type Origin struct {
Kind string
Project string
Item string // "#12", "!3", a file path or a commit id
Author string // a username, without "@"
}
Origin says where a block of text came from: its kind, the project, the issue, merge request or path, and who wrote it.
type Question ¶
Question is what the server asks the person before a write that ships work or deletes something for good (§4.12). Text is the message a client shows; accepting it is the confirmation. Every word is the server's, except what stands in backticks, which is quoted from GitLab or from the call and cut to one line. A blank line separates the lines, so a client that draws Markdown keeps them apart.
Bind is what an answer is bound to: what the write depends on, which must not change between the question and the write. It is Text, and more where Text shows less than the write uses — a whole head sha, a whole comment.
func AskApplySuggestions ¶ added in v2.2.0
func AskApplySuggestions(project string, iid int64, source, sha string, sgs []AskedSuggestion) Question
AskApplySuggestions asks before apply_suggestions: the text is someone else's, committed under the person's name. The head and each whole text are bound.
func AskApprove ¶
AskApprove asks before approve_merge_request.
func AskCreateRelease ¶
AskCreateRelease asks before create_release.
func AskCreateTag ¶
AskCreateTag asks before create_tag. A tag a protection rule would cover is refused before it is asked about.
func AskDeleteBranch ¶
AskDeleteBranch asks before delete_branch. The whole head is bound.
func AskDeleteComment ¶
AskDeleteComment asks before delete_comment, showing the start of the comment; the whole comment is bound. kind is "issue" or "merge_request".
func AskDeleteLabel ¶
AskDeleteLabel asks before delete_label. The count is shown and not bound: a label that is applied while the person reads would never be confirmed. The label is bound by its name.
func AskDeleteMilestone ¶
AskDeleteMilestone asks before delete_milestone.
func AskDeleteSnippet ¶ added in v2.1.0
AskDeleteSnippet asks before delete_snippet; project is empty for a personal snippet. It counts the files and names each on its own line, the first askFiles of them. The whole title and every file name are bound.
func AskDeleteTag ¶
AskDeleteTag asks before delete_tag. The whole commit is bound.
func AskDeleteWikiPage ¶
AskDeleteWikiPage asks before delete_wiki_page. The page's content is bound by the witness delete_wiki_page already holds.
func AskMerge ¶
func AskMerge(project string, iid int64, title, source, target, sha string, autoMerge bool, squash, removeSource *bool) Question
AskMerge asks before merge_merge_request, or before setting a merge request to merge when its pipeline succeeds. The whole head is bound.
func AskPlayJob ¶
func AskPlayJob(project string, jobID int64, name, stage string, pipelineID int64, variables, inputs []string) Question
AskPlayJob asks before play_job. Variable values are never shown, only their keys.
func AskPublishIssue ¶
AskPublishIssue asks before update_issue makes a confidential issue public.
func AskRunMergeRequestPipeline ¶ added in v2.1.0
func AskRunMergeRequestPipeline(project string, iid int64, title, source, target, sha string, sourceKind, targetKind RefKind) Question
AskRunMergeRequestPipeline asks before run_merge_request_pipeline when both of the merge request's branches count as protected, so its jobs may see protected variables. The whole head and the branches are bound.
func AskRunPipeline ¶
AskRunPipeline asks before run_pipeline on the default branch or a protected ref.
func AskUploadFile ¶ added in v2.3.0
AskUploadFile asks before upload_file: an upload discloses the image to whoever can open its link. notes are the server's own sentences on who can and what goes with it. The image's bytes are bound.