prcheck

package
v0.15.2 Latest Latest
Warning

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

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

Documentation

Overview

Package prcheck validates pull request bodies against the repository's "## Changelog" contract (parity with the migrated JavaScript verifier workflow).

Packages in prcheck MUST NOT read environment variables or touch the filesystem; callers inject GitHub/network via PullRequestFetcher.

Index

Constants

View Source
const (
	// StatusPass is written to Verdict.Status when validation succeeds or no-changelog bypass applies.
	StatusPass = "pass"
	// StatusFail is written to Verdict.Status when validation reports one or more errors.
	StatusFail = "fail"
)
View Source
const MarkerForPRCheck = "<!-- pr-changelog-check -->"

MarkerForPRCheck is embedded in verdict comments so later runs locate the same comment.

Variables

This section is empty.

Functions

func BuildFailureCommentBody

func BuildFailureCommentBody(marker string, errs []string) string

BuildFailureCommentBody matches the legacy failure comment template (byte-compatible).

func BuildNoChangelogPassCommentBody

func BuildNoChangelogPassCommentBody(marker string) string

BuildNoChangelogPassCommentBody matches the legacy no-changelog pass comment template verbatim.

func BuildPassCommentBody

func BuildPassCommentBody(marker string) string

BuildPassCommentBody matches the legacy pass comment template verbatim.

func UpsertVerdictIssueComment

func UpsertVerdictIssueComment(ctx context.Context, rest IssueCommentsREST, owner, repo string, issueNumber int, verdict Verdict) error

UpsertVerdictIssueComment mirrors pr-changelog-check/check.js comment upsert semantics.

Types

type Comment

type Comment struct {
	ID        int64
	Body      string
	UserLogin string
}

Comment is a minimal snapshot of an issue comment for upsert lookups.

func FindExistingComment

func FindExistingComment(comments []Comment, marker string) *Comment

FindExistingComment returns the first github-actions[bot] comment containing marker, or nil.

type IssueCommentsREST

type IssueCommentsREST interface {
	ListIssueComments(ctx context.Context, owner, repo string, issueNumber int) ([]Comment, error)
	CreateIssueComment(ctx context.Context, owner, repo string, issueNumber int, body string) error
	UpdateIssueComment(ctx context.Context, owner, repo string, commentID int64, body string) error
}

IssueCommentsREST lists and mutates GitHub issue comments (used for PR threads).

type PullRequest

type PullRequest struct {
	Number int
	Body   string
	Labels []string
}

PullRequest is the validator input trimmed from GitHub PR APIs.

type PullRequestFetcher

type PullRequestFetcher interface {
	GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)
}

PullRequestFetcher retrieves PR payload for Validate.

type Status

type Status string

Status is serialized as the JSON status string ("pass" | "fail").

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON encodes Status as a JSON string literal.

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes Status from JSON string literals ("pass", "fail").

type ValidateOptions

type ValidateOptions struct {
	Owner            string
	Repo             string
	Number           int
	Fetcher          PullRequestFetcher
	NoChangelogLabel string
}

ValidateOptions configures Validate (no environment access).

type Verdict

type Verdict struct {
	Status Status `json:"status"`

	// Errors lists validation diagnostics when Status is StatusFail (JS errors array parity).
	Errors []string `json:"errors,omitempty"`

	// NoChangelogSkip is true when validation was bypassed via the configured no-changelog label.
	NoChangelogSkip bool `json:"no_changelog_skip,omitempty"`
}

Verdict is the canonical JSON verdict for workflows (see GitHub Actions result_json consumer).

func Validate

func Validate(ctx context.Context, opts ValidateOptions) (Verdict, error)

Validate loads the PR, applies optional no-changelog suppression, parses via section.Parse, and validates via section.ValidateChangelogSectionFull (default options).

Operational errors from Fetcher bubble up wrapped; validation failures return Verdict.StatusFail and a nil error.

Jump to

Keyboard shortcuts

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