comment

package
v0.0.0-...-413351d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package comment defines the internal representation of a review comment.

Index

Constants

View Source
const FormatVersion = 0

FormatVersion defines the latest version of the comment format supported by the tool.

View Source
const Ref = "refs/notes/devtools/discuss"

Ref defines the git-notes ref that we expect to contain review comments.

Variables

View Source
var ErrInvalidRange = errors.New("invalid file location range. The required form is StartLine[+StartColumn][:EndLine[+EndColumn]]. The first line in a file is considered to be line 1")

ErrInvalidRange inidcates an error during parsing of a user-defined file range

Functions

func ParseAllValid

func ParseAllValid(notes []repository.Note) map[string]Comment

ParseAllValid takes collection of git notes and tries to parse a review comment from each one. Any notes that are not valid review comments get ignored, as we expect the git notes to be a heterogenous list, with only some of them being review comments.

Types

type Comment

type Comment struct {
	// Timestamp and Author are optimizations that allows us to display comment threads
	// without having to run git-blame over the notes object. This is done because
	// git-blame will become more and more expensive as the number of code reviews grows.
	Timestamp string `json:"timestamp,omitempty"`
	Author    string `json:"author,omitempty"`
	// If original is provided, then the comment is an updated version of another comment.
	Original string `json:"original,omitempty"`
	// If parent is provided, then the comment is a response to another comment.
	Parent string `json:"parent,omitempty"`
	// If location is provided, then the comment is specific to that given location.
	Location    *Location `json:"location,omitempty"`
	Description string    `json:"description,omitempty"`
	// The resolved bit indicates that no further action is needed.
	//
	// When the parent of the comment is another comment, this means that comment
	// has been addressed. Otherwise, the parent is the commit, and this means that the
	// change has been accepted. If the resolved bit is unset, then the comment is only an FYI.
	Resolved *bool `json:"resolved,omitempty"`
	// Version represents the version of the metadata format.
	Version int `json:"v,omitempty"`

	gpg.Sig
}

Comment represents a review comment, and can occur in any of the following contexts: 1. As a comment on an entire commit. 2. As a comment about a specific file in a commit. 3. As a comment about a specific line in a commit. 4. As a response to another comment.

func New

func New(author string, description string) Comment

New returns a new comment with the given description message.

The Timestamp and Author fields are automatically filled in with the current time and user.

func Parse

func Parse(note repository.Note) (Comment, error)

Parse parses a review comment from a git note.

func (Comment) Hash

func (comment Comment) Hash() (string, error)

Hash returns the SHA1 hash of a review comment.

func (Comment) Write

func (comment Comment) Write() (repository.Note, error)

Write writes a review comment as a JSON-formatted git note.

type Location

type Location struct {
	Commit string `json:"commit,omitempty"`
	// If the path is omitted, then the comment applies to the entire commit.
	Path string `json:"path,omitempty"`
	// If the range is omitted, then the location represents an entire file.
	Range *Range `json:"range,omitempty"`
}

Location represents the location of a comment within a commit.

func (*Location) Check

func (location *Location) Check(repo repository.Repo) error

Check verifies that this location is valid in the provided repository.

type Range

type Range struct {
	StartLine   uint32 `json:"startLine"`
	StartColumn uint32 `json:"startColumn,omitempty"`
	EndLine     uint32 `json:"endLine,omitempty"`
	EndColumn   uint32 `json:"endColumn,omitempty"`
}

Range represents the range of text that is under discussion.

func (*Range) Set

func (r *Range) Set(s string) error

Set implenents flag.Value for the Range type

func (*Range) String

func (r *Range) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL