review

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GithubPRApproved is the value GitHub set the `reviewDecision` field to
	// when a Pull Request has been approved by a reviewer.
	GithubPRApproved = "APPROVED"

	// the default approval status we assign to a commit.
	DefaultApprovalStatus = "UNKNOWN"
)

Variables

This section is empty.

Functions

func NewCommitApprovalPipeline

func NewCommitApprovalPipeline(config *CommitApprovalPipelineConfig) *beam.Pipeline

NewCommitApprovalPipeline constructs and returns a *beam.Pipeline to get approval status for commits.

func NewGitHubGraphQLClient

func NewGitHubGraphQLClient(ctx context.Context, accessToken string) *githubv4.Client

Types

type BigQueryBreakGlassIssueFetcher

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

BigQueryBreakGlassIssueFetcher implements the BreakGlassIssueFetcher interface and fetches the break glass issue data from BigQuery.

type BreakGlassIssueDoFn

type BreakGlassIssueDoFn struct {
	// Config is the configuration. Beam will serialize public attributes of the
	// struct when intitializing worker nodes. Thus any attribute that should be
	// serialized needs to be public.
	Config *CommitApprovalPipelineConfig
	// contains filtered or unexported fields
}

BreakGlassIssueDoFn is an object that implements beams "DoFn" interface to provide the processing logic for converting retrieving the associated break glass issue for a CommitReviewStatus.

func (*BreakGlassIssueDoFn) ProcessElement

func (fn *BreakGlassIssueDoFn) ProcessElement(ctx context.Context, commitReviewStatus CommitReviewStatus, emit func(status CommitReviewStatus))

ProcessElement is a DoFn implementation that takes a CommitReviewStatus and populates its breakGlassIssue field (if necessary) and then emits it using the given emit function. The process only searches for break glass issues for commits that do not have the status GithubPRApproved.

func (*BreakGlassIssueDoFn) StartBundle

func (fn *BreakGlassIssueDoFn) StartBundle(ctx context.Context, _ func(CommitReviewStatus)) error

StartBundle is called by Beam when the DoFn function is initialized. With a local runner this is called from the running version of the application. For Dataflow, this is called on each worker node after the binary is provisioned. Remote Dataflow workers do not have the same environment or runtime arguments as the launcher process. The CommitApprovalDoFn struct is serialized to the worker along with all public attributes that can be serialized. This causes us to have to initialize the bigQueryClient from this method once it has materialized on the remote host. Since ProcessElement uses an emit function, we are required by Beam to accept one in StartBundle as well even though it is not used.

type BreakGlassIssueFetcher

type BreakGlassIssueFetcher interface {
	// contains filtered or unexported methods
}

BreakGlassIssueFetcher fetches break glass issues from a data source.

type Commit

type Commit struct {
	Author       string `bigquery:"author"`
	Organization string `bigquery:"organization"`
	Repository   string `bigquery:"repository"`
	Branch       string `bigquery:"branch"`
	SHA          string `bigquery:"commit_sha"`

	// Timestamp will be in ISO 8601 format (https://en.wikipedia.org/wiki/ISO_8601)
	// and should be parsable using time.RFC3339 format
	Timestamp string `bigquery:"commit_timestamp"`
}

Commit maps the columns from the driving BigQuery query to a usable structure.

type CommitApprovalDoFn

type CommitApprovalDoFn struct {
	// Config is the configuration. Beam will serialize public attributes of the
	// struct when intitializing worker nodes. Thus any attribute that should be
	// serialized needs to be public.
	Config *CommitApprovalPipelineConfig
	// contains filtered or unexported fields
}

CommitApprovalDoFn is an object that implements beams "DoFn" interface to provide the processing logic for converting a Commit to CommitReviewStatus.

func (*CommitApprovalDoFn) ProcessElement

func (fn *CommitApprovalDoFn) ProcessElement(ctx context.Context, commit Commit, emit func(CommitReviewStatus))

ProcessElement is a DoFn implementation that take a Commit, determines if the commit was properly approved, and outputs the resulting CommitReviewStatus using the provided emit function. A commit is considered properly reviewed as long as there is an associated PR for the commit targeting the repository's main branch with reviewDecision of 'APPROVED'.

func (*CommitApprovalDoFn) StartBundle

func (fn *CommitApprovalDoFn) StartBundle(ctx context.Context, _ func(CommitReviewStatus)) error

StartBundle is called by Beam when the DoFn function is initialized. With a local runner this is called from the running version of the application. For Dataflow, this is called on each worker node after the binary is provisioned. Remote Dataflow workers do not have the same environment or runtime arguments as the launcher process. The CommitApprovalDoFn struct is serialized to the worker along with all public attributes that can be serialized. This causes us to have to initialize the githubClient from this method once it has materialized on the remote host. Since ProcessElement uses an emit function, we are required by Beam to accept one in StartBundle as well even though it is not used.

type CommitApprovalPipelineConfig

type CommitApprovalPipelineConfig struct {
	// GitHubToken is the GitHub Token to use for authentication
	GitHubToken string

	// PushEventsTable is the fully qualified name of the BigQuery table that
	// holds push event data. This is the table that is used to source the commits
	// that need to be processed.
	PushEventsTable *bigqueryio.QualifiedTableName

	// CommitReviewStatusTable is the fully qualified name of the BigQuery table
	// that holds the commit review/approval status. This is the table that stores
	// the final output of the pipeline.
	CommitReviewStatusTable *bigqueryio.QualifiedTableName

	// IssuesTable is the fully qualified name of the BigQuery table that holds GitHub issue
	// data. This table is used to determine if a commit was pushed using
	// 'break glass' permissions.
	IssuesTable *bigqueryio.QualifiedTableName
}

CommitApprovalPipelineConfig holds the configuration data for the commit approval beam pipeline.

type CommitReviewStatus

type CommitReviewStatus struct {
	Commit
	HTMLURL            string   `bigquery:"commit_html_url"`
	PullRequestID      int      `bigquery:"pull_request_id"`
	PullRequestNumber  int      `bigquery:"pull_request_number"`
	PullRequestHTMLURL string   `bigquery:"pull_request_html_url"`
	ApprovalStatus     string   `bigquery:"approval_status"`
	BreakGlassURLs     []string `bigquery:"break_glass_issue_urls"`
	Note               string   `bigquery:"note"`
}

CommitReviewStatus maps the columns of the 'commit_review_status` table in BigQuery.

type PullRequest

type PullRequest struct {
	// BasRefName is the target the PR is being merged into. For example,
	// If a PR is being opened to merge the code from feature branch 'my-feature'
	// into branch 'main', then BasRefName for this PR would be 'main'.
	BaseRefName    githubv4.String
	DatabaseID     githubv4.Int
	Number         githubv4.Int
	ReviewDecision githubv4.String
	URL            githubv4.String
}

PullRequest represents a pull request in GitHub and contains the GitHub assigned ID, the pull request number in the repository, and the review decision for the pull request.

func GetPullRequestsTargetingDefaultBranch

func GetPullRequestsTargetingDefaultBranch(ctx context.Context, client *githubv4.Client, githubOrg, repository, commitSha string) ([]*PullRequest, error)

GetPullRequestsTargetingDefaultBranch retrieves all associated pull requests for a commit that target the repository's default branch from GitHub based on the given GitHub organization, repository, and commit sha. If the commit has no such associated pull requests then an empty slice is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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