trigger

package
v0.0.0-...-141b21d Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package trigger determines if and how Gerrit CL is triggered.

Index

Constants

View Source
const AutoSubmitLabelName = "Auto-Submit"

AutoSubmitLabelName is the name of the Gerrit label used for triggering auto submission on a given CL.

View Source
const CQLabelName = "Commit-Queue"

CQLabel is full Gerrit label name used for triggering LUCI CV, previously known as CQ.

Variables

View Source
var ErrResetPermanentTag = errors.BoolTag{
	Key: errors.NewTagKey("permanent error while resetting triggers"),
}

ErrResetPermanentTag is an error tag indicating that error occurs during the reset is permanent (e.g. lack of vote permission).

View Source
var ErrResetPreconditionFailedTag = errors.BoolTag{
	Key: errors.NewTagKey("reset precondition not met"),
}

ErrResetPreconditionFailedTag is an error tag indicating that the precondition of resetting a trigger has not been met,

Functions

func CQVoteByMode

func CQVoteByMode(m run.Mode) int32

CQVoteByMode returns the numeric Commit-Queue value for a given Run mode.

func Find

func Find(input *FindInput) *run.Triggers

Find computes the triggers corresponding to a given CL.

It will return the highest priority trigger based on CQ+1 and CQ+2 votes, if the CQ label is non-zero, and an additional trigger for the most recently uploaded patchset if new patchset runs are enabled and a run has not yet been completed for such a patchset.

CQ+2 a.k.a. Full Run takes priority of CQ+1 a.k.a Dry Run, even if CQ+1 vote is newer. Among several equal votes, the earliest is selected as the *triggering* CQ vote.

If the applicable ConfigGroup specifies additional modes AND user who voted on the *triggering* CQ vote also voted on the additional label, then the additional mode is selected instead of the standard Dry/Full Run.

Returns up to one trigger based on a vote on the Commit-Queue label, plus up to one trigger for the new patchset.

func HasAutoSubmit

func HasAutoSubmit(ci *gerritpb.ChangeInfo) bool

func IsResetErrFromGerrit

func IsResetErrFromGerrit(err error) (codes.Code, bool)

IsResetErrFromGerrit returns gerrit grpc error code if the `trigger.Reset` fails because of Gerrit.

func Reset

func Reset(ctx context.Context, in ResetInput) error

Reset removes or "deactivates" the trigger that made CV start processing the current run, whether by removing votes on a CL and posting the given message, or by updating the datastore entity associated with the CL; this, depending on the RunMode of the Run.

For vote-removal-based reset:

Returns error tagged with `ErrPreconditionFailedTag` if one of the following conditions is matched.

  • The patchset of the provided CL is not the latest in Gerrit.
  • The provided CL gets `changelist.AccessDenied` or `changelist.AccessDeniedProbably` from Gerrit.

Normally, the triggering vote(s) is removed last and all other votes are removed in chronological order (latest to earliest). After all votes are removed, the message is posted to Gerrit.

Abnormally, e.g. lack of permission to remove votes, falls back to post a special message which "deactivates" the triggering votes. This special message is a combination of:

  • the original message in the input
  • reason for abnormality,
  • special `botdata.BotData` which ensures CV won't consider previously triggering votes as triggering in the future.

Alternatively, in the case of a new patchset run:

Updates the CLEntity to record that CV is not to create new patchset runs with the current patchset or lower. This prevents trigger.Find() from continuing to return a trigger for this patchset, analog to the effect of removing a cq vote on gerrit.

Types

type FindInput

type FindInput struct {
	// ChangeInfo is required. It should contain the most recent information
	// about the CL to find the triggers in. E.g. label votes and patchsets.
	ChangeInfo *gerritpb.ChangeInfo

	// ConfigGroup is required. It specifies the configuration that matches the
	// change and should define any additional modes required.
	ConfigGroup *cfgpb.ConfigGroup

	// TriggerNewPatchsetRunAfterPS tells Find to ignore patchsets less or equal
	// to this number.
	TriggerNewPatchsetRunAfterPS int32
}

FindInput contains the parameters needed to find active triggers related to a particular CL.

TODO(crbug/1242951): Use the changelist.CL insteat of gerritpb.ChangeInfo,

and remove TriggerNewPatchsetRunAfterPS.

type ResetInput

type ResetInput struct {
	// CL is a Gerrit CL entity.
	//
	// Must have CL.Snapshot set.
	CL *changelist.CL
	// Trigger identifies the triggering vote. Required.
	//
	// Removed only after all other votes on CQ label are removed.
	Triggers *run.Triggers
	// LUCIProject is the project that initiates this reset.
	//
	// The project scoped account of this LUCI project SHOULD have the permission
	// to set the CQ label on behalf of other users in Gerrit.
	LUCIProject string
	// Message to be posted along with the triggering vote removal
	Message string
	// Requester describes the caller (e.g. Project Manager, Run Manager).
	Requester string
	// Notify describes whom to notify regarding the reset.
	//
	// If empty, notifies no one.
	Notify gerrit.Whoms
	// AddToAttentionSet describes whom to add in the attention set.
	//
	// If empty, no change will be made to attention set.
	AddToAttentionSet gerrit.Whoms
	// AttentionReason describes the reason of the attention change.
	//
	// It is attached to the attention set change, and rendered in UI to explain
	// the reason of the attention to users.
	//
	// This is noop, if AddAttentionSet is empty.
	AttentionReason string
	// LeaseDuration is how long a lease will be held for this reset.
	//
	// If the passed context has a closer deadline, uses that deadline as lease
	// `ExpireTime`.
	LeaseDuration time.Duration
	// ConfigGroups are the ConfigGroups that are watching this CL.
	//
	// They are used to remove votes for additional modes. Normally, there is
	// just 1 ConfigGroup.
	ConfigGroups []*prjcfg.ConfigGroup
	// GFactory is used to create the gerrit client needed to perform the reset.
	GFactory gerrit.Factory
	// CLMutator performs mutations to the CL entity and notifies relevant parts
	// of CV when appropriate.
	CLMutator *changelist.Mutator
}

ResetInput contains info to reset triggers of Run on a CL.

Jump to

Keyboard shortcuts

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