review

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GithubPRApproved is the approving review status indicating the PR
	// is approved to be merged.
	GithubPRApproved = "APPROVED"

	// GithubPRReviewRequired is the default review status of a PR indicating
	// the PR requires a review.
	GithubPRReviewRequired = "REVIEW_REQUIRED"

	// GithubPRChangesRequested is a blocking review status indicating that
	// changes need to be made to the PR code.
	GithubPRChangesRequested = "CHANGES_REQUESTED"

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

Variables

This section is empty.

Functions

func ExecuteJob added in v0.0.26

func ExecuteJob(ctx context.Context, cfg *Config) error

ExecuteJob runs the pipeline job to read GitHub commits to check if they were properly reviewed.

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 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"`
	Visibility   string `bigquery:"visibility"`
	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 time.Time `bigquery:"commit_timestamp"`
}

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

type CommitGraphQlQuery added in v0.0.20

type CommitGraphQlQuery struct {
	Repository struct {
		DefaultBranchRef struct {
			Name githubv4.String
		}
		Object struct {
			Commit struct {
				AssociatedPullRequest struct {
					Nodes      []*PullRequest
					PageInfo   *PageInfo
					TotalCount githubv4.Int
				} `graphql:"associatedPullRequests(first: 100, after: $pullRequestCursor)"`
			} `graphql:"... on Commit"`
		} `graphql:"object(oid: $commitSha)"`
	} `graphql:"repository(owner: $githubOrg, name: $repository)"`
}

CommitGraphQlQuery is struct that maps to the GitHub GraphQLQuery that fetches all the PRs and associated PR reviews for a commit sha.

type CommitReviewStatus

type CommitReviewStatus struct {
	*Commit
	HTMLURL            string   `bigquery:"commit_html_url"`
	PullRequestID      int64    `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 Config added in v0.0.26

type Config struct {
	GitHubAppID            string `env:"GITHUB_APP_ID,required"`             // The GitHub App ID
	GitHubInstallID        string `env:"GITHUB_INSTALL_ID,required"`         // The provisioned GitHub App Installation reference
	GitHubPrivateKeySecret string `env:"GITHUB_PRIVATE_KEY_SECRET,required"` // The secret name & version containing the GitHub App private key

	ProjectID string `env:"PROJECT_ID,required"` // The project id where the tables live
	DatasetID string `env:"DATASET_ID,required"` // The dataset id where the tables live

	PushEventsTableID         string `env:"PUSH_EVENTS_TABLE_ID,required"`          // The table_name of the push events table
	CommitReviewStatusTableID string `env:"COMMIT_REVIEW_STATUS_TABLE_ID,required"` // The table_name of the commit_review_status table
	IssuesTableID             string `env:"ISSUES_TABLE_ID,required"`               // The table_name of the issues table
}

Config defines the set of environment variables required for running the artifact job.

func NewConfig added in v0.0.26

func NewConfig(ctx context.Context) (*Config, error)

NewConfig creates a new Config from environment variables.

func (*Config) ToFlags added in v0.0.26

func (cfg *Config) ToFlags(set *cli.FlagSet) *cli.FlagSet

ToFlags binds the config to the cli.FlagSet and returns it.

func (*Config) Validate added in v0.0.26

func (cfg *Config) Validate() error

Validate validates the artifacts config after load.

type PageInfo added in v0.0.20

type PageInfo struct {
	HasNextPage     githubv4.Boolean
	HasPreviousPage githubv4.Boolean
	EndCursor       githubv4.String
	StartCursor     githubv4.String
}

PageInfo represents a pagination info in GitHub's GraphQL API. For all potential fields see: https://docs.github.com/en/graphql/reference/objects#pageinfo

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
	FullDatabaseID githubv4.String
	Number         githubv4.Int
	Reviews        struct {
		Nodes    []*Review
		PageInfo *PageInfo
	} `graphql:"reviews(first: 100, after: $reviewCursor)"`
	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. For all potential fields see: https://docs.github.com/en/graphql/reference/objects#pullrequest

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.

type Review added in v0.0.16

type Review struct {
	State githubv4.String
}

Review represents a pull request review in GitHub's GraphQL API. For all potential fields see: https://docs.github.com/en/graphql/reference/objects#pullrequestreview

Jump to

Keyboard shortcuts

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