Documentation
¶
Overview ¶
Package diff parses unified diff patches into line-level data used by the diff review view. It is independent of where the patch came from (GitHub API or a local git working tree).
Index ¶
Constants ¶
const ( SideRight = "RIGHT" // new file (added and context lines) SideLeft = "LEFT" // old file (removed lines) )
Side constants identify which side of a diff a line belongs to. They match the values GitHub's PR review API expects.
Variables ¶
This section is empty.
Functions ¶
func AddedFilePatch ¶
AddedFilePatch builds a patch that marks every line of content as added. Used for untracked files, which have no git diff but should still be reviewable in the diff view.
func StripHeader ¶
StripHeader removes everything before the first hunk header ("@@"). Local `git diff` output starts with "diff --git", "index", "---", and "+++" lines that ParsePatch would otherwise misread as removed/added content. GitHub's API patches already start at the first hunk, so they pass through unchanged.
Types ¶
type Info ¶
type Info struct {
Lines []Line
}
Info contains parsed diff data for a single file.
func ParsePatch ¶
ParsePatch parses a unified diff patch string into Info. The patch must start at the first hunk header (see StripHeader for git output). Returns nil for an empty patch.
func (*Info) FormatDiffLines ¶
FormatDiffLines returns display strings for the diff lines with +/-/space prefix. A space separator is inserted between the prefix and content for readability.