cancel

package
v0.0.0-...-8a57daa Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package cancel implements cancelling triggers of Run by removing CQ Votes on a CL.

Index

Constants

This section is empty.

Variables

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

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

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

ErrPreconditionFailedTag is an error tag indicating that Cancel precondition failed.

Functions

func Cancel

func Cancel(ctx context.Context, in Input) error

Cancel 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 cancellations:

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 Input

type Input 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 cancellation.
	//
	// 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 cancellation.
	//
	// 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 cancellation.
	//
	// 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
	// RunCLExternalIDs are IDs of all CLs involved in the Run.
	//
	// It will be included in `botdata.BotData` and posted to Gerrit as part of
	// the message in "unhappy path". See doc for `Cancel()`
	//
	// TODO(yiwzhang): consider dropping after M1 is launched if it is not adding
	// any value to include those IDs in the bot data.
	RunCLExternalIDs []changelist.ExternalID
	// GFactory is used to create the gerrit client needed to perform the
	// cancellation.
	GFactory gerrit.Factory
	// CLMutator performs mutations to the CL entity and notifies relevant parts
	// of CV when appropriate.
	CLMutator *changelist.Mutator
}

Input contains info to cancel triggers of Run on a CL.

Jump to

Keyboard shortcuts

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