Help us shape the future of Go! Take the 2026 Go Developer Survey

githubapi

package
v1.233.2-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package githubapi contains the GitHub data shared by Mage reporting targets.

Index

Constants

View Source
const (
	PageSize  = 100
	PageLimit = 100
)

Variables

View Source
var (
	RepoPattern = regexp.MustCompile(`^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$`)
	SHAPattern  = regexp.MustCompile(`^[0-9a-f]{40}$`)
)
View Source
var CommentRunPattern = regexp.MustCompile(`<!-- atmos-benchmark-run:(\d+):(\d+) -->`)
View Source
var ErrPRPaginationLimit = errors.New("PR pagination limit exceeded")

ErrPRPaginationLimit reports that a PR listing exceeded PageLimit pages.

Functions

func Get

func Get(ctx context.Context, client API, path string, response any) error

func NotFound

func NotFound(err error) bool

Types

type API

type API interface {
	DoWithContext(context.Context, string, string, io.Reader, interface{}) error
	RequestWithContext(context.Context, string, string, io.Reader) (*http.Response, error)
}

type Comment

type Comment struct {
	ID   int64  `json:"id"`
	Body string `json:"body"`
	User struct {
		Login string `json:"login"`
		Type  string `json:"type"`
	} `json:"user"`
}

type HeadRef

type HeadRef struct {
	Owner, Branch, SHA string
}

HeadRef identifies a PR head by its fork owner, branch and expected commit.

type PR

type PR struct {
	Milestone    *PRMilestone `json:"milestone"`
	Updated      time.Time    `json:"updated_at"`
	MergeSHA     string       `json:"merge_commit_sha"`
	ChangedFiles *int         `json:"changed_files"`
	Draft        bool         `json:"draft"`
	Number       int          `json:"number"`
	State        string       `json:"state"`
	// Mergeable is nil until GitHub has lazily computed it after a push or base move.
	Mergeable      *bool  `json:"mergeable"`
	MergeableState string `json:"mergeable_state"`
	Labels         []struct {
		Name string `json:"name"`
	} `json:"labels"`
	User struct {
		Login string `json:"login"`
		Type  string `json:"type"`
	} `json:"user"`
	Head struct {
		SHA  string `json:"sha"`
		Repo struct {
			FullName string `json:"full_name"`
		} `json:"repo"`
	} `json:"head"`
	Base struct {
		Ref  string `json:"ref"`
		SHA  string `json:"sha"`
		Repo struct {
			FullName string `json:"full_name"`
		} `json:"repo"`
	} `json:"base"`
}

func ListOpenMainPRs

func ListOpenMainPRs(ctx context.Context, client API, path, headSHA string) ([]PR, error)

ListOpenMainPRs lists open PRs against main from a paginated pulls endpoint. The path is a complete API path that already carries a query string. When headSHA is set, only PRs whose head is exactly that commit qualify, so a PR whose head moved after an event is never selected for the stale commit.

func OpenPRsForHead

func OpenPRsForHead(ctx context.Context, client API, repo string, head HeadRef) ([]PR, error)

OpenPRsForHead resolves open main PRs by their head branch. GitHub's commit association endpoint lists nothing for a commit that exists only in a fork, but the exact owner:branch lookup is strongly consistent. Every result's head is verified against sha.

type PRMilestone

type PRMilestone struct {
	Number int    `json:"number"`
	Title  string `json:"title"`
	State  string `json:"state"`
}

PRMilestone is the mutable release assignment returned with pull requests.

type Run

type Run struct {
	ID             int64     `json:"id"`
	Attempt        int       `json:"run_attempt"`
	HeadSHA        string    `json:"head_sha"`
	Branch         string    `json:"head_branch"`
	Event          string    `json:"event"`
	Status         string    `json:"status"`
	Conclusion     string    `json:"conclusion"`
	Path           string    `json:"path"`
	Created        time.Time `json:"created_at"`
	Updated        time.Time `json:"updated_at"`
	HeadRepository struct {
		FullName string `json:"full_name"`
	} `json:"head_repository"`
	PullRequests []struct {
		Number int `json:"number"`
	} `json:"pull_requests"`
}

Jump to

Keyboard shortcuts

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