Documentation ¶
Index ¶
- func FormatApplyComment(commentData ApplyCommentData) (string, error)
- func FormatDiffComment(commentData DiffCommentData) (string, error)
- func FormatErrorComment(commentData ErrorCommentData) (string, error)
- func FormatHelpComment(commentData HelpCommentData) (string, error)
- func FormatStatusComment(commentData StatusCommentData) (string, error)
- func GenerateJWT(pemStr string, appID string) (string, error)
- func GetCoveredClusters(repoRoot string, diffs []*github.CommitFile, env string, ...) ([]*config.ClusterConfig, error)
- type AccessToken
- type ApplyCommentData
- type ClusterApply
- type ClusterDiff
- type ClusterStatus
- type DiffCommentData
- type ErrorCommentData
- type FakePullRequestClient
- func (prc *FakePullRequestClient) Approved(ctx context.Context) bool
- func (prc *FakePullRequestClient) Base() string
- func (prc *FakePullRequestClient) BehindBy() int
- func (prc *FakePullRequestClient) Close() error
- func (prc *FakePullRequestClient) GetCoveredClusters(env string, selectedClusterGlobStrs []string, subpathOverride string) ([]*config.ClusterConfig, error)
- func (prc *FakePullRequestClient) HeadSHA() string
- func (prc *FakePullRequestClient) Init(ctx context.Context) error
- func (prc *FakePullRequestClient) IsDraft(ctx context.Context) bool
- func (prc *FakePullRequestClient) IsMergeable(ctx context.Context) bool
- func (prc *FakePullRequestClient) IsMerged(ctx context.Context) bool
- func (prc *FakePullRequestClient) Merge(ctx context.Context) error
- func (prc *FakePullRequestClient) PostComment(ctx context.Context, body string) error
- func (prc *FakePullRequestClient) PostErrorComment(ctx context.Context, env string, err error) error
- func (prc *FakePullRequestClient) Statuses(ctx context.Context) ([]PullRequestStatus, error)
- func (prc *FakePullRequestClient) UpdateStatus(ctx context.Context, state string, stateContext string, description string, ...) error
- type GHPullRequestClient
- func (prc *GHPullRequestClient) Approved(ctx context.Context) bool
- func (prc *GHPullRequestClient) Base() string
- func (prc *GHPullRequestClient) BehindBy() int
- func (prc *GHPullRequestClient) Close() error
- func (prc *GHPullRequestClient) GetCoveredClusters(env string, selectedClusterGlobStrs []string, subpathOverride string) ([]*config.ClusterConfig, error)
- func (prc *GHPullRequestClient) HeadSHA() string
- func (prc *GHPullRequestClient) Init(ctx context.Context) error
- func (prc *GHPullRequestClient) IsDraft(ctx context.Context) bool
- func (prc *GHPullRequestClient) IsMergeable(ctx context.Context) bool
- func (prc *GHPullRequestClient) IsMerged(ctx context.Context) bool
- func (prc *GHPullRequestClient) Merge(ctx context.Context) error
- func (prc *GHPullRequestClient) PostComment(ctx context.Context, body string) error
- func (prc *GHPullRequestClient) PostErrorComment(ctx context.Context, env string, err error) error
- func (prc *GHPullRequestClient) Statuses(ctx context.Context) ([]PullRequestStatus, error)
- func (prc *GHPullRequestClient) UpdateStatus(ctx context.Context, state string, stateContext string, description string, ...) error
- type HelpCommentData
- type PullRequestClient
- type PullRequestStatus
- type StatusCommentData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatApplyComment ¶
func FormatApplyComment(commentData ApplyCommentData) (string, error)
FormatApplyComment generates the body of an apply comment result.
func FormatDiffComment ¶
func FormatDiffComment(commentData DiffCommentData) (string, error)
FormatDiffComment generates the body of a diff comment result.
func FormatErrorComment ¶
func FormatErrorComment(commentData ErrorCommentData) (string, error)
FormatErrorComment generates the body of an error comment result.
func FormatHelpComment ¶
func FormatHelpComment(commentData HelpCommentData) (string, error)
FormatHelpComment generates the body of a help comment result.
func FormatStatusComment ¶
func FormatStatusComment(commentData StatusCommentData) (string, error)
FormatStatusComment generates the body of a status comment result.
func GenerateJWT ¶
GenerateJWT generates a signed JWT for an app. See https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/ for more details.
func GetCoveredClusters ¶
func GetCoveredClusters( repoRoot string, diffs []*github.CommitFile, env string, selectedClusterGlobStrs []string, subpathOverride string, multiSubpaths bool, ) ([]*config.ClusterConfig, error)
GetCoveredClusters returns the configs of all clusters that are "covered" by the provided diffs. The general approach followed is:
- Walk the repo from the root
- Find each cluster config that matches the argument environment
- Get all of the expanded files associated with each config
- Go over all the diffs, mapping them back to the cluster(s) that are configuring them
- Drop any clusters that are not associated with any diffs
- Find the lowest parent among each set of cluster diffs and use this to set the subpath in the associated cluster config or, if multiSubpaths is set to true, all changed subpaths.
There are a few overrides that adjust this behavior:
- selectedClusterGlobStrs: If set, then clusters in this slice are never dropped, even if they don't have have any diffs in them.
- subpathOverride: If set, then this is used for the cluster subpaths instead of the procedure in step 6 above.
Types ¶
type AccessToken ¶
type AccessToken struct { Token string `json:"token"` ExpiresAt time.Time `json:"expires_at"` Permissions map[string]string `json:"permissions"` }
AccessToken wraps the results returned by the Github access_tokens API.
func GenerateAccessToken ¶
func GenerateAccessToken( ctx context.Context, jwt string, installationID string, ) (*AccessToken, error)
GenerateAccessToken uses a JWT to generate an access token in a specific app installation (e.g., organization). See https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/ for more details.
type ApplyCommentData ¶
type ApplyCommentData struct { ClusterApplies []ClusterApply PullRequestClient PullRequestClient Env string }
ApplyCommentData stores data for templating out a "kubeapply apply" comment result.
type ClusterApply ¶
type ClusterApply struct { ClusterConfig *config.ClusterConfig Results []apply.Result }
ClusterApply contains the results of applying in a single cluster.
func (ClusterApply) NumUpdates ¶
func (c ClusterApply) NumUpdates() int
NumUpdates returns the number of updates that were made as part of the apply.
type ClusterDiff ¶
type ClusterDiff struct { ClusterConfig *config.ClusterConfig Results []diff.Result }
ClusterDiff contains the results of a diff in a single cluster.
type ClusterStatus ¶
type ClusterStatus struct { ClusterConfig *config.ClusterConfig HealthSummary string }
ClusterStatus contains the results of getting the status of a cluster.
type DiffCommentData ¶
type DiffCommentData struct { ClusterDiffs []ClusterDiff PullRequestClient PullRequestClient Env string }
DiffCommentData stores data for templating out a "kubeapply diff" comment result.
type ErrorCommentData ¶
ErrorCommentData represents data for templating out a kubeapply error comment result.
type FakePullRequestClient ¶
type FakePullRequestClient struct { ClusterConfigs []*config.ClusterConfig Comments []string RequestStatuses []PullRequestStatus BehindByVal int ApprovedVal bool Draft bool Mergeable bool Merged bool }
FakePullRequestClient is a fake implementation of a PullRequestClient. For testing purposes only.
func (*FakePullRequestClient) Approved ¶
func (prc *FakePullRequestClient) Approved(ctx context.Context) bool
Approved returns whether this pull request is approved.
func (*FakePullRequestClient) Base ¶
func (prc *FakePullRequestClient) Base() string
Base returns the base branch for this pull request.
func (*FakePullRequestClient) BehindBy ¶
func (prc *FakePullRequestClient) BehindBy() int
BehindBy returns the number of commits that this pull request is behind the base by.
func (*FakePullRequestClient) Close ¶
func (prc *FakePullRequestClient) Close() error
Close closes the client.
func (*FakePullRequestClient) GetCoveredClusters ¶
func (prc *FakePullRequestClient) GetCoveredClusters( env string, selectedClusterGlobStrs []string, subpathOverride string, ) ([]*config.ClusterConfig, error)
GetCoveredClusters returns the configs of the clusters that are affected by this pull request.
func (*FakePullRequestClient) HeadSHA ¶
func (prc *FakePullRequestClient) HeadSHA() string
HeadSHA returns the git SHA of the HEAD of the branch on which this pull request is based.
func (*FakePullRequestClient) Init ¶
func (prc *FakePullRequestClient) Init(ctx context.Context) error
Init initializes this client.
func (*FakePullRequestClient) IsDraft ¶
func (prc *FakePullRequestClient) IsDraft(ctx context.Context) bool
IsDraft returns whether this pull request is a draft.
func (*FakePullRequestClient) IsMergeable ¶
func (prc *FakePullRequestClient) IsMergeable(ctx context.Context) bool
IsMergeable returns whether this pull request is mergeable.
func (*FakePullRequestClient) IsMerged ¶
func (prc *FakePullRequestClient) IsMerged(ctx context.Context) bool
IsMerged returns whether this pull request has been merged.
func (*FakePullRequestClient) Merge ¶
func (prc *FakePullRequestClient) Merge( ctx context.Context, ) error
Merge does a fake merge of this pull request.
func (*FakePullRequestClient) PostComment ¶
func (prc *FakePullRequestClient) PostComment(ctx context.Context, body string) error
PostComment posts a fake comment.
func (*FakePullRequestClient) PostErrorComment ¶
func (prc *FakePullRequestClient) PostErrorComment( ctx context.Context, env string, err error, ) error
PostErrorComment posts a fake error comment.
func (*FakePullRequestClient) Statuses ¶
func (prc *FakePullRequestClient) Statuses( ctx context.Context, ) ([]PullRequestStatus, error)
Statuses returns all of the statuses associated with this pull request.
func (*FakePullRequestClient) UpdateStatus ¶
func (prc *FakePullRequestClient) UpdateStatus( ctx context.Context, state string, stateContext string, description string, url string, ) error
UpdateStatus updates a status in this pull request.
type GHPullRequestClient ¶
GHPullRequestClient is an implementation of PullRequestClient that hits the Github API. The actual work of communicating with Github is handled by a go-github client instance.
func NewGHPullRequestClient ¶
func NewGHPullRequestClient( token string, owner string, repo string, pullRequestNum int, ) *GHPullRequestClient
NewGHPullRequestClient returns a new GHPullRequestClient.
func (*GHPullRequestClient) Approved ¶
func (prc *GHPullRequestClient) Approved(ctx context.Context) bool
Approved determines whether this pull request has been approved.
func (*GHPullRequestClient) Base ¶
func (prc *GHPullRequestClient) Base() string
Base returns the base branch for this pull request.
func (*GHPullRequestClient) BehindBy ¶
func (prc *GHPullRequestClient) BehindBy() int
BehindBy returns the number of commits this branch is behind the base by.
func (*GHPullRequestClient) Close ¶
func (prc *GHPullRequestClient) Close() error
Close closes this client.
func (*GHPullRequestClient) GetCoveredClusters ¶
func (prc *GHPullRequestClient) GetCoveredClusters( env string, selectedClusterGlobStrs []string, subpathOverride string, ) ([]*config.ClusterConfig, error)
GetCoveredClusters returns the configs of the clusters potentially affected by this pull request.
func (*GHPullRequestClient) HeadSHA ¶
func (prc *GHPullRequestClient) HeadSHA() string
HeadSHA returns the git SHA of the HEAD of the branch that this pull request is using.
func (*GHPullRequestClient) Init ¶
func (prc *GHPullRequestClient) Init(ctx context.Context) error
Init initializes this client by fetching information about the target pull request from the Github API.
func (*GHPullRequestClient) IsDraft ¶
func (prc *GHPullRequestClient) IsDraft(ctx context.Context) bool
IsDraft returns whether this pull request is a draft.
func (*GHPullRequestClient) IsMergeable ¶
func (prc *GHPullRequestClient) IsMergeable(ctx context.Context) bool
IsMergeable returns whether this pull request is mergeable according to Github.
func (*GHPullRequestClient) IsMerged ¶
func (prc *GHPullRequestClient) IsMerged(ctx context.Context) bool
IsMerged returns whether this pull request has been merged.
func (*GHPullRequestClient) Merge ¶
func (prc *GHPullRequestClient) Merge( ctx context.Context, ) error
Merge merges this pull request via the Github API.
func (*GHPullRequestClient) PostComment ¶
func (prc *GHPullRequestClient) PostComment(ctx context.Context, body string) error
PostComment posts a comment to this pull request using the Github API.
func (*GHPullRequestClient) PostErrorComment ¶
func (prc *GHPullRequestClient) PostErrorComment( ctx context.Context, env string, err error, ) error
PostErrorComment posts an error comment to this pull request using the Github API.
func (*GHPullRequestClient) Statuses ¶
func (prc *GHPullRequestClient) Statuses( ctx context.Context, ) ([]PullRequestStatus, error)
Statuses returns the statuses of all checks for this pull request.
func (*GHPullRequestClient) UpdateStatus ¶
func (prc *GHPullRequestClient) UpdateStatus( ctx context.Context, state string, stateContext string, description string, url string, ) error
UpdateStatus updates the status of the HEAD SHA of the branch in the pull request. Note that the "state" argument must be one of error, failure, pending, or success.
type HelpCommentData ¶
type HelpCommentData struct { ClusterConfigs []*config.ClusterConfig Env string }
HelpCommentData stores data for templating out a "kubeapply help" comment result.
type PullRequestClient ¶
type PullRequestClient interface { // Init initializes the client by cloning the repo, etc. Init(ctx context.Context) error // GetCoveredClusters gets the configs for all clusters "covered" by a pull request. GetCoveredClusters( env string, selectedClusterGlobStrs []string, subpathOverride string, ) ([]*config.ClusterConfig, error) // PostComment posts a non-error comment in the discussion stream for a pull request. PostComment(ctx context.Context, body string) error // PostErrorComment posts an error comment in the discussion stream for a pull request. PostErrorComment( ctx context.Context, env string, err error, ) error // UpdateStatus updates the status of pull request. UpdateStatus( ctx context.Context, state string, stateContext string, description string, url string, ) error // Merge merges the client's pull request into the base branch. Merge(ctx context.Context) error // Statuses gets all statuses for the pull request. Statuses(ctx context.Context) ([]PullRequestStatus, error) // IsDraft returns whether the pull request is a draft. IsDraft(ctx context.Context) bool // IsMerged returns whether the pull request is already merged. IsMerged(ctx context.Context) bool // IsMergeable returns whether the pull request is mergeble. IsMergeable(ctx context.Context) bool // Approved returns whether the client pull request is approved. Approved(ctx context.Context) bool // Base returns the base branch for the pull request. Base() string // BehindBy returns the number of commits that the pull request is behind the base branch by. BehindBy() int // HeadSHA returns the SHA of the head of this pull request. HeadSHA() string // Close cleans up the resources behind this pull request. Close() error }
PullRequestClient is an interface for communicating with a pull request management system, i.e. Github, for a single pull request.
type PullRequestStatus ¶
PullRequestStatus represents the status of a single check on a pull request.
func (PullRequestStatus) IsSuccess ¶
func (prc PullRequestStatus) IsSuccess() bool
IsSuccess returns whether this PullRequestStatus is successful/green.
type StatusCommentData ¶
type StatusCommentData struct { ClusterStatuses []ClusterStatus PullRequestClient PullRequestClient Env string }
StatusCommentData stores data for templating out a "kubeapply status" comment result.