gerrit

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MaxChanges is the max number of changes to request from Gerrit.
	//
	// This should be a number small enough so that it can be handled in one
	// request, but also large enough to avoid skipping over changes.
	MaxChanges = 60
)

Variables

View Source
var GerritServer gerritServer

GerritServer implements RestAPI for the Gerrit service.

Functions

func CLNumber

func CLNumber(revision string) string

CLNumber extracts the CL number from a revision ref.

func CommentIsInChangedLines

func CommentIsInChangedLines(c context.Context, data *tricium.Data_Comment, changedLines ChangedLinesInfo, numNearbyLines int) bool

CommentIsInChangedLines returns true whether a comment is in or close enough to the change.

Comments on the change description and comments within numNearbyLines of changed lines are included.

func CreateURL

func CreateURL(host, revision string) string

CreateURL makes a URL to link to a particular revision.

func ExtractCLPatchSetNumbers

func ExtractCLPatchSetNumbers(revision string) (string, string)

ExtractCLPatchSetNumbers extracts CL/patch numbers from a revision ref.

func FilterRequestChangedLines

func FilterRequestChangedLines(request *track.AnalyzeRequest, changedLines *ChangedLinesInfo)

FilterRequestChangedLines will remove changed lines for all files in |request| that should be ignored when considering whether to post a comment to the file.

func IsGerritProjectRequest

func IsGerritProjectRequest(request *track.AnalyzeRequest) bool

IsGerritProjectRequest determines if the |request| is for a Gerrit project.

func PatchSetNumber

func PatchSetNumber(revision string) string

PatchSetNumber extracts the patch set number from a revision ref.

Types

type API

type API interface {
	// QueryChanges sends one query for changes to Gerrit using the provided
	// poll data.
	//
	// The poll data is assumed to correspond to the last seen change before
	// this poll. Even though Gerrit supports paging, we only make one request
	// to Gerrit because polling too many changes can quickly use up too much
	// memory and time.
	//
	// A list of changes is returned in the same order as they were returned by
	// Gerrit. The result tuple includes a boolean value to indicate if the
	// result was truncated.
	QueryChanges(c context.Context, host, project string, lastTimestamp time.Time) ([]gr.ChangeInfo, bool, error)
	// PostRobotComments posts robot comments to a change.
	PostRobotComments(c context.Context, host, change, revision string, runID int64, comments []*track.Comment) error
	// GetChangedLines requests the diff info for all files for a
	// particular revision and extracts the lines in the "new" post-patch
	// version that are considered changed.
	GetChangedLines(c context.Context, host, change, revision string) (ChangedLinesInfo, error)
}

API specifies the Gerrit REST API tuned to the needs of Tricium.

type ChangedLinesInfo

type ChangedLinesInfo map[string][]int

ChangedLinesInfo contains the line numbers that have been touched in particular change. The string key is the file name (in posix form), and the value is a list of changed (i.e. added or modified) lines (sorted) in the destination file.

type MockRestAPI

type MockRestAPI struct {
	LastMsg      string
	LastComments []*track.Comment
	ChangedLines ChangedLinesInfo
}

MockRestAPI mocks the GerritAPI interface for testing.

Remembers the last posted message and comments.

func (*MockRestAPI) GetChangedLines

func (m *MockRestAPI) GetChangedLines(c context.Context, host, change, revision string) (ChangedLinesInfo, error)

GetChangedLines requests the diff info for all files for a particular revision and extracts the lines in the "new" post-patch version that are considered changed.

func (*MockRestAPI) PostRobotComments

func (m *MockRestAPI) PostRobotComments(c context.Context, host, change, revision string, runID int64, comments []*track.Comment) error

PostRobotComments posts robot comments to a change.

func (*MockRestAPI) QueryChanges

func (*MockRestAPI) QueryChanges(c context.Context, host, project string, ts time.Time) ([]gr.ChangeInfo, bool, error)

QueryChanges sends one query for changes to Gerrit using the provided poll data.

Jump to

Keyboard shortcuts

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