Documentation
¶
Overview ¶
Package review breaks a change down for a reviewer: what each changed file is for, which files are safe to skim, and which declarations changed. It works from diffs and file contents supplied by the caller and never runs git; see the gitdiff package for reading a range from a repository.
Index ¶
Constants ¶
const ( GroupChange = "change" GroupDocs = "docs" GroupConfig = "config" GroupDependencies = "dependencies" GroupMechanical = "mechanical" GroupSkim = "skim" )
Group kinds, in the order they are presented.
const ( Added = "added" Modified = "modified" Deleted = "deleted" Renamed = "renamed" Copied = "copied" TypeChanged = "type-changed" )
File statuses.
const ( SymbolAdded = "added" SymbolSignature = "signature" SymbolBody = "body" )
Symbol change kinds.
const MaxContentBytes = 1 << 20
MaxContentBytes is the most file content worth supplying per side. Larger files are still classified from their first bytes but not outlined.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Commit ¶
type Commit struct {
SHA string `json:"sha,omitempty"`
Subject string `json:"subject"`
Body string `json:"body,omitempty"`
Files []CommitFile `json:"files,omitempty"`
}
Commit is one commit in the change, oldest first.
func ReadPatch ¶
ReadPatch parses a single diff as written by git diff, git format-patch or diff -u, calling visit once per section, and returns optional format-patch metadata. Patch series are rejected. Added and deleted files carry their full contents, since the diff holds every line; other files carry none.
type CommitFile ¶
type CommitFile struct {
Path string `json:"path"`
OldPath string `json:"old_path,omitempty"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
}
CommitFile is one path a commit changed and by how much. OldPath is set when the commit renamed it.
type Content ¶
Content is one side of a changed file. Complete is false when Data holds only a prefix.
type Dependency ¶
Dependency marks a file a package manager reads, as identified by manifests.
type File ¶
type File struct {
Path string `json:"path"`
OldPath string `json:"old_path,omitempty"`
Status string `json:"status"`
Similarity int `json:"similarity,omitempty"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Binary bool `json:"binary,omitempty"`
OldMode string `json:"old_mode,omitempty"`
NewMode string `json:"new_mode,omitempty"`
Roles []roles.Role `json:"roles"`
Evidence []roles.Evidence `json:"evidence"`
Hunks int `json:"hunks"`
Contexts []string `json:"contexts,omitempty"`
Dependency *Dependency `json:"dependency,omitempty"`
Skip string `json:"skip,omitempty"`
Mechanical string `json:"mechanical,omitempty"`
Surface *Surface `json:"surface,omitempty"`
Symbols []SymbolChange `json:"symbols,omitempty"`
// contains filtered or unexported fields
}
File is the analysis of one changed path.
type FileDiff ¶
type FileDiff struct {
Path string
OldPath string
Status string
Similarity int
Additions int
Deletions int
Binary bool
Symlink bool
Submodule bool
// OldMode and NewMode are git file modes such as 100644, empty for a
// side that doesn't exist or when the diff doesn't say.
OldMode string
NewMode string
Hunks []Hunk
Base *Content
Head *Content
Symbols []Symbol
// BaseSymbols are the declarations in the base version.
BaseSymbols []Symbol
}
FileDiff is one changed file as a diff describes it. Base, Head, Symbols and BaseSymbols are optional: without contents, classification is by path alone and declarations are not compared; without Symbols, changes are described by hunk context rather than by name; without BaseSymbols, a declaration whose every line changed is taken to be new.
type Group ¶
type Group struct {
ID int `json:"id"`
Kind string `json:"kind"`
Title string `json:"title"`
Summary []string `json:"summary"`
Commits []string `json:"commits,omitempty"`
Files []string `json:"files"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
// Children split a large group into parts, numbered from 1 within it.
Children []Group `json:"children,omitempty"`
// contains filtered or unexported fields
}
Group is a set of files to read together. IDs follow presentation order and are stable for the same input.
type Hunk ¶
type Hunk struct {
Header string `json:"header"`
OldStart int `json:"old_start"`
OldLines int `json:"old_lines"`
NewStart int `json:"new_start"`
NewLines int `json:"new_lines"`
Lines []string `json:"-"`
}
Hunk is one hunk of a file's diff. Lines keep their leading ' ', '-' or '+', and a "\ No newline at end of file" marker stays after the line it applies to.
func ParseHunkHeader ¶
ParseHunkHeader reads the line ranges from "@@ -a,b +c,d @@ context".
type Overview ¶
type Overview struct {
Range *Range `json:"range,omitempty"`
Branch string `json:"branch,omitempty"`
// Commits is optional metadata; grouping and rendering use the net diff.
Commits []Commit `json:"commits,omitempty"`
Files []File `json:"files"`
Links []Link `json:"links,omitempty"`
Groups []Group `json:"groups"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Warnings []string `json:"warnings,omitempty"`
}
Overview is the breakdown of one net diff. Callers fill Range, Branch and Links as available, Add each file, then call Group.
func (*Overview) Group ¶
func (o *Overview) Group()
Group partitions the files into groups in reading order, replacing any earlier grouping.
type Range ¶
type Range struct {
Base string `json:"base"`
Head string `json:"head"`
BaseRev string `json:"base_rev"`
HeadRev string `json:"head_rev"`
MergeBase bool `json:"merge_base"`
}
Range is the pair of commits a review covers.
type Surface ¶
type Surface struct {
Lines []SurfaceLine `json:"lines"`
Truncated bool `json:"truncated,omitempty"`
}
Surface compares the outlines (signatures, types, imports, comments) of a file's two versions. An empty Lines with Truncated false means only function bodies changed.
type SurfaceLine ¶
type SurfaceLine struct {
Op string `json:"op"`
Text string `json:"text"`
Context string `json:"context,omitempty"`
}
SurfaceLine is one declaration-level line that differs between the base and head outlines. Context is the enclosing top-level declaration for indented lines such as struct fields or methods.
type Symbol ¶
type Symbol struct {
Name string `json:"name"`
Qualified string `json:"qualified,omitempty"`
Kind string `json:"kind"`
Signature string `json:"signature,omitempty"`
StartLine int `json:"start_line"`
EndLine int `json:"end_line"`
Exported bool `json:"exported,omitempty"`
}
Symbol is a declaration in one version of a file, with one-based inclusive line numbers. Qualified names it within the file, such as "Store.load", and Signature is its text up to any body, such as "func (b *B) Load(x int) error".
type SymbolChange ¶
type SymbolChange struct {
Name string `json:"name"`
Kind string `json:"kind"`
Exported bool `json:"exported,omitempty"`
Change string `json:"change"`
}
SymbolChange says how a head declaration was affected by the change.
type TextOptions ¶
type TextOptions struct {
// Markdown writes GitHub-flavoured Markdown instead of terminal text.
Markdown bool
// Declarations adds each file's declaration-level changes under it.
Declarations bool
}
TextOptions control rendering.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
review
command
|
|
|
Package gitdiff reads a commit range from a local repository with the git binary and analyses it with the review package.
|
Package gitdiff reads a commit range from a local repository with the git binary and analyses it with the review package. |
|
internal
|
|
|
gittest
Package gittest builds throwaway git repositories for tests.
|
Package gittest builds throwaway git repositories for tests. |