Documentation ¶
Index ¶
- Constants
- func AttributeFromContext(ctx context.Context, key string) interface{}
- func Serve(b Bot)
- type Bot
- type BotOptions
- type EventHandlerFunc
- type EventType
- type GitHubClient
- func (c GitHubClient) AddComment(ctx context.Context, pr *github.PullRequest, content string) error
- func (c GitHubClient) AddLabel(ctx context.Context, pr *github.PullRequest, label string) error
- func (c GitHubClient) Client() *github.Client
- func (c GitHubClient) CloneRepo(ctx context.Context, ref, destDir string) (*git.Repository, error)
- func (c GitHubClient) Close(ctx context.Context) error
- func (c GitHubClient) FetchWorkflowRunArtifact(ctx context.Context, wr *github.WorkflowRun, name string) (*zip.Reader, error)
- func (c GitHubClient) FetchWorkflowRunLogs(ctx context.Context, wr *github.WorkflowRun, store httpreaderat.Store) (*zip.Reader, error)
- func (c GitHubClient) GetWorkflowRunArtifact(ctx context.Context, wr *github.WorkflowRun, name string) (*zip.Reader, error)deprecated
- func (c GitHubClient) GetWorkflowRunLogs(ctx context.Context, wre github.WorkflowRunEvent) ([]byte, error)deprecated
- func (c GitHubClient) GetWorkloadRunPullRequestNumber(ctx context.Context, wre github.WorkflowRunEvent) (int, error)
- func (c GitHubClient) ListArtifactsFunc(ctx context.Context, wr *github.WorkflowRun, opt *github.ListOptions, ...) error
- func (c GitHubClient) RemoveLabel(ctx context.Context, pr *github.PullRequest, label string) error
- func (c GitHubClient) SetComment(ctx context.Context, pr *github.PullRequest, botName, content string) error
- type IssueCommentHandler
- type PullRequestHandler
- type PushHandler
- type WorkflowRunArtifactHandler
- type WorkflowRunHandler
- type WorkflowRunLogsHandler
Constants ¶
const ( ContextKeyAttributes contextKey = "ce-attributes" ContextKeyType contextKey = "ce-type" ContextKeySubject contextKey = "ce-subject" )
Define constants for the keys to use with context.WithValue.
Variables ¶
This section is empty.
Functions ¶
func AttributeFromContext ¶ added in v0.6.5
AttributeFromContext retrieves an attribute by key from the context. Returns nil if the attribute does not exist.
Types ¶
type Bot ¶
type Bot struct { Name string Handlers map[EventType]EventHandlerFunc }
func NewBot ¶ added in v0.6.0
func NewBot(name string, opts ...BotOptions) Bot
func (*Bot) RegisterHandler ¶ added in v0.6.0
func (b *Bot) RegisterHandler(handler EventHandlerFunc)
type BotOptions ¶ added in v0.6.0
type BotOptions func(*Bot)
func BotWithHandler ¶ added in v0.6.0
func BotWithHandler(handler EventHandlerFunc) BotOptions
type EventHandlerFunc ¶ added in v0.6.0
type EventHandlerFunc interface {
EventType() EventType
}
type EventType ¶ added in v0.6.0
type EventType string
const ( // Github events (https://github.com/chainguard-dev/terraform-infra-common/tree/main/modules/github-events) PullRequestEvent EventType = "dev.chainguard.github.pull_request" WorkflowRunEvent EventType = "dev.chainguard.github.workflow_run" IssueCommentEvent EventType = "dev.chainguard.github.issue_comment" PushEvent EventType = "dev.chainguard.github.push" // LoFo events WorkflowRunArtifactEvent EventType = "dev.chainguard.lofo.workflow_run_artifacts" WorkflowRunLogsEvent EventType = "dev.chainguard.lofo.workflow_run_logs" )
type GitHubClient ¶
type GitHubClient struct {
// contains filtered or unexported fields
}
func NewGitHubClient ¶
func NewGitHubClient(ctx context.Context, org, repo, policyName string) GitHubClient
NewGitHubClient creates a new GitHub client, using a new token from OctoSTS, for the given org, repo and policy name.
A new token is created for each client, and is not refreshed. It can be revoked with Close.
func (GitHubClient) AddComment ¶ added in v0.6.33
func (c GitHubClient) AddComment(ctx context.Context, pr *github.PullRequest, content string) error
AddComment adds a new comment to the given pull request.
func (GitHubClient) AddLabel ¶
func (c GitHubClient) AddLabel(ctx context.Context, pr *github.PullRequest, label string) error
func (GitHubClient) Client ¶
func (c GitHubClient) Client() *github.Client
func (GitHubClient) CloneRepo ¶ added in v0.6.61
func (c GitHubClient) CloneRepo(ctx context.Context, ref, destDir string) (*git.Repository, error)
CloneRepo clones the repository into a destination directory, and checks out a ref.
ref should be "refs/heads/<branch>" or "refs/tags/<tag>" or "refs/pull/<pr>/merge" or a commit SHA.
It returns the git.Repository object for the cloned repository.
func (GitHubClient) FetchWorkflowRunArtifact ¶ added in v0.6.15
func (c GitHubClient) FetchWorkflowRunArtifact(ctx context.Context, wr *github.WorkflowRun, name string) (*zip.Reader, error)
FetchWorkflowRunArtifact returns a zip reader for the artifact with `name` from the given WorkflowRun.
func (GitHubClient) FetchWorkflowRunLogs ¶ added in v0.6.15
func (c GitHubClient) FetchWorkflowRunLogs(ctx context.Context, wr *github.WorkflowRun, store httpreaderat.Store) (*zip.Reader, error)
FetchWorkflowRunLogs returns a Reader for the logs of the given WorkflowRun
func (GitHubClient) GetWorkflowRunArtifact
deprecated
added in
v0.6.12
func (c GitHubClient) GetWorkflowRunArtifact(ctx context.Context, wr *github.WorkflowRun, name string) (*zip.Reader, error)
Deprecated: Use FetchWorkflowRunArtifact instead.
func (GitHubClient) GetWorkflowRunLogs
deprecated
added in
v0.6.4
func (c GitHubClient) GetWorkflowRunLogs(ctx context.Context, wre github.WorkflowRunEvent) ([]byte, error)
Deprecated: use FetchWorkflowRunLogs instead.
func (GitHubClient) GetWorkloadRunPullRequestNumber ¶ added in v0.6.4
func (c GitHubClient) GetWorkloadRunPullRequestNumber(ctx context.Context, wre github.WorkflowRunEvent) (int, error)
func (GitHubClient) ListArtifactsFunc ¶ added in v0.6.19
func (c GitHubClient) ListArtifactsFunc(ctx context.Context, wr *github.WorkflowRun, opt *github.ListOptions, f func(artifact *github.Artifact) (bool, error)) error
ListArtifactsFunc executes a paginated list of all artifacts for a given workflow run and executes the provided function on each of the artifacts. The provided function should return a boolean to indicate whether the list operation can stop making API calls.
func (GitHubClient) RemoveLabel ¶
func (c GitHubClient) RemoveLabel(ctx context.Context, pr *github.PullRequest, label string) error
func (GitHubClient) SetComment ¶
func (c GitHubClient) SetComment(ctx context.Context, pr *github.PullRequest, botName, content string) error
SetComment adds or replaces a bot comment on the given pull request.
type IssueCommentHandler ¶ added in v0.6.9
type IssueCommentHandler func(ctx context.Context, ice github.IssueCommentEvent) error
func (IssueCommentHandler) EventType ¶ added in v0.6.9
func (r IssueCommentHandler) EventType() EventType
type PullRequestHandler ¶ added in v0.6.0
type PullRequestHandler func(ctx context.Context, pre github.PullRequestEvent) error
func (PullRequestHandler) EventType ¶ added in v0.6.0
func (r PullRequestHandler) EventType() EventType
type PushHandler ¶ added in v0.6.52
func (PushHandler) EventType ¶ added in v0.6.52
func (r PushHandler) EventType() EventType
type WorkflowRunArtifactHandler ¶ added in v0.6.17
type WorkflowRunArtifactHandler func(ctx context.Context, wre github.WorkflowRunEvent) error
func (WorkflowRunArtifactHandler) EventType ¶ added in v0.6.17
func (r WorkflowRunArtifactHandler) EventType() EventType
type WorkflowRunHandler ¶ added in v0.6.0
type WorkflowRunHandler func(ctx context.Context, wre github.WorkflowRunEvent) error
func (WorkflowRunHandler) EventType ¶ added in v0.6.0
func (r WorkflowRunHandler) EventType() EventType
type WorkflowRunLogsHandler ¶ added in v0.6.33
type WorkflowRunLogsHandler func(ctx context.Context, wre github.WorkflowRunEvent) error
func (WorkflowRunLogsHandler) EventType ¶ added in v0.6.33
func (r WorkflowRunLogsHandler) EventType() EventType