gerrit

package
v0.0.0-...-abfb8b1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: BSD-3-Clause Imports: 17 Imported by: 6

Documentation

Overview

Package gerrit provides library functions for interacting with the gerrit code review system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRefString

func ParseRefString(ref string) (int, int, error)

ParseRefString parses the cl and patchset number from the given ref string.

func PresubmitTestTypes

func PresubmitTestTypes() []string

func Push

func Push(seq runutil.Sequence, clOpts CLOpts) error

Push pushes the current branch to Gerrit.

func Reference

func Reference(opts CLOpts) string

Reference inputs CL options and returns a matching string representation of a Gerrit reference.

func WriteLog

func WriteLog(logFilePath string, cls CLList) (e error)

WriteLog writes the given list of CLs to a log file, as a json-encoded map of ref strings => CLs.

Types

type CLList

type CLList []Change

The following types reflect the schema Gerrit uses to represent CLs.

func NewOpenCLs

func NewOpenCLs(prevCLsMap CLRefMap, curCLs CLList) ([]CLList, []error)

NewOpenCLs returns a slice of CLLists that are "newer" relative to the previous query. A CLList is newer if one of the following condition holds: - If a CLList has only one cl, then it is newer if:

  • Its ref string cannot be found among the CLs from the previous query.

    For example: from the previous query, we got cl 1000/1 (cl number 1000 and patchset 1). Then CLLists 1000/2 and 2000/1 are both newer.

- If a CLList has multiple CLs, then it is newer if:

  • It forms a "consistent" (its CLs have the same topic) and "complete" (it contains all the parts) multi-part CL set.

  • At least one of their ref strings cannot be found in the CLs from the previous query.

    For example: from the previous query, we got cl 3001/1 which is the first part of a multi part cl set with topic "T1". Suppose the current query returns cl 3002/1 which is the second part of the same set. In this case, a CLList [3001/1 3002/1] will be returned. Then suppose in the next query, we got cl 3002/2 which is newer then 3002/1. In this case, a CLList [3001/1 3002/2] will be returned.

type CLOpts

type CLOpts struct {
	// Autosubmit determines if the CL should be auto-submitted when it
	// meets the submission rules.
	Autosubmit bool
	// Branch identifies the local branch that contains the CL.
	Branch string
	// Ccs records a list of email addresses to cc on the CL.
	Ccs []string
	// Draft determines if this CL is a draft.
	Draft bool
	// Edit determines if the user should be prompted to edit the commit
	// message when the CL is exported to Gerrit.
	Edit bool
	// Remote identifies the Gerrit remote that this CL will be pushed to
	Remote string
	// Host identifies the Gerrit host.
	Host *url.URL
	// Presubmit determines what presubmit tests to run.
	Presubmit PresubmitTestType
	// RemoteBranch identifies the remote branch the CL pertains to.
	RemoteBranch string
	// Reviewers records a list of email addresses of CL reviewers.
	Reviewers []string
	// Topic records the CL topic.
	Topic string
	// Verify controls whether git pre-push hooks should be run before uploading.
	Verify bool
}

CLOpts records the review options.

type CLRefMap

type CLRefMap map[string]Change

func ReadLog

func ReadLog(logFilePath string) (CLRefMap, error)

ReadLog returns a map of CLs indexed by their refs, read from the given log file.

type Change

type Change struct {
	// CL data.
	Change_id        string
	Current_revision string
	Project          string
	Topic            string
	Revisions        Revisions
	Owner            Owner
	Labels           map[string]map[string]interface{}

	// Custom labels.
	AutoSubmit    bool
	MultiPart     *MultiPartCLInfo
	PresubmitTest PresubmitTestType
}

func GenCL

func GenCL(clNumber, patchset int, project string) Change

func GenCLWithMoreData

func GenCLWithMoreData(clNumber, patchset int, project string, presubmit PresubmitTestType, ownerEmail string) Change

func GenMultiPartCL

func GenMultiPartCL(clNumber, patchset int, project, topic string, index, total int) Change

func GenMultiPartCLWithMoreData

func GenMultiPartCLWithMoreData(clNumber, patchset int, project, topic string, index, total int, ownerEmail string) Change

func (Change) OwnerEmail

func (c Change) OwnerEmail() string

func (Change) Reference

func (c Change) Reference() string

type ChangeError

type ChangeError struct {
	Err error
	CL  Change
}

func NewChangeError

func NewChangeError(cl Change, err error) *ChangeError

func (*ChangeError) Error

func (ce *ChangeError) Error() string

type Comment

type Comment struct {
	Line    int    `json:"line,omitempty"`
	Message string `json:"message,omitempty"`
}

Comment represents a single inline file comment.

type Commit

type Commit struct {
	Message string
}

type Fetch

type Fetch struct {
	Http `json:"http"`
}

type Files

type Files map[string]struct{}

type Gerrit

type Gerrit struct {
	// contains filtered or unexported fields
}

Gerrit records a hostname of a Gerrit instance.

func New

func New(s runutil.Sequence, host *url.URL) *Gerrit

New is the Gerrit factory.

func (*Gerrit) GetChange

func (g *Gerrit) GetChange(changeNumber int) (*Change, error)

GetChange returns a Change object for the given changeId number.

func (*Gerrit) PostReview

func (g *Gerrit) PostReview(ref string, message string, labels map[string]string) (e error)

PostReview posts a review to the given Gerrit reference.

func (*Gerrit) Query

func (g *Gerrit) Query(query string) (_ CLList, e error)

Query returns a list of QueryResult entries matched by the given Gerrit query string from the given Gerrit instance. The result is sorted by the last update time, most recently updated to oldest updated.

See the following links for more details about Gerrit search syntax: - https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes - https://gerrit-review.googlesource.com/Documentation/user-search.html

func (*Gerrit) SetTopic

func (g *Gerrit) SetTopic(cl string, opts CLOpts) (e error)

SetTopic sets the topic of the given Gerrit reference.

func (*Gerrit) Submit

func (g *Gerrit) Submit(changeID string) (e error)

Submit submits the given changelist through Gerrit.

type Http

type Http struct {
	Ref string
}

type MultiPartCLInfo

type MultiPartCLInfo struct {
	Topic string
	Index int // This should be 1-based.
	Total int
}

MultiPartCLInfo contains data used to process multiple cls across different projects.

type MultiPartCLSet

type MultiPartCLSet struct {
	// contains filtered or unexported fields
}

MultiPartCLSet represents a set of CLs that spans multiple projects.

func NewMultiPartCLSet

func NewMultiPartCLSet() *MultiPartCLSet

NewMultiPartCLSet creates a new instance of MultiPartCLSet.

func (*MultiPartCLSet) AddCL

func (s *MultiPartCLSet) AddCL(cl Change) error

AddCL adds a CL to the set after it passes a series of checks.

func (*MultiPartCLSet) CLs

func (s *MultiPartCLSet) CLs() CLList

CLs returns a list of CLs in this set sorted by their part number.

func (*MultiPartCLSet) Complete

func (s *MultiPartCLSet) Complete() bool

Complete returns whether the current set has all the cl parts it needs.

type Owner

type Owner struct {
	Email string
}

type PresubmitTestType

type PresubmitTestType string
const (
	PresubmitTestTypeNone PresubmitTestType = "none"
	PresubmitTestTypeAll  PresubmitTestType = "all"
)

type Review

type Review struct {
	Message  string               `json:"message,omitempty"`
	Labels   map[string]string    `json:"labels,omitempty"`
	Comments map[string][]Comment `json:"comments,omitempty"`
}

Review represents a Gerrit review. For more details, see: http://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#review-input

type Revision

type Revision struct {
	Fetch  `json:"fetch"`
	Commit `json:"commit"`
	Files  `json:"files"`
}

type Revisions

type Revisions map[string]Revision

type Topic

type Topic struct {
	Topic string `json:"topic"`
}

Jump to

Keyboard shortcuts

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