github

package
v0.0.0-...-0ae0667 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package github provides helpers for managing PR labels via the GitHub API.

Index

Constants

View Source
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.

View Source
const CommentMarker = "<!-- render-diff-comment -->"

CommentMarker is the HTML comment used to identify render-diff PR comments for idempotent updates.

View Source
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.

View Source
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.

View Source
const NeedsApprovalProductionLabel = "prod/needs-approval"

NeedsApprovalProductionLabel is applied when the PR affects the production environment, signalling that explicit approval is required before merging.

View Source
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

View Source
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

func IsKargoBot(login string) bool

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 NewClient

func NewClient(token, repoFullName string) (*Client, error)

NewClient creates a new GitHub client from a token and "owner/repo" string.

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.

func (*Client) PRHeadSHA

func (c *Client) PRHeadSHA(ctx context.Context, prNumber int) (string, error)

PRHeadSHA returns the current head SHA of the PR.

func (*Client) SyncLabels

func (c *Client) SyncLabels(ctx context.Context, prNumber int, desiredLabels []string) error

SyncLabels ensures the PR has exactly the given labels (for managed prefixes) and removes any stale managed labels.

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

func (c *CommentClient) UpsertComment(ctx context.Context, prNumber int, body string) error

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.

Jump to

Keyboard shortcuts

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