Documentation
¶
Index ¶
- Constants
- Variables
- func NewPREventHandler(minApprovals int) func(*github.PullRequestEvent, *github.Client, *slog.Logger)
- func NewProcessComment(minApprovals int, categories map[string][]string) func(*github.IssueCommentEvent, *github.Client, *slog.Logger)
- func ProcessComment(event *github.IssueCommentEvent, client *github.Client, logger *slog.Logger)
- func RegisterEventHandlers(r *gin.Engine, client *github.Client, logger *slog.Logger, ...) func(string, []byte)
- type CommandDef
- type CommandPlugin
- type LabelDef
- type PREventDef
- type ProwGitHubClient
- type ProwLiteGitHubClient
Constants ¶
const ApprovalResetComment = "Approval has been reset since this PR was reopened."
ApprovalResetComment is posted when a PR is reopened to signal that previous approvals are void. countApprovals uses it as a marker to discard approvals granted before the reopen.
Variables ¶
var AssignPlugin = CommandPlugin{ Name: "assign", Description: "Assigns and unassigns users on issues and pull requests via slash commands.", Trigger: "GitHub `issue_comment` webhook event.", Commands: []CommandDef{ { Triggers: []string{"/assign"}, Description: "Assigns up to 3 users to the issue or pull request. The `@` prefix on usernames is optional.", Usage: "/assign @user1 [@user2] [@user3]", }, { Triggers: []string{"/unassign"}, Description: "Removes up to 3 users from issue or pull request assignees. The `@` prefix on usernames is optional.", Usage: "/unassign @user1 [@user2] [@user3]", }, }, }
AssignPlugin documents the assign/unassign command group.
var LGTMPlugin = CommandPlugin{ Name: "lgtm", Description: "Manages pull request approvals via slash commands. Tracks approval count against a configurable minimum and maintains a GitHub check run.", Trigger: "GitHub `issue_comment` and `pull_request` webhook events.", Commands: []CommandDef{ { Triggers: []string{"/lgtm", "/approve"}, Description: "Approves the pull request. Adds the `lgtm` label, removes `do-not-merge`, and marks the LGTM check run as passed.", Usage: "/lgtm", }, { Triggers: []string{"/remove-lgtm", "/remove-approve", "/remove-approval", "/unapprove", "/unlgtm"}, Description: "Revokes approval of the pull request. Removes the `lgtm` label, adds `do-not-merge`, and resets the LGTM check run to neutral.", Usage: "/remove-lgtm", }, }, PREvents: []PREventDef{ { Action: "opened", Description: "Adds `do-not-merge` label; creates LGTM check run with `neutral` conclusion.", }, { Action: "reopened", Description: "Adds `do-not-merge`, removes `lgtm`, posts an approval-reset comment, and creates an LGTM check run with `neutral` conclusion.", }, }, Labels: []LabelDef{ {Name: "lgtm", Meaning: "PR has been approved."}, {Name: "do-not-merge", Meaning: "PR is not ready to merge."}, }, }
LGTMPlugin documents the lgtm/approve command group and its PR lifecycle behavior.
var LabelPlugin = CommandPlugin{ Name: "label", Description: "Adds and removes labels on issues and pull requests via slash commands.", Trigger: "GitHub `issue_comment` webhook event.", Commands: []CommandDef{ { Triggers: []string{"/label"}, Description: "Adds a label to the issue or PR. Supports `category/name`, `category:name`, or `category name` syntax.", Usage: "/label <label-name>", }, { Triggers: []string{"/unlabel", "/remove-label"}, Description: "Removes a label from the issue or PR. Supports `category/name`, `category:name`, or `category name` syntax.", Usage: "/unlabel <label-name>", }, }, Notes: []string{ "When `labels.yml` is configured, category-specific commands are generated automatically: `/<category> <label>` adds `<category>/<label>` and `/un<category> <label>` removes it. For example, `/kind bug` adds the `kind/bug` label and `/unkind bug` removes it.", }, }
LabelPlugin documents the label/unlabel command group.
Functions ¶
func NewPREventHandler ¶ added in v0.4.0
func NewPREventHandler(minApprovals int) func(*github.PullRequestEvent, *github.Client, *slog.Logger)
NewPREventHandler returns a pull_request event handler configured with the given minimum approvals.
func NewProcessComment ¶ added in v0.4.0
func NewProcessComment(minApprovals int, categories map[string][]string) func(*github.IssueCommentEvent, *github.Client, *slog.Logger)
NewProcessComment returns a ProcessComment function configured with the given minimum approvals and optional label categories loaded from labels.yml. Pass nil for categories to skip dynamic commands.
func ProcessComment ¶
ProcessComment dispatches slash commands with a default of 1 required approval and no category commands.
Types ¶
type CommandDef ¶ added in v0.3.0
type CommandDef struct {
// Triggers are the slash-command prefixes that activate this command.
Triggers []string
Description string
// Usage shows the full invocation syntax.
Usage string
}
CommandDef describes a slash command handled by the event plugin.
type CommandPlugin ¶ added in v0.5.0
type CommandPlugin struct {
Name string
Description string
// Trigger describes which webhook events activate this plugin.
Trigger string
Commands []CommandDef
PREvents []PREventDef
Labels []LabelDef
// Notes are appended as a freeform section at the end of the generated doc.
Notes []string
}
CommandPlugin groups related slash commands into a named plugin for documentation.
type PREventDef ¶ added in v0.3.0
PREventDef documents a pull_request webhook action handled by the event plugin.
type ProwGitHubClient ¶
type ProwGitHubClient interface {
GetClient() *github.Client
CreateCheckRun(ctx context.Context, owner, repo string, opt github.CreateCheckRunOptions) (*github.CheckRun, *github.Response, error)
}
ProwGitHubClient is the interface consumed by callers that need a GitHub client.
type ProwLiteGitHubClient ¶
type ProwLiteGitHubClient struct {
// contains filtered or unexported fields
}
ProwLiteGitHubClient wraps a GitHub client authenticated as a GitHub App installation.
func NewGithubClient ¶
func NewGithubClient(logger *slog.Logger) (*ProwLiteGitHubClient, error)
func (*ProwLiteGitHubClient) CreateCheckRun ¶
func (*ProwLiteGitHubClient) GetClient ¶
func (g *ProwLiteGitHubClient) GetClient() *github.Client