app

package
v0.0.0-...-f58e54c Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigItemString indicates a config item that is expected to be a string.
	ConfigItemString = configItemType(iota)
	// ConfigItemInt indicates a config item that is expected to be an integer.
	ConfigItemInt
	// ConfigItemChannel indicates a config item that is expected to be a chat channel.
	ConfigItemChannel
	// ConfigItemUserList indicates a config item that is expected to be a list of user chat IDs.
	ConfigItemUserList
	// ConfigItemLink indicates a config item that is expected to be a URL.
	ConfigItemLink
	// ConfigItemBool indicates a config item that is expected to be a boolean.
	ConfigItemBool
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App represents the Changeset Chihuahua application for a particular team.

func New

func New(ctx context.Context, logger *zap.Logger, chat slack.EventedChatSystem, chatFormatter messages.ChatSystemFormatter, persistentDB *PersistentDB, gerritConnector gerritConnector) *App

New creates a new App instance.

func (*App) AssigneeChanged

func (a *App) AssigneeChanged(_ context.Context, _ events.Account, _ events.Change, _ events.Account)

AssigneeChanged is called when we receive a Gerrit assignee-changed event.

func (*App) ChangeAbandoned

func (a *App) ChangeAbandoned(ctx context.Context, abandoner events.Account, change events.Change, reason string)

ChangeAbandoned is called when we receive a Gerrit change-abandoned event.

func (*App) ChangeMerged

func (a *App) ChangeMerged(ctx context.Context, submitter events.Account, change events.Change, patchSet events.PatchSet)

ChangeMerged is called when we receive a Gerrit change-merged event.

func (*App) ChangeRestored

func (a *App) ChangeRestored(ctx context.Context, restorer events.Account, change events.Change, patchSet events.PatchSet, reason string)

ChangeRestored is called when we receive a Gerrit change-restored event.

func (*App) ChatEvent

func (a *App) ChatEvent(ctx context.Context, eventObj slack.ChatEvent) error

ChatEvent is called when a chat event has been received related to this team.

func (*App) Close

func (a *App) Close() error

Close closes an App, freeing its resources.

func (*App) CommentAdded

func (a *App) CommentAdded(ctx context.Context, author events.Account, change events.Change, patchSet events.PatchSet, comment string, eventTime time.Time)

CommentAdded is called when we receive a Gerrit comment-added event.

Because we are dealing with software, and software is terrible, the events that come from the Gerrit webhooks plugin do not contain any info about inline comments. We have to get the info from the API.

Worse, there is apparently _no_ reliable way to identify which inline comments are associated with this "comment-added" event. We could fudge it by using the timestamps, but we'd be bound to get too many inline comments or too few in certain cases, depending on our implementation. Instead of opening that pandora's box of confusion, we will try to keep track of which inline comments we have seen before. Luckily, they do all have unique identifiers.

Notification rules:

  • If change owner has posted a top-level comment, notify all the reviewers.
  • If someone else has posted a top-level comment, notify change owner.
  • For all new inline comments, notify the change owner and all prior thread participants (except for the commenter).

func (*App) ConfigureGerritServer

func (a *App) ConfigureGerritServer(ctx context.Context, gerritAddress string) error

ConfigureGerritServer updates the Gerrit server being used for this team, opening a new Gerrit client. If there is already a Gerrit client handle open, it is closed first.

func (*App) GerritEvent

func (a *App) GerritEvent(ctx context.Context, event events.GerritEvent)

GerritEvent is called when a Gerrit event has been received related to this team.

func (*App) IncomingChatCommand

func (a *App) IncomingChatCommand(userID, chanID string, isDM bool, text string) (reply string)

IncomingChatCommand gets called by the ChatSystem when the bot sees a chat message. This might be a message in a channel that the bot is in, or it might be a direct message (isDM). If this returns a non-empty string, it will be sent to the original channel (or DM session) as a reply.

func (*App) JenkinsRobotCommentAdded

func (a *App) JenkinsRobotCommentAdded(ctx context.Context, change events.Change, patchSet events.PatchSet, comment string) bool

JenkinsRobotCommentAdded is called when the Jenkins robot adds a comment to a Gerrit change.

func (*App) PatchSetCreated

func (a *App) PatchSetCreated(ctx context.Context, uploader events.Account, change events.Change, patchSet events.PatchSet)

PatchSetCreated is called when we receive a Gerrit patchset-created event.

func (*App) PeriodicPersonalReports

func (a *App) PeriodicPersonalReports(ctx context.Context, getTime func() time.Time) error

PeriodicPersonalReports schedules and issues all personal Gerrit reports.

func (*App) PeriodicTeamReports

func (a *App) PeriodicTeamReports(ctx context.Context, getTime func() time.Time) error

PeriodicTeamReports schedules and issues all configured periodic team Gerrit reports.

func (*App) PersonalReportToUser

func (a *App) PersonalReportToUser(ctx context.Context, logger *zap.Logger, now, cutOffTime time.Time, acct *gerrit.AccountInfo)

PersonalReportToUser looks up information on the given user, and if it is an appropriate time, sends them a report on the changesets currently waiting for their review.

Note this is pretty inefficient with respect to execution time and data transferred. Since I don't expect this to be dealing with very large amounts of data, and performance is very non-critical here, I would rather let it be a little slow as a simplistic way of keeping down the load on the chat and Gerrit servers. If this needs to be snappier, though, this is probably a good place to start parallelizing.

func (*App) PersonalReports

func (a *App) PersonalReports(ctx context.Context, t time.Time)

PersonalReports builds and issues personal Gerrit reports to all users who are due for reports.

func (*App) ReviewerAdded

func (a *App) ReviewerAdded(ctx context.Context, reviewer events.Account, change events.Change, eventTime time.Time)

ReviewerAdded is called when we receive a Gerrit reviewer-added event.

func (*App) TeamReport

func (a *App) TeamReport(ctx context.Context, t time.Time, config reportConfig)

TeamReport builds and sends a team Gerrit report.

func (*App) TopicChanged

func (a *App) TopicChanged(ctx context.Context, changer events.Account, change events.Change)

TopicChanged is called when we receive a Gerrit topic-changed event.

func (*App) VoteDeleted

func (a *App) VoteDeleted(ctx context.Context, reviewer events.Account, remover events.Account, change events.Change, patchSet events.PatchSet, approval events.Approval)

VoteDeleted is called when a Gerrit vote has been deleted.

func (*App) WipStateChanged

func (a *App) WipStateChanged(ctx context.Context, changer events.Account, change events.Change, _ events.PatchSet)

WipStateChanged is called when we receive a Gerrit topic-changed event.

type PersistentDB

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

PersistentDB represents a persistent database attached to a specific team.

func NewPersistentDB

func NewPersistentDB(logger *zap.Logger, dbSource string) (*PersistentDB, error)

NewPersistentDB creates a new PersistentDB instance.

func (*PersistentDB) AssociateChatIDWithGerritUser

func (ud *PersistentDB) AssociateChatIDWithGerritUser(ctx context.Context, gerritUsername, chatID string) error

AssociateChatIDWithGerritUser associates a chat ID with a Gerrit username, storing that association in the persistent DB for future reference.

func (*PersistentDB) Close

func (ud *PersistentDB) Close() error

Close closes a PersistentDB.

func (*PersistentDB) GetAllConfigItems

func (ud *PersistentDB) GetAllConfigItems(ctx context.Context) (map[string]string, error)

GetAllConfigItems gets all config items for this team and returns them as a map of config key to config value.

func (*PersistentDB) GetAllUsersWhoseLastReportWasBefore

func (ud *PersistentDB) GetAllUsersWhoseLastReportWasBefore(ctx context.Context, t time.Time) ([]*dbx.GerritUser, error)

GetAllUsersWhoseLastReportWasBefore gets all users whose last report was before the specified time.

func (*PersistentDB) GetConfig

func (ud *PersistentDB) GetConfig(ctx context.Context, key, defaultValue string) (string, error)

GetConfig gets the value of a config item for this team and returns it as a string. If the config item does not exist or can not be read, defaultValue is returned instead, along with any error encountered along the way.

func (*PersistentDB) GetConfigBool

func (ud *PersistentDB) GetConfigBool(ctx context.Context, key string, defaultValue bool) (bool, error)

GetConfigBool gets the value of a config item for this team, parses it as a boolean, and returns the value. If the config item does not exist or can not be read or parsed as a boolean, defaultValue is returned instead, along with any error encountered along the way.

func (*PersistentDB) GetConfigInt

func (ud *PersistentDB) GetConfigInt(ctx context.Context, key string, defaultValue int) (int, error)

GetConfigInt gets the value of a config item for this team, parses it as an integer, and returns the value. If the config item does not exist or can not be read or parsed as an integer, defaultValue is returned instead, along with any error encountered along the way.

func (*PersistentDB) GetConfigWildcard

func (ud *PersistentDB) GetConfigWildcard(ctx context.Context, pattern string) (items map[string]string, err error)

GetConfigWildcard gets all config items and their associated values where the config items match the specified LIKE pattern. The items are returned as a map of config key to config value.

func (*PersistentDB) GetPatchSetAnnouncements

func (ud *PersistentDB) GetPatchSetAnnouncements(ctx context.Context, projectName string, changeNum, patchSetNum int) ([]string, error)

GetPatchSetAnnouncements looks up all announcements made about a particular patchset on a particular change, and returns the associated message handle(s).

func (*PersistentDB) IdentifyNewInlineComments

func (ud *PersistentDB) IdentifyNewInlineComments(ctx context.Context, commentsByID map[string]time.Time) (err error)

IdentifyNewInlineComments accepts a map of comment_id to time, and determines which of them are already known in the database. Those which are not already known are inserted into the inline_comments table with their associated times.

func (*PersistentDB) JustGetConfig

func (ud *PersistentDB) JustGetConfig(ctx context.Context, key, defaultValue string) string

JustGetConfig gets the value of a config item for this team and returns it as a string. If the config item does not exist, defaultValue is returned instead. If the config item can not be read, the error is logged, and defaultValue is returned.

func (*PersistentDB) JustGetConfigBool

func (ud *PersistentDB) JustGetConfigBool(ctx context.Context, key string, defaultValue bool) bool

JustGetConfigBool gets the value of a config item for this team, parses it as a boolean, and returns the value. If the config item does not exist, defaultValue is returned instead. If the config item can not be read or parsed as a boolean, the error is logged, and defaultValue is returned.

func (*PersistentDB) JustGetConfigInt

func (ud *PersistentDB) JustGetConfigInt(ctx context.Context, key string, defaultValue int) int

JustGetConfigInt gets the value of a config item for this team, parses it as an integer, and returns the value. If the config item does not exist, defaultValue is returned instead. If the config item can not be read or parsed as an integer, the error is logged, and defaultValue is returned.

func (*PersistentDB) JustGetConfigWildcard

func (ud *PersistentDB) JustGetConfigWildcard(ctx context.Context, pattern string) map[string]string

JustGetConfigWildcard gets all config items and their associated values where the config items match the specified LIKE pattern. The items are returned as a map of config key to config value. If an error is encountered trying to read the config items, the error is logged, and a nil map is returned.

func (*PersistentDB) LookupChatIDForGerritUser

func (ud *PersistentDB) LookupChatIDForGerritUser(ctx context.Context, gerritUsername string) (string, error)

LookupChatIDForGerritUser tries to determine the corresponding chat ID for a given Gerrit username. A cache is checked first, then the persistent DB is checked if necessary.

func (*PersistentDB) LookupGerritUser

func (ud *PersistentDB) LookupGerritUser(ctx context.Context, gerritUsername string) (*dbx.GerritUser, error)

LookupGerritUser checks whether this PersistentDB already knows about the specified Gerrit username, and if so, what do we know about it.

func (*PersistentDB) Prune

func (ud *PersistentDB) Prune(ctx context.Context, now time.Time) error

Prune removes all records of old patchset announcements and inline comments, so the db does not grow indefinitely.

func (*PersistentDB) RecordPatchSetAnnouncements

func (ud *PersistentDB) RecordPatchSetAnnouncements(ctx context.Context, projectName string, changeNum, patchSetNum int, announcementHandles []string) error

RecordPatchSetAnnouncements records making announcements about a particular patchset on a particular change, so they can be looked up later by GetPatchSetAnnouncements.

func (*PersistentDB) SetConfig

func (ud *PersistentDB) SetConfig(ctx context.Context, key, value string) error

SetConfig stores a config item with the specified value.

func (*PersistentDB) SetConfigInt

func (ud *PersistentDB) SetConfigInt(ctx context.Context, key string, value int) error

SetConfigInt stores a config item with the specified value, encoded as a decimal integer.

func (*PersistentDB) UpdateLastReportTime

func (ud *PersistentDB) UpdateLastReportTime(ctx context.Context, gerritUsername string, when time.Time) error

UpdateLastReportTime updates the stored last report time for a given Gerrit username.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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