github

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 17 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatShadowIssueBody

func FormatShadowIssueBody(sourceRepo string, issueNumber int, title, body string) string

FormatShadowIssueBody formats an issue body for a shadow repo mirror issue.

func VerifyWebhookSignature

func VerifyWebhookSignature(payload []byte, signature string, secret string) bool

VerifyWebhookSignature verifies the GitHub webhook signature.

Types

type Client

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

Client wraps the GitHub API for issue operations using GitHub App authentication.

func New

func New(appID int64, privateKey []byte) *Client

New creates a new GitHub API client authenticated as a GitHub App.

func (*Client) CloseIssue

func (c *Client) CloseIssue(ctx context.Context, installationID int64, repo string, issueNumber int) error

CloseIssue closes a GitHub issue by setting its state to "closed".

func (*Client) CreateBranch

func (c *Client) CreateBranch(ctx context.Context, installationID int64, repo, branchName string) error

CreateBranch creates a new branch from the main branch's HEAD.

func (*Client) CreateComment

func (c *Client) CreateComment(ctx context.Context, installationID int64, repo string, issueNumber int, body string) (int64, error)

CreateComment posts a comment on a GitHub issue and returns the comment ID.

func (*Client) CreateIssue

func (c *Client) CreateIssue(ctx context.Context, installationID int64, repo, title, body string) (int, error)

CreateIssue creates a new issue in a repository and returns the issue number.

func (*Client) CreateOrUpdateFile

func (c *Client) CreateOrUpdateFile(ctx context.Context, installationID int64, repo, path, branch, message string, content []byte) error

CreateOrUpdateFile creates or updates a file in a repository.

func (*Client) CreatePullRequest

func (c *Client) CreatePullRequest(ctx context.Context, installationID int64, repo, title, body, head, base string) (int, error)

CreatePullRequest creates a pull request and returns the PR number.

func (*Client) GetFileContents

func (c *Client) GetFileContents(ctx context.Context, installationID int64, repo, path string) ([]byte, error)

GetFileContents reads a file's contents from a repository via the Contents API. Returns the decoded content bytes and nil error, or nil bytes with nil error if the file does not exist (404).

func (*Client) GetIssue added in v0.1.1

func (c *Client) GetIssue(ctx context.Context, installationID int64, repo string, number int) (*Issue, error)

GetIssue returns a single issue by number for the given repo.

func (*Client) GetLatestReleases added in v0.1.1

func (c *Client) GetLatestReleases(ctx context.Context, installationID int64, repo string, n int) ([]Release, error)

GetLatestReleases returns up to n most-recent non-draft releases for repo.

func (*Client) GetTree

func (c *Client) GetTree(ctx context.Context, installationID int64, repo, ref string) ([]TreeEntry, error)

GetTree fetches the full recursive file tree for a repository at the given ref (branch, tag, or SHA). Only blob entries (files) are returned; tree (directory) entries are filtered out. If the tree response is truncated, a warning is logged to stderr.

func (*Client) InstallationToken

func (c *Client) InstallationToken(ctx context.Context, installationID int64) (string, error)

InstallationToken returns an access token for the given installation. This can be used for git clone/push operations via HTTPS.

func (*Client) ListComments

func (c *Client) ListComments(ctx context.Context, installationID int64, repo string, issueNumber int) ([]Comment, error)

ListComments returns all comments on a GitHub issue.

func (*Client) ListInstallations

func (c *Client) ListInstallations(ctx context.Context) ([]int64, error)

ListInstallations returns all installation IDs for this GitHub App.

func (*Client) ListMergedPRsBetween added in v0.1.1

func (c *Client) ListMergedPRsBetween(ctx context.Context, installationID int64, repo, fromTag, toTag string) ([]MergedPR, error)

ListMergedPRsBetween returns PRs merged between two git tags on the given repo, using the closed-PRs search API. Tags must exist in the repo; the method resolves them to dates via the /git/ref/tags + /git/commits chain, following annotated-tag indirection when necessary.

func (*Client) SearchIssues

func (c *Client) SearchIssues(ctx context.Context, installationID int64, query string) ([]IssueSearchResult, error)

SearchIssues searches for issues in a repository using the GitHub search API. The query is passed as the q parameter and URL-encoded internally. Callers should include repo: and is: qualifiers as raw strings.

func (*Client) WarmTLS added in v0.1.1

func (c *Client) WarmTLS(ctx context.Context) error

WarmTLS issues one throwaway unauthenticated GET to api.github.com to prime DNS resolution and the TLS session before the first real request arrives. Cold-start Cloud Run instances have been observed to time out the TLS handshake on the first call to /app/installations/*/access_tokens, which silently drops maintainer `lgtm` signals.

type Comment

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

Comment represents a GitHub issue comment.

type CommentDetail

type CommentDetail struct {
	ID   int64       `json:"id"`
	Body string      `json:"body"`
	User CommentUser `json:"user"`
}

CommentDetail is the comment portion of an issue_comment event.

type CommentUser

type CommentUser struct {
	Login string `json:"login"`
	Type  string `json:"type"`
}

CommentUser represents the user who made a comment.

type InstallationInfo

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

InstallationInfo identifies the GitHub App installation that sent the event.

type Issue added in v0.1.1

type Issue struct {
	Number int
	Title  string
	Body   string
	State  string
	URL    string
}

Issue is a minimal subset of a GitHub issue.

type IssueChangeField

type IssueChangeField struct {
	From string `json:"from"`
}

IssueChangeField holds the previous value of a changed field.

type IssueChanges

type IssueChanges struct {
	Body *IssueChangeField `json:"body,omitempty"`
}

IssueChanges represents the changes payload sent by GitHub on issues.edited events.

type IssueCommentEvent

type IssueCommentEvent struct {
	Action       string           `json:"action"`
	Issue        IssueDetail      `json:"issue"`
	Comment      CommentDetail    `json:"comment"`
	Repo         RepoDetail       `json:"repository"`
	Installation InstallationInfo `json:"installation"`
}

IssueCommentEvent represents a GitHub issue_comment webhook event payload.

type IssueDetail

type IssueDetail struct {
	Number int         `json:"number"`
	Title  string      `json:"title"`
	Body   string      `json:"body"`
	State  string      `json:"state"`
	Labels []LabelInfo `json:"labels"`
	User   IssueUser   `json:"user"`
}

IssueDetail is the issue portion of a webhook event.

type IssueEvent

type IssueEvent struct {
	Action       string           `json:"action"`
	Issue        IssueDetail      `json:"issue"`
	Changes      *IssueChanges    `json:"changes,omitempty"`
	Repo         RepoDetail       `json:"repository"`
	Installation InstallationInfo `json:"installation"`
}

IssueEvent represents a GitHub issue webhook event payload.

type IssueSearchResult

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

IssueSearchResult represents a single issue returned from the GitHub search API.

type IssueUser

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

IssueUser is the user who created the issue.

type LabelInfo

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

LabelInfo is a GitHub label.

type MergedPR added in v0.1.1

type MergedPR struct {
	Number   int
	Title    string
	Body     string
	MergedAt time.Time
	URL      string
	Labels   []string
}

MergedPR is a subset of fields from GitHub's closed-PRs search.

type PushCommit

type PushCommit struct {
	Added    []string `json:"added"`
	Modified []string `json:"modified"`
	Removed  []string `json:"removed"`
}

PushCommit represents a single commit in a push event.

type PushEvent

type PushEvent struct {
	Ref          string           `json:"ref"`
	Commits      []PushCommit     `json:"commits"`
	Repo         RepoDetail       `json:"repository"`
	Installation InstallationInfo `json:"installation"`
}

PushEvent represents a GitHub push webhook event payload.

type Release added in v0.1.1

type Release struct {
	TagName     string
	Name        string
	Body        string
	PublishedAt time.Time
	Prerelease  bool
	Draft       bool
	HTMLURL     string
}

Release is a subset of fields from GitHub's releases list.

type RepoDetail

type RepoDetail struct {
	FullName string `json:"full_name"`
}

RepoDetail is the repository portion of a webhook event.

type TreeEntry

type TreeEntry struct {
	Path string `json:"path"`
	Type string `json:"type"`
	Size int    `json:"size"`
}

TreeEntry represents a single entry in a git tree (file or directory).

Jump to

Keyboard shortcuts

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