Documentation
¶
Overview ¶
Package gogithub provides a Go client for the GitHub API.
Recommended: Version-Isolated Client ¶
For new code, use the clientv1 package which provides stable types that won't change when go-github updates its major version:
import "github.com/grokify/gogithub/clientv1" client, err := clientv1.NewClient(ctx, "your-token") user, err := client.GetAuthenticatedUser(ctx) // Returns *clientv1.User repos, err := client.ListUserRepos(ctx, "user") // Returns []*clientv1.Repository sha, err := client.GetBranchSHA(ctx, "owner", "repo", "main")
Operation Packages ¶
The following packages also accept clientv1.Client and return stable gogithub.* types, so they stay version-isolated like the client itself:
- search: Search API (issues, PRs, code, etc.)
- repo: Repository operations (fork, branch, commit, batch)
- pr: Pull request operations
- release: Release and asset operations
- checks: Check run polling and status
- tag: Git tag operations
- sarif: SARIF upload for code scanning
A few legacy functions in auth and config still return go-github types directly and are deprecated (auth.NewGitHubClient, config.Config.NewClient); prefer clientv1.NewClient and config.Config.NewClientV1 instead.
Example:
package main
import (
"context"
"fmt"
"github.com/grokify/gogithub/clientv1"
"github.com/grokify/gogithub/search"
)
func main() {
ctx := context.Background()
client, err := clientv1.NewClient(ctx, "your-token")
if err != nil {
panic(err)
}
c := search.NewClient(client)
issues, err := c.SearchIssuesAll(ctx, search.Query{
search.ParamUser: "grokify",
search.ParamState: search.ParamStateValueOpen,
}, nil)
if err != nil {
panic(err)
}
fmt.Printf("Found %d issues\n", len(issues))
}
Index ¶
- Constants
- type App
- type Branch
- type BranchProtection
- type CheckRun
- type CheckSuite
- type CodeResult
- type CodeSearchResult
- type Commit
- type CommitAuthor
- type CommitFile
- type CommitParent
- type ContentOptions
- type ContributorStats
- type CreateFileResult
- type DeleteFileResult
- type Event
- type EventRepo
- type FileContent
- type GitObject
- type Issue
- type IssueComment
- type IssueSearchResult
- type Label
- type MergeResult
- type PullRequest
- type PullRequestBranch
- type PullRequestComment
- type PullRequestReview
- type PullRequestReviewsEnforcement
- type RateLimit
- type Reference
- type Release
- type ReleaseAsset
- type ReleaseAssetUpload
- type Repository
- type RequiredStatusChecks
- type SearchResult
- type Tag
- type TreeNode
- type User
- type WeeklyStats
- type Workflow
- type WorkflowRun
Constants ¶
const ( // BaseURLRepoAPI is the base URL for the GitHub API repository endpoints. BaseURLRepoAPI = "https://api.github.com/repos" // BaseURLRepoHTML is the base URL for GitHub repository web pages. BaseURLRepoHTML = "https://github.com" )
GitHub API base URLs.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BranchProtection ¶ added in v0.17.0
type BranchProtection struct {
RequiredStatusChecks *RequiredStatusChecks
RequiredPullRequestReviews *PullRequestReviewsEnforcement
EnforceAdmins bool
RequireSignedCommits bool
AllowForcePushes bool
AllowDeletions bool
URL string
}
BranchProtection represents a repository branch's protection settings.
type CheckRun ¶ added in v0.15.0
type CheckRun struct {
ID int64
HeadSHA string
Status string // "queued", "in_progress", "completed"
Conclusion string // "success", "failure", "neutral", "cancelled", "skipped", "timed_out", "action_required"
Name string
HTMLURL string
StartedAt *time.Time
CompletedAt *time.Time
}
CheckRun represents a GitHub Actions check run.
type CheckSuite ¶ added in v0.15.0
type CheckSuite struct {
ID int64
HeadBranch string
HeadSHA string
Status string // "queued", "in_progress", "completed"
Conclusion string // "success", "failure", "neutral", "cancelled", "skipped", "timed_out", "action_required"
URL string
App *App
CreatedAt time.Time
UpdatedAt time.Time
}
CheckSuite represents a GitHub Actions check suite.
type CodeResult ¶ added in v0.15.0
type CodeResult struct {
Name string
Path string
SHA string
HTMLURL string
Repository *Repository
}
CodeResult represents a single code search result.
type CodeSearchResult ¶ added in v0.15.0
type CodeSearchResult struct {
Total int
IncompleteResults bool
Items []*CodeResult
}
CodeSearchResult represents search results for code.
type Commit ¶ added in v0.15.0
type Commit struct {
SHA string
Message string
Author *CommitAuthor
Committer *CommitAuthor
HTMLURL string
Tree *GitObject // Root tree of this commit
Parents []CommitParent
}
Commit represents a git commit.
type CommitAuthor ¶ added in v0.15.0
CommitAuthor represents the author/committer of a commit.
type CommitFile ¶ added in v0.15.0
type CommitFile struct {
SHA string
Filename string
Status string // "added", "removed", "modified", "renamed", "copied", "changed", "unchanged"
Additions int
Deletions int
Changes int
Patch string
BlobURL string
RawURL string
ContentsURL string
Previous string // Previous filename for renamed files
}
CommitFile represents a file changed in a commit.
type CommitParent ¶ added in v0.15.0
CommitParent represents a parent commit reference.
type ContentOptions ¶ added in v0.15.0
type ContentOptions struct {
Ref string // Branch, tag, or commit SHA. Empty uses default branch.
}
ContentOptions specifies options for fetching repository content.
type ContributorStats ¶ added in v0.15.0
type ContributorStats struct {
Author *User
Total int
Weeks []WeeklyStats
}
ContributorStats represents contribution statistics for a user.
type CreateFileResult ¶ added in v0.15.0
type CreateFileResult struct {
Content *FileContent
Commit *Commit
}
CreateFileResult represents the result of creating or updating a file.
type DeleteFileResult ¶ added in v0.15.0
type DeleteFileResult struct {
Commit *Commit
}
DeleteFileResult represents the result of deleting a file.
type Event ¶ added in v0.16.0
type Event struct {
ID string
Type string
Public bool
Actor *User
Repo *EventRepo
CreatedAt time.Time
}
Event represents a GitHub activity event, such as those returned by a user's public timeline (e.g., "PushEvent", "PullRequestEvent", "IssuesEvent").
type EventRepo ¶ added in v0.16.0
EventRepo identifies the repository an Event occurred in. It carries only the fields the GitHub Events API populates, not the full Repository.
type FileContent ¶ added in v0.15.0
type FileContent struct {
Path string
Name string
SHA string
Size int
Type string // "file", "dir", "symlink", "submodule"
Content []byte // Decoded content (for files)
DownloadURL string
}
FileContent represents file content from a repository.
type Issue ¶
type Issue struct {
ID int64
Number int
State string
Title string
Body string
HTMLURL string
RepositoryURL string // API URL of the repository
User *User
Labels []Label
Assignees []*User
Comments int
IsPullRequest bool // true if this issue is actually a pull request
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt *time.Time
}
Issue represents a GitHub issue.
type IssueComment ¶ added in v0.15.0
type IssueComment struct {
ID int64
User *User
Body string
HTMLURL string
CreatedAt time.Time
UpdatedAt time.Time
}
IssueComment represents a comment on an issue or pull request.
type IssueSearchResult ¶ added in v0.15.0
type IssueSearchResult = SearchResult[*Issue]
IssueSearchResult is a search result containing issues.
type MergeResult ¶ added in v0.15.0
MergeResult represents the result of merging a pull request.
type PullRequest ¶ added in v0.15.0
type PullRequest struct {
ID int64
Number int
State string // "open", "closed"
Title string
Body string
HTMLURL string
User *User
Head *PullRequestBranch
Base *PullRequestBranch
Labels []Label
Assignees []*User
Merged bool
Mergeable *bool
Draft bool
Additions int
Deletions int
Commits int
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt *time.Time
MergedAt *time.Time
}
PullRequest represents a GitHub pull request.
type PullRequestBranch ¶ added in v0.15.0
type PullRequestBranch struct {
Label string
Ref string
SHA string
User *User
Repo *Repository
}
PullRequestBranch represents the head or base branch of a PR.
type PullRequestComment ¶ added in v0.15.0
type PullRequestComment struct {
ID int64
User *User
Body string
Path string
Line int
Side string // "LEFT" or "RIGHT"
CommitID string
HTMLURL string
CreatedAt time.Time
UpdatedAt time.Time
}
PullRequestComment represents a comment on a pull request diff.
type PullRequestReview ¶ added in v0.15.0
type PullRequestReview struct {
ID int64
User *User
Body string
State string // "APPROVED", "CHANGES_REQUESTED", "COMMENTED", "DISMISSED", "PENDING"
HTMLURL string
CommitID string
SubmittedAt *time.Time
}
PullRequestReview represents a review on a pull request.
type PullRequestReviewsEnforcement ¶ added in v0.17.0
type PullRequestReviewsEnforcement struct {
DismissStaleReviews bool
RequireCodeOwnerReviews bool
RequiredApprovingReviewCount int
}
PullRequestReviewsEnforcement represents the pull request review requirements of a protected branch.
type RateLimit ¶ added in v0.17.0
RateLimit represents the core (non-search) API rate limit for the authenticated client.
type Reference ¶ added in v0.15.0
type Reference struct {
Ref string // e.g., "refs/heads/main"
SHA string // Convenience field: same as Object.SHA
URL string
Object *GitObject
}
Reference represents a git reference (branch, tag).
type Release ¶ added in v0.15.0
type Release struct {
ID int64
TagName string
TargetCommitish string
Name string
Body string
Draft bool
Prerelease bool
HTMLURL string
TarballURL string
ZipballURL string
CreatedAt time.Time
PublishedAt *time.Time
Author *User
Assets []ReleaseAsset
}
Release represents a GitHub release.
type ReleaseAsset ¶ added in v0.15.0
type ReleaseAsset struct {
ID int64
Name string
Label string
State string
ContentType string
Size int
DownloadCount int
BrowserDownloadURL string
CreatedAt time.Time
UpdatedAt time.Time
}
ReleaseAsset represents an asset attached to a release.
type ReleaseAssetUpload ¶ added in v0.15.0
ReleaseAssetUpload represents an asset being uploaded to a release.
type Repository ¶ added in v0.15.0
type Repository struct {
ID int64
Owner *User
Name string
FullName string
Description string
HTMLURL string
CloneURL string
SSHURL string
DefaultBranch string
Private bool
Visibility string // "public", "private", or "internal"
Fork bool
Archived bool
Disabled bool
Language string
Topics []string
ForksCount int
StargazersCount int
WatchersCount int
OpenIssuesCount int
Size int
CreatedAt time.Time
UpdatedAt time.Time
PushedAt time.Time
}
Repository represents a GitHub repository.
type RequiredStatusChecks ¶ added in v0.17.0
RequiredStatusChecks represents the required status checks of a protected branch.
type SearchResult ¶ added in v0.15.0
SearchResult represents search results from the GitHub API.
type Tag ¶ added in v0.15.0
type Tag struct {
Name string
Commit *Commit
SHA string // SHA of the tag object (for annotated) or commit (for lightweight)
}
Tag represents a git tag.
type TreeNode ¶ added in v0.15.0
type TreeNode struct {
Path string
Mode string // "100644" (file), "100755" (executable), "040000" (dir), "160000" (submodule), "120000" (symlink)
Type string // "blob", "tree", "commit"
SHA string
Size int
URL string
}
TreeNode represents a node in a git tree.
type User ¶ added in v0.15.0
type User struct {
ID int64
Login string
Name string
Email string
AvatarURL string
HTMLURL string
Type string // "User" or "Organization"
Bio string
Company string
Location string
Blog string
Followers int
Following int
CreatedAt time.Time
UpdatedAt time.Time
}
User represents a GitHub user. This is a stable type that won't change when go-github updates its major version.
type WeeklyStats ¶ added in v0.15.0
WeeklyStats represents contribution stats for a single week.
type Workflow ¶ added in v0.17.0
type Workflow struct {
ID int64
Name string
Path string
State string
URL string
HTMLURL string
BadgeURL string
CreatedAt time.Time
UpdatedAt time.Time
}
Workflow represents a GitHub Actions workflow.
type WorkflowRun ¶ added in v0.17.0
type WorkflowRun struct {
ID int64
Name string
WorkflowID int64
RunNumber int
Event string
Status string
Conclusion string
HeadBranch string
HeadSHA string
URL string
HTMLURL string
CreatedAt time.Time
UpdatedAt time.Time
}
WorkflowRun represents a run of a GitHub Actions workflow.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth provides GitHub authentication utilities.
|
Package auth provides GitHub authentication utilities. |
|
Package checks provides GitHub check runs operations.
|
Package checks provides GitHub check runs operations. |
|
Package clientv1 provides a stable, version-isolated client for the GitHub API.
|
Package clientv1 provides a stable, version-isolated client for the GitHub API. |
|
cmd/bulk_git_rm
command
|
|
|
cmd
|
|
|
gogithub
command
Package main provides the gogithub CLI tool.
|
Package main provides the gogithub CLI tool. |
|
searchuserpr
command
|
|
|
Package config provides configuration utilities for GitHub API clients.
|
Package config provides configuration utilities for GitHub API clients. |
|
Package errors provides error types and translation utilities for GitHub API errors.
|
Package errors provides error types and translation utilities for GitHub API errors. |
|
Package graphql provides GitHub GraphQL API utilities.
|
Package graphql provides GitHub GraphQL API utilities. |
|
Package pathutil provides path validation and normalization utilities for GitHub repository paths.
|
Package pathutil provides path validation and normalization utilities for GitHub repository paths. |
|
Package pr provides GitHub pull request operations.
|
Package pr provides GitHub pull request operations. |
|
Package profile provides aggregated GitHub user profile statistics.
|
Package profile provides aggregated GitHub user profile statistics. |
|
readme
Package readme generates GitHub profile README files from user profile data.
|
Package readme generates GitHub profile README files from user profile data. |
|
svg
Package svg provides SVG stats card generation for GitHub profiles.
|
Package svg provides SVG stats card generation for GitHub profiles. |
|
svg/chart
Package chart provides generic SVG chart generation.
|
Package chart provides generic SVG chart generation. |
|
Package release provides GitHub release operations.
|
Package release provides GitHub release operations. |
|
Package repo provides GitHub repository operations.
|
Package repo provides GitHub repository operations. |
|
Package sarif provides helpers for uploading SARIF files to GitHub Code Scanning.
|
Package sarif provides helpers for uploading SARIF files to GitHub Code Scanning. |
|
Package search provides GitHub search API functionality.
|
Package search provides GitHub search API functionality. |
|
Package tag provides GitHub Git tag operations.
|
Package tag provides GitHub Git tag operations. |