github

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package github implements forge.Forge for github.com using the GitHub REST API. Uses net/http directly; no extra dependencies.

GitHub Releases API: fetch latest release and download assets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifySignature

func VerifySignature(secret, body []byte, sig string) error

VerifySignature verifies the HMAC-SHA256 signature of a GitHub webhook payload. sig must be in the format "sha256=<hex>".

Types

type AppClient

type AppClient struct {
	AppID     int64
	Transport http.RoundTripper // throttle transport passed to NewClient; must be set
	// contains filtered or unexported fields
}

AppClient authenticates as a GitHub App using RS256 JWTs and caches installation access tokens.

func NewAppClient

func NewAppClient(appID int64, privateKeyPEM []byte, transport http.RoundTripper) (*AppClient, error)

NewAppClient parses a PEM-encoded RSA private key and returns an AppClient. Both PKCS8 and PKCS1 key formats are supported.

func (*AppClient) DeleteInstallation

func (a *AppClient) DeleteInstallation(ctx context.Context, installationID int64) error

DeleteInstallation removes the app installation, effectively uninstalling it. Used to reject installs from non-allowlisted owners.

func (*AppClient) ForgeClient

func (a *AppClient) ForgeClient(ctx context.Context, installationID int64) (forge.Forge, error)

ForgeClient returns a forge.Forge authenticated with an installation access token.

func (*AppClient) InstallationToken

func (a *AppClient) InstallationToken(ctx context.Context, installationID int64) (string, error)

InstallationToken returns a cached or freshly-obtained installation access token.

func (*AppClient) PostComment

func (a *AppClient) PostComment(ctx context.Context, installationID int64, owner, repo string, issueNumber int, body string) error

PostComment posts a comment on the given issue or pull request using an installation token.

func (*AppClient) RepoInstallation

func (a *AppClient) RepoInstallation(ctx context.Context, owner, repo string) (int64, error)

RepoInstallation returns the installation ID for the app on the given repository. This is used to obtain an installation token when no installation ID is cached.

type CheckRunEvent

type CheckRunEvent struct {
	Action   string `json:"action"`
	CheckRun struct {
		HeadSHA    string `json:"head_sha"`
		Name       string `json:"name"`
		Status     string `json:"status"`
		Conclusion string `json:"conclusion"`
		HTMLURL    string `json:"html_url"`
		ID         int64  `json:"id"`
	} `json:"check_run"`
	Repository WebhookRepo `json:"repository"`
}

CheckRunEvent is the payload for X-GitHub-Event: check_run.

type CheckSuiteEvent

type CheckSuiteEvent struct {
	Action     string `json:"action"`
	CheckSuite struct {
		HeadSHA    string `json:"head_sha"`
		HeadBranch string `json:"head_branch"`
		Conclusion string `json:"conclusion"` // "success", "failure", "neutral", etc.
	} `json:"check_suite"`
	Repository   WebhookRepo         `json:"repository"`
	Installation WebhookInstallation `json:"installation"`
}

CheckSuiteEvent is the payload for X-GitHub-Event: check_suite.

type Client

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client is a minimal GitHub API client authenticated with a personal access token. It implements forge.Forge.

func NewClient

func NewClient(token string, throttle http.RoundTripper) *Client

NewClient returns a Client that authenticates with token and throttles/retries via throttle. The transport chain is: Header → Retry → throttle. When token is empty, requests are unauthenticated (lower rate limits).

func (*Client) BranchCompareURL

func (c *Client) BranchCompareURL(remoteURL, branch string) string

BranchCompareURL returns the GitHub compare URL for a branch.

func (*Client) CIHomeURL

func (c *Client) CIHomeURL(remoteURL string) string

CIHomeURL returns the GitHub Actions overview URL for a repo.

func (*Client) CIJobURL

func (c *Client) CIJobURL(owner, repo string, runID, jobID int64) string

CIJobURL returns the GitHub Actions job URL.

func (*Client) CreatePR

func (c *Client) CreatePR(ctx context.Context, owner, repo, head, base, title, body string) (forge.PR, error)

CreatePR creates a pull request on GitHub and returns its metadata.

func (*Client) DownloadAsset added in v0.5.6

func (c *Client) DownloadAsset(ctx context.Context, url string) (io.ReadCloser, error)

DownloadAsset fetches a release asset URL and returns the response body as a stream. The caller must close the returned ReadCloser.

func (*Client) FindPRByBranch

func (c *Client) FindPRByBranch(ctx context.Context, owner, repo, headBranch string) (forge.PR, error)

FindPRByBranch returns the PR for the given head branch, or ErrNotFound if no PR exists for that branch.

func (*Client) GetCheckRuns

func (c *Client) GetCheckRuns(ctx context.Context, owner, repo, sha string) ([]forge.CheckRun, error)

GetCheckRuns returns all check runs for the given commit SHA.

func (*Client) GetDefaultBranchSHA

func (c *Client) GetDefaultBranchSHA(ctx context.Context, owner, repo, branch string) (string, error)

GetDefaultBranchSHA returns the HEAD commit SHA of branch in the given repo. Uses the lightweight git refs API — no full commit data is fetched.

func (*Client) GetJobLabels

func (c *Client) GetJobLabels(ctx context.Context, owner, repo string, jobID int64) ([]string, error)

GetJobLabels returns the runner labels for a GitHub Actions job by fetching the job details endpoint. Labels typically include the runner OS (e.g. "ubuntu-latest").

func (*Client) GetJobLog

func (c *Client) GetJobLog(ctx context.Context, owner, repo string, jobID int64, failingOnly bool) (string, error)

GetJobLog fetches the log for a GitHub Actions job, capped at 100 MB. When failingOnly is true, the log is trimmed to only the steps that contain ##[error] markers; if no such steps are found the full log is returned.

func (*Client) LatestRelease added in v0.5.6

func (c *Client) LatestRelease(ctx context.Context, owner, repo string) (*Release, error)

LatestRelease fetches the latest non-prerelease for the given owner/repo.

func (*Client) MergePR

func (c *Client) MergePR(ctx context.Context, owner, repo string, prNumber int, commitTitle, commitMessage string) error

MergePR squash-merges a pull request on GitHub.

func (*Client) Name

func (c *Client) Name() string

Name returns "GitHub".

func (*Client) PRLabel

func (c *Client) PRLabel(prNumber int) string

PRLabel returns a GitHub-style PR label.

func (*Client) PRURL

func (c *Client) PRURL(owner, repo string, prNumber int) string

PRURL returns the GitHub pull request URL.

func (*Client) PostComment

func (c *Client) PostComment(ctx context.Context, owner, repo string, issueNumber int, body string) error

PostComment posts a comment on the given issue or pull request.

type InstallationEvent

type InstallationEvent struct {
	Action       string `json:"action"` // "created", "deleted", "suspend", "unsuspend"
	Installation struct {
		ID      int64 `json:"id"`
		Account struct {
			Login string `json:"login"`
			Type  string `json:"type"` // "User" or "Organization"
		} `json:"account"`
	} `json:"installation"`
}

InstallationEvent is the payload for X-GitHub-Event: installation.

type IssueCommentEvent

type IssueCommentEvent struct {
	Action       string              `json:"action"`
	Issue        WebhookIssue        `json:"issue"`
	Comment      WebhookComment      `json:"comment"`
	Repository   WebhookRepo         `json:"repository"`
	Installation WebhookInstallation `json:"installation"`
}

IssueCommentEvent is the payload for X-GitHub-Event: issue_comment.

type IssuesEvent

type IssuesEvent struct {
	Action       string              `json:"action"`
	Issue        WebhookIssue        `json:"issue"`
	Repository   WebhookRepo         `json:"repository"`
	Installation WebhookInstallation `json:"installation"`
}

IssuesEvent is the payload for X-GitHub-Event: issues.

type PullRequestEvent

type PullRequestEvent struct {
	Action       string              `json:"action"`
	PullRequest  WebhookPR           `json:"pull_request"`
	Repository   WebhookRepo         `json:"repository"`
	Installation WebhookInstallation `json:"installation"`
}

PullRequestEvent is the payload for X-GitHub-Event: pull_request.

type Release added in v0.5.6

type Release struct {
	TagName string         `json:"tag_name"`
	Assets  []ReleaseAsset `json:"assets"`
}

Release is the subset of the GitHub Release API response needed for updates.

type ReleaseAsset added in v0.5.6

type ReleaseAsset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
}

ReleaseAsset is a single release asset.

type WebhookComment

type WebhookComment struct {
	Body    string      `json:"body"`
	User    WebhookUser `json:"user"`
	HTMLURL string      `json:"html_url"`
}

WebhookComment carries the comment fields used from webhook payloads.

type WebhookInstallation

type WebhookInstallation struct {
	ID int64 `json:"id"`
}

WebhookInstallation carries the GitHub App installation ID from a webhook payload.

type WebhookIssue

type WebhookIssue struct {
	Number  int            `json:"number"`
	Title   string         `json:"title"`
	Body    string         `json:"body"`
	Labels  []WebhookLabel `json:"labels"`
	User    WebhookUser    `json:"user"`
	HTMLURL string         `json:"html_url"`
}

WebhookIssue carries the issue fields used from webhook payloads.

type WebhookLabel

type WebhookLabel struct {
	Name string `json:"name"`
}

WebhookLabel carries a label from a webhook payload.

type WebhookPR

type WebhookPR struct {
	Number  int         `json:"number"`
	Title   string      `json:"title"`
	Body    string      `json:"body"`
	User    WebhookUser `json:"user"`
	HTMLURL string      `json:"html_url"`
	Head    struct {
		Ref string `json:"ref"` // branch name
		SHA string `json:"sha"`
	} `json:"head"`
	Base struct {
		Ref string `json:"ref"` // target branch
	} `json:"base"`
}

WebhookPR carries the pull request fields used from webhook payloads.

type WebhookRepo

type WebhookRepo struct {
	FullName string `json:"full_name"` // "owner/repo"
}

WebhookRepo carries repository identity from a webhook payload.

type WebhookUser

type WebhookUser struct {
	Login string `json:"login"`
}

WebhookUser carries user identity from a webhook payload.

type WorkflowRunEvent

type WorkflowRunEvent struct {
	Action      string `json:"action"`
	WorkflowRun struct {
		HeadSHA    string `json:"head_sha"`
		Name       string `json:"name"`
		Status     string `json:"status"`
		Conclusion string `json:"conclusion"`
		ID         int64  `json:"id"`
	} `json:"workflow_run"`
	Repository WebhookRepo `json:"repository"`
}

WorkflowRunEvent is the payload for X-GitHub-Event: workflow_run.

Jump to

Keyboard shortcuts

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