ghcomment

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ghcomment keeps one relgap comment per report kind on a GitHub pull request, edited in place and left alone when its content hasn't changed.

Index

Constants

View Source
const DefaultAPIURL = "https://api.github.com"

DefaultAPIURL is the GitHub REST API on github.com.

View Source
const Scope = "pull-request"

Scope is the marker scope of a pull request comment, which covers the whole report.

Variables

View Source
var ErrAuth = errors.New("authentication failed")

ErrAuth is wrapped when GitHub refuses the token.

View Source
var ErrConfig = errors.New("pull request comment not configured")

ErrConfig is wrapped when the repository, the pull request or the token is missing.

Functions

func PullRequestFromEvent

func PullRequestFromEvent(path string) (int, error)

PullRequestFromEvent reads the pull request number from a GitHub Actions event file. It knows pull_request, pull_request_target and issue_comment events on a pull request.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client edits the comments of one pull request.

func New

func New(hc *http.Client, cfg Config) (*Client, error)

New checks cfg and returns a client. Pass an httpx client: it retries reads and never resends a POST after a server error.

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, p Post) (*Result, error)

Publish creates, edits or leaves the comment for p.Kind. A report with nothing open turns an existing comment into "Nothing to report" and creates none.

func (*Client) Render

func (c *Client) Render(p Post) (string, Marker)

Render returns the comment body for p and its marker. The hash covers the heading and the Markdown, not the footer.

func (*Client) Target

func (c *Client) Target() string

Target names the pull request as owner/name#number.

type Config

type Config struct {
	Repo        string // owner/name
	PullRequest int
	APIURL      string // DefaultAPIURL when empty
	Token       string
	DryRun      bool // read with GET only and write nothing
	MaxChars    int  // the longest comment; render.DefaultMDMaxChars when 0
}

Config says which pull request to comment on.

func FromEnv

func FromEnv(c Config, lookup func(string) (string, bool)) (Config, error)

FromEnv fills the empty fields of c from the variables GitHub Actions sets: GITHUB_REPOSITORY, GITHUB_API_URL, and the pull request number in the GITHUB_EVENT_PATH file.

type Marker

type Marker struct {
	Kind  string `json:"kind"`
	Scope string `json:"scope"`
	Hash  string `json:"hash"`
}

Marker is the hidden first line of a comment. Kind and Scope find the comment again; Hash says whether its content changed.

func ParseMarker

func ParseMarker(body string) (Marker, bool)

ParseMarker finds the marker in a comment body.

func (Marker) String

func (m Marker) String() string

String renders the marker as an HTML comment, which GitHub doesn't show.

type Op

type Op string

Op is what Publish did, or would do in a dry run.

const (
	OpCreate    Op = "create"
	OpUpdate    Op = "update"
	OpResolve   Op = "resolve"   // an existing comment now says "Nothing to report"
	OpUnchanged Op = "unchanged" // the hash matches, so nothing was written
	OpSkipped   Op = "skipped"   // nothing to report and no comment yet
)

Operations.

type Post

type Post struct {
	Kind  string // one comment per kind, such as drift
	Title string // the comment's heading
	Body  string // Markdown under the heading, cut to fit when too long
	Open  bool   // false when the report found nothing: the comment becomes "Nothing to report"
	Hint  string // ends the truncation footer, such as "Run relgap drift --format json."
}

Post is one report to publish.

type Result

type Result struct {
	Op     Op     `json:"op"`
	Kind   string `json:"kind"`
	Target string `json:"target"`
	URL    string `json:"url,omitempty"`
	DryRun bool   `json:"dry_run"`
}

Result says what Publish did.

Jump to

Keyboard shortcuts

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