tide

package
v0.0.0-...-37c3036 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package tide contains a controller for managing a tide pool of PRs. The controller will automatically retest PRs in the pool and merge them if they pass tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action represents what actions the controller can take. It will take exactly one action each sync.

const (
	Wait         Action = "WAIT"
	Trigger      Action = "TRIGGER"
	TriggerBatch Action = "TRIGGER_BATCH"
	Merge        Action = "MERGE"
	MergeBatch   Action = "MERGE_BATCH"
	PoolBlocked  Action = "BLOCKED"
)

Constants for various actions the controller might take

type CheckRun

type CheckRun struct {
	Name       githubql.String
	Conclusion githubql.String
	Status     githubql.String
}

type CheckRunNode

type CheckRunNode struct {
	CheckRun CheckRun `graphql:"... on CheckRun"`
}

type CodeReviewCommon

type CodeReviewCommon struct {
	// NameWithOwner is from graphql.NameWithOwner, <org>/<repo>
	NameWithOwner string
	// The number of PR
	Number int
	Org    string
	Repo   string
	// BaseRefPrefix gets prefix of ref, such as /refs/head, /refs/tags
	BaseRefPrefix string
	BaseRefName   string
	HeadRefName   string
	HeadRefOID    string

	Title string
	Body  string
	// AuthorLogin is the author login from the fork on GitHub, this will be the
	// author login from Gerrit.
	AuthorLogin   string
	UpdatedAtTime time.Time

	Mergeable string

	GitHub *PullRequest
	Gerrit *gerrit.ChangeInfo
}

func CodeReviewCommonFromGerrit

func CodeReviewCommonFromGerrit(gci *gerrit.ChangeInfo, instance string) *CodeReviewCommon

CodeReviewCommonFromGerrit derives CodeReviewCommon struct from Gerrit ChangeInfo struct, by extracting shared fields among different code review providers.

Gerrit ChangeInfo doesn't know which host it's from, which makes sense, as host for Gerrit is like `github.com` for GitHub, so it's required to be passed in by caller.

func CodeReviewCommonFromPullRequest

func CodeReviewCommonFromPullRequest(pr *PullRequest) *CodeReviewCommon

CodeReviewCommonFromPullRequest derives CodeReviewCommon struct from GitHub PullRequest struct, by extracting shared fields among different code review providers.

func (*CodeReviewCommon) GitHubCommits

func (crc *CodeReviewCommon) GitHubCommits() *Commits

GitHubCommits returns Commits struct from GitHub.

This is used by checking status context to determine whether the PR is ready for merge or not.

func (*CodeReviewCommon) GitHubLabels

func (crc *CodeReviewCommon) GitHubLabels() *Labels

GitHubLabels returns labels struct for GitHub, using this function is almost equivalent to `if isGitHub() {// then do that}`.

This is useful for determining the merging strategy.

type CodeReviewForDeck

type CodeReviewForDeck struct {
	Title      string
	Number     int
	HeadRefOID string
	Mergeable  string
}

CodeReviewForDeck contains superset of data from CodeReviewCommon, it's meant to be consumed by deck only.

Tide serves Pool data to deck via http request inside cluster, which could contain many PullRequests, sending over full PullRequest struct could be very expensive in some cases.

func FromCodeReviewCommonToCodeReviewForDeck

func FromCodeReviewCommonToCodeReviewForDeck(crc *CodeReviewCommon) *CodeReviewForDeck

type Commit

type Commit struct {
	Status            CommitStatus
	OID               githubql.String `graphql:"oid"`
	StatusCheckRollup StatusCheckRollup
}

Commit holds graphql data about commits and which contexts they have

type CommitNode

type CommitNode struct {
	Commit Commit
}

type CommitStatus

type CommitStatus struct {
	Contexts []Context
}

type Commits

type Commits struct {
	Nodes []struct {
		Commit Commit
	}
}

type Context

type Context struct {
	// Context is the name of the context, it's identical to the full name of a
	// prowjob if the context is for a prowjob.
	Context githubql.String
	// Description is the description for a context, it's formed by
	// config.ContextDescriptionWithBaseSha for a prowjob.
	Description githubql.String
	// State is the state for a prowjob: EXPECTED, ERROR, FAILURE, PENDING, SUCCESS.
	State githubql.StatusState
}

Context holds graphql response data for github contexts.

type Controller

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

func NewController

func NewController(
	ghcSync,
	ghcStatus github.Client,
	mgr manager,
	cfg config.Getter,
	gc git.ClientFactory,
	maxRecordsPerPool int,
	opener io.Opener,
	historyURI,
	statusURI string,
	logger *logrus.Entry,
	usesGitHubAppsAuth bool,
) (*Controller, error)

NewController makes a Controller out of the given clients.

func NewGerritController

func NewGerritController(
	mgr manager,
	cfgAgent *config.Agent,
	gc git.ClientFactory,
	maxRecordsPerPool int,
	opener io.Opener,
	historyURI,
	statusURI string,
	logger *logrus.Entry,
	configOptions configflagutil.ConfigOptions,
	cookieFilePath string,
	maxQPS, maxBurst int,
) (*Controller, error)

NewController makes a Controller out of the given clients.

func (*Controller) History

func (c *Controller) History() *history.History

func (*Controller) ServeHTTP

func (c *Controller) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Controller) Shutdown

func (c *Controller) Shutdown()

Shutdown signals the statusController to stop working and waits for it to finish its last update loop before terminating. Controller.Sync() should not be used after this function is called.

func (*Controller) Sync

func (c *Controller) Sync() error

type GerritProvider

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

GerritProvider implements provider, used by Tide Controller for interacting directly with Gerrit.

Tide Controller should only use GerritProvider for communicating with Gerrit.

func (*GerritProvider) GetChangedFiles

func (p *GerritProvider) GetChangedFiles(org, repo string, number int) ([]string, error)

func (*GerritProvider) GetPresubmits

func (p *GerritProvider) GetPresubmits(identifier, baseBranch string, baseSHAGetter config.RefGetter, headSHAGetters ...config.RefGetter) ([]config.Presubmit, error)

GetPresubmits gets presubmit jobs for a PR.

(TODO:chaodaiG): deduplicate this with GitHub, which means inrepoconfig processing all use cache client.

func (*GerritProvider) GetRef

func (p *GerritProvider) GetRef(org, repo, ref string) (string, error)

GetRef gets the latest revision from org/repo/branch.

func (*GerritProvider) GetTideContextPolicy

func (p *GerritProvider) GetTideContextPolicy(org, repo, branch string, baseSHAGetter config.RefGetter, crc *CodeReviewCommon) (contextChecker, error)

GetTideContextPolicy returns an empty config.TideContextPolicy struct.

These information are only for determining whether a PR is ready for merge or not, this in Gerrit is handled by Gerrit query filters, so this is not useful for Gerrit.

func (*GerritProvider) Query

func (p *GerritProvider) Query() (map[string]CodeReviewCommon, error)

Query returns all PRs from configured Gerrit org/repos.

type GitHubProvider

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

GitHubProvider implements provider, used by tide Controller for interacting directly with GitHub.

Tide Controller should only use GitHubProvider for communicating with GitHub.

func (*GitHubProvider) GetChangedFiles

func (gi *GitHubProvider) GetChangedFiles(org, repo string, number int) ([]string, error)

func (*GitHubProvider) GetPresubmits

func (gi *GitHubProvider) GetPresubmits(identifier, baseBranch string, baseSHAGetter config.RefGetter, headSHAGetters ...config.RefGetter) ([]config.Presubmit, error)

func (*GitHubProvider) GetRef

func (gi *GitHubProvider) GetRef(org, repo, ref string) (string, error)

func (*GitHubProvider) GetTideContextPolicy

func (gi *GitHubProvider) GetTideContextPolicy(org, repo, branch string, baseSHAGetter config.RefGetter, pr *CodeReviewCommon) (contextChecker, error)

func (*GitHubProvider) Query

func (gi *GitHubProvider) Query() (map[string]CodeReviewCommon, error)

Query gets all open PRs based on tide configuration.

type Labels

type Labels struct {
	Nodes []struct {
		Name githubql.String
	}
}

type Milestone

type Milestone struct {
	Title githubql.String
}

type MinCodeReviewCommon

type MinCodeReviewCommon CodeReviewCommon

MinCodeReviewCommon can be casted into full CodeReviewCommon, which will result in json marshal/unmarshal overrides.

This should be used only right before serialization, and for now it's consumed only by Deck.

func (*MinCodeReviewCommon) MarshalJSON

func (m *MinCodeReviewCommon) MarshalJSON() ([]byte, error)

MarshalJSON marshals MinCodeReviewCommon into CodeReviewForDeck

func (*MinCodeReviewCommon) UnmarshalJSON

func (m *MinCodeReviewCommon) UnmarshalJSON(b []byte) error

UnmarshalJSON overrides unmarshal function, the marshalled bytes should only be used by Typescript for now

type PRNode

type PRNode struct {
	PullRequest PullRequest `graphql:"... on PullRequest"`
}

type Pool

type Pool struct {
	Org    string
	Repo   string
	Branch string

	// PRs with passing tests, pending tests, and missing or failed tests.
	// Note that these results are rolled up. If all tests for a PR are passing
	// except for one pending, it will be in PendingPRs.
	SuccessPRs []CodeReviewCommon
	PendingPRs []CodeReviewCommon
	MissingPRs []CodeReviewCommon

	// Empty if there is no pending batch.
	BatchPending []CodeReviewCommon

	// Which action did we last take, and to what target(s), if any.
	Action   Action
	Target   []CodeReviewCommon
	Blockers []blockers.Blocker
	Error    string

	// All of the TenantIDs associated with PRs in the pool.
	TenantIDs []string
}

Pool represents information about a tide pool. There is one for every org/repo/branch combination that has PRs in the pool.

type PoolForDeck

type PoolForDeck struct {
	Org    string
	Repo   string
	Branch string

	// PRs with passing tests, pending tests, and missing or failed tests.
	// Note that these results are rolled up. If all tests for a PR are passing
	// except for one pending, it will be in PendingPRs.
	SuccessPRs []MinCodeReviewCommon
	PendingPRs []MinCodeReviewCommon
	MissingPRs []MinCodeReviewCommon

	// Empty if there is no pending batch.
	BatchPending []MinCodeReviewCommon

	// Which action did we last take, and to what target(s), if any.
	Action   Action
	Target   []MinCodeReviewCommon
	Blockers []blockers.Blocker
	Error    string

	// All of the TenantIDs associated with PRs in the pool.
	TenantIDs []string
}

PoolForDeck contains the same data as Pool, the only exception is that it has a minified version of CodeReviewCommon which is good for deck, as MinCodeReview is a very small superset of CodeReviewCommon.

func PoolToPoolForDeck

func PoolToPoolForDeck(p *Pool) *PoolForDeck

type PullRequest

type PullRequest struct {
	Number githubql.Int
	Author struct {
		Login githubql.String
	}
	BaseRef struct {
		Name   githubql.String
		Prefix githubql.String
	}
	HeadRefName  githubql.String `graphql:"headRefName"`
	HeadRefOID   githubql.String `graphql:"headRefOid"`
	Mergeable    githubql.MergeableState
	CanBeRebased githubql.Boolean `graphql:"canBeRebased"`
	Repository   struct {
		Name          githubql.String
		NameWithOwner githubql.String
		Owner         struct {
			Login githubql.String
		}
	}
	ReviewDecision githubql.PullRequestReviewDecision `graphql:"reviewDecision"`
	// Request the 'last' 4 commits hoping that one of them is the logically 'last'
	// commit with OID matching HeadRefOID. If we don't find it we have to use an
	// additional API token. (see the 'headContexts' func for details)
	// We can't raise this too much or we could hit the limit of 50,000 nodes
	// per query: https://developer.github.com/v4/guides/resource-limitations/#node-limit
	Commits   Commits `graphql:"commits(last: 4)"`
	Labels    Labels  `graphql:"labels(first: 100)"`
	Milestone *Milestone
	Body      githubql.String
	Title     githubql.String
	UpdatedAt githubql.DateTime
}

PullRequest holds graphql data about a PR, including its commits and their contexts. This struct is GitHub specific

type StatusCheckRollup

type StatusCheckRollup struct {
	Contexts StatusCheckRollupContext `graphql:"contexts(last: 100)"`
}

type StatusCheckRollupContext

type StatusCheckRollupContext struct {
	Nodes []CheckRunNode
}

Directories

Path Synopsis
Package history provides an append only, size limited log of recent actions that Tide has taken for each subpool.
Package history provides an append only, size limited log of recent actions that Tide has taken for each subpool.

Jump to

Keyboard shortcuts

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