Documentation
¶
Overview ¶
Package github provides helpers for managing PR labels via the GitHub API.
Index ¶
Constants ¶
const ApprovedProductionLabel = "prod/approved"
ApprovedProductionLabel records that a human approved a production change. This tool never applies it: "prod/" is a managed prefix, so the label is removed on every label sync and a new push requires a fresh approval.
const CommentMarker = "<!-- render-diff-comment -->"
CommentMarker is the HTML comment used to identify render-diff PR comments for idempotent updates.
const HoldProductionLabel = "infra/hold-production"
HoldProductionLabel is applied when the PR affects the production environment. Prow Tide can be configured to refuse merging PRs that carry this label, ensuring a human explicitly removes it after review.
const KargoBot = "konflux-kargo-bot[bot]"
KargoBot is the GitHub login of the Kargo automation bot (App ID 286661375). Renaming the App requires updating this constant.
const NeedsApprovalProductionLabel = "prod/needs-approval"
NeedsApprovalProductionLabel is applied when the PR affects the production environment, signalling that explicit approval is required before merging.
const UnreferencedChangesLabel = "infra/unreferenced-changes"
UnreferencedChangesLabel is applied when the PR changes files under components/ or configs/ that no ApplicationSet references. Such changes are not deployed by anything and are usually a sign of editing dead code.
Variables ¶
var LabelPrefixes = []string{
"environment/",
"cluster/",
"infra/",
"prod/",
}
LabelPrefixes are the prefixes managed by this tool. Labels with these prefixes will be added/removed as needed.
Functions ¶
func IsKargoBot ¶
IsKargoBot reports whether login is the Kargo GitHub App bot.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the GitHub APIs used by this tool.
func (*Client) KargoSoleCommitter ¶
func (c *Client) KargoSoleCommitter(ctx context.Context, prNumber int, expectedHeadSHA, sender string) (bool, error)
KargoSoleCommitter reports whether the PR is a same-repository promotion authored and pushed by Kargo, with a single verified commit on a Kargo promotion branch, committed by GitHub's web-flow signer or by Kargo itself, and a head matching expectedHeadSHA. Promotion branches are assumed to be writable only by the Kargo automation; a repository writer could otherwise replace the branch and bypass this check.
type CommentClient ¶
type CommentClient struct {
// contains filtered or unexported fields
}
CommentClient wraps a GitHub Issues comment service.
func NewCommentClient ¶
func NewCommentClient(token, repoFullName string) (*CommentClient, error)
NewCommentClient creates a new comment client from a token and "owner/repo" string.
func (*CommentClient) UpsertComment ¶
UpsertComment creates or updates a PR comment identified by CommentMarker. If a comment with the marker exists, it is updated; otherwise a new comment is created.
func (*CommentClient) UpsertCommentByMarker ¶
func (c *CommentClient) UpsertCommentByMarker(ctx context.Context, prNumber int, body, marker string) error
UpsertCommentByMarker creates or updates a PR comment identified by the given marker string. This allows multiple tools to each maintain their own idempotent comment on the same PR without interfering with each other.
type IssueCommentsService ¶
type IssueCommentsService interface {
ListComments(ctx context.Context, owner, repo string, number int, opts *gh.IssueListCommentsOptions) ([]*gh.IssueComment, *gh.Response, error)
CreateComment(ctx context.Context, owner, repo string, number int, comment *gh.IssueComment) (*gh.IssueComment, *gh.Response, error)
EditComment(ctx context.Context, owner, repo string, commentID int64, comment *gh.IssueComment) (*gh.IssueComment, *gh.Response, error)
}
IssueCommentsService is the subset of the GitHub Issues API used for comments.
type IssuesService ¶
type IssuesService interface {
ListLabelsByIssue(ctx context.Context, owner, repo string, number int, opts *gh.ListOptions) ([]*gh.Label, *gh.Response, error)
RemoveLabelForIssue(ctx context.Context, owner, repo string, number int, label string) (*gh.Response, error)
AddLabelsToIssue(ctx context.Context, owner, repo string, number int, labels []string) ([]*gh.Label, *gh.Response, error)
GetLabel(ctx context.Context, owner, repo, name string) (*gh.Label, *gh.Response, error)
CreateLabel(ctx context.Context, owner, repo string, label *gh.Label) (*gh.Label, *gh.Response, error)
}
IssuesService is the subset of the GitHub Issues API used by this package.
type PullRequestsService ¶
type PullRequestsService interface {
Get(ctx context.Context, owner, repo string, number int) (*gh.PullRequest, *gh.Response, error)
ListCommits(ctx context.Context, owner, repo string, number int, opts *gh.ListOptions) ([]*gh.RepositoryCommit, *gh.Response, error)
}
PullRequestsService is the subset of the GitHub Pull Requests API used here.