Documentation
¶
Overview ¶
Package github provides a client for interacting with the GitHub API.
Index ¶
- Variables
- func CompareAPIEfficiency() map[string]any
- func ExtractSocialMediaFromHTML(html string) []string
- type ActivityDataResponse
- type Client
- func (c *Client) FetchActivityWithGraphQL(ctx context.Context, username string) ([]PullRequest, []Issue, error)
- func (c *Client) FetchCommentsWithGraphQL(ctx context.Context, username string) ([]Comment, error)
- func (c *Client) FetchIssues(ctx context.Context, username string) ([]Issue, error)
- func (c *Client) FetchIssuesWithLimit(ctx context.Context, username string, maxPages int) ([]Issue, error)
- func (c *Client) FetchOrganizations(ctx context.Context, username string) ([]Organization, error)
- func (c *Client) FetchPinnedRepositories(ctx context.Context, username string) ([]Repository, error)
- func (c *Client) FetchPopularRepositories(ctx context.Context, username string) ([]Repository, error)
- func (c *Client) FetchProfileHTML(ctx context.Context, username string) string
- func (c *Client) FetchPublicEvents(ctx context.Context, username string) ([]PublicEvent, error)
- func (c *Client) FetchPullRequests(ctx context.Context, username string) ([]PullRequest, error)
- func (c *Client) FetchPullRequestsWithLimit(ctx context.Context, username string, maxPages int) ([]PullRequest, error)
- func (c *Client) FetchSocialFromHTML(ctx context.Context, username string) []string
- func (c *Client) FetchStarredRepositories(ctx context.Context, username string) ([]time.Time, []Repository, error)
- func (c *Client) FetchUserComments(ctx context.Context, username string) ([]Comment, error)
- func (c *Client) FetchUserCommitActivities(ctx context.Context, username string) ([]CommitActivity, error)
- func (c *Client) FetchUserCommitActivitiesGraphQL(ctx context.Context, username string, maxCommits int) ([]CommitActivity, error)
- func (c *Client) FetchUserCommitActivitiesWithLimit(ctx context.Context, username string, maxPages int) ([]CommitActivity, error)
- func (c *Client) FetchUserCommits(ctx context.Context, username string) ([]time.Time, error)
- func (c *Client) FetchUserCommitsWithLimit(ctx context.Context, username string, maxPages int) ([]time.Time, error)
- func (c *Client) FetchUserEnhancedGraphQL(ctx context.Context, username string) (*User, []Repository, []PullRequest, []Issue, error)
- func (c *Client) FetchUserGists(ctx context.Context, username string) ([]time.Time, error)
- func (c *Client) FetchUserGistsDetails(ctx context.Context, username string) ([]Gist, error)
- func (c *Client) FetchUserRepositories(ctx context.Context, username string) ([]Repository, error)
- func (c *Client) FetchUserSSHKeys(ctx context.Context, username string) ([]SSHKey, error)
- type Comment
- type CommentDataResponse
- type CommitActivity
- type Gist
- type GraphQLClient
- func (c *GraphQLClient) FetchActivityData(ctx context.Context, username string, prCursor, issueCursor string) (*ActivityDataResponse, error)
- func (c *GraphQLClient) FetchComments(ctx context.Context, username string, issueCursor, commitCursor string) (*CommentDataResponse, error)
- func (c *GraphQLClient) FetchUserProfile(ctx context.Context, username string) (*UserProfileResponse, error)
- type GraphQLError
- type GraphQLResponse
- type Issue
- type IssueSearchItem
- type Organization
- type PRSearchItem
- type PublicEvent
- type PullRequest
- type Repository
- type SSHKey
- type SocialAccount
- type User
- type UserProfileResponse
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoGitHubToken = errors.New("no GitHub token available") ErrUserNotFound = errors.New("user not found") )
Common errors.
Functions ¶
func CompareAPIEfficiency ¶
CompareAPIEfficiency shows the efficiency gains from using GraphQL.
func ExtractSocialMediaFromHTML ¶
ExtractSocialMediaFromHTML extracts social media links from GitHub profile HTML.
Types ¶
type ActivityDataResponse ¶
type ActivityDataResponse struct {
User struct {
PullRequests struct {
Nodes []struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Repository struct {
Name string `json:"name"`
Owner struct {
Login string `json:"login"`
} `json:"owner"`
} `json:"repository"`
Title string `json:"title"`
URL string `json:"url"`
State string `json:"state"`
Number int `json:"number"`
} `json:"nodes"`
PageInfo struct {
EndCursor string `json:"endCursor"`
HasNextPage bool `json:"hasNextPage"`
} `json:"pageInfo"`
TotalCount int `json:"totalCount"`
} `json:"pullRequests"`
Issues struct {
Nodes []struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Repository struct {
Name string `json:"name"`
Owner struct {
Login string `json:"login"`
} `json:"owner"`
} `json:"repository"`
Title string `json:"title"`
URL string `json:"url"`
State string `json:"state"`
Number int `json:"number"`
} `json:"nodes"`
PageInfo struct {
EndCursor string `json:"endCursor"`
HasNextPage bool `json:"hasNextPage"`
} `json:"pageInfo"`
TotalCount int `json:"totalCount"`
} `json:"issues"`
} `json:"user"`
}
ActivityDataResponse for paginated activity data.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides methods for interacting with the GitHub API.
func NewClient ¶
func NewClient(logger *slog.Logger, httpClient *http.Client, githubToken string, cachedHTTPDo func(context.Context, *http.Request) (*http.Response, error), ) *Client
NewClient creates a new GitHub API client.
func (*Client) FetchActivityWithGraphQL ¶
func (c *Client) FetchActivityWithGraphQL(ctx context.Context, username string) ([]PullRequest, []Issue, error)
FetchActivityWithGraphQL fetches PRs and Issues using GraphQL This is MUCH more efficient than the search API: - Single query vs multiple search requests - 5000 points/hour vs 30 requests/minute - Can fetch 100 PRs + 100 issues in one request.
func (*Client) FetchCommentsWithGraphQL ¶
FetchCommentsWithGraphQL fetches both issue comments (includes PR comments) and commit comments using GraphQL.
func (*Client) FetchIssues ¶
FetchIssues fetches issues for a user with default page limit.
func (*Client) FetchIssuesWithLimit ¶
func (c *Client) FetchIssuesWithLimit(ctx context.Context, username string, maxPages int) ([]Issue, error)
FetchIssuesWithLimit fetches issues for a user with custom page limit.
func (*Client) FetchOrganizations ¶
FetchOrganizations fetches organizations that a user belongs to.
func (*Client) FetchPinnedRepositories ¶
func (c *Client) FetchPinnedRepositories(ctx context.Context, username string) ([]Repository, error)
FetchPinnedRepositories fetches repositories pinned by a user via GraphQL.
func (*Client) FetchPopularRepositories ¶
func (c *Client) FetchPopularRepositories(ctx context.Context, username string) ([]Repository, error)
FetchPopularRepositories fetches user's most popular repositories sorted by stars.
func (*Client) FetchProfileHTML ¶
FetchProfileHTML fetches the raw HTML of a GitHub profile page.
func (*Client) FetchPublicEvents ¶
FetchPublicEvents fetches public events (limited to last 30 days by GitHub API).
func (*Client) FetchPullRequests ¶
FetchPullRequests fetches pull requests for a user with default page limit.
func (*Client) FetchPullRequestsWithLimit ¶
func (c *Client) FetchPullRequestsWithLimit(ctx context.Context, username string, maxPages int) ([]PullRequest, error)
FetchPullRequestsWithLimit fetches pull requests for a user with custom page limit.
func (*Client) FetchSocialFromHTML ¶
FetchSocialFromHTML scrapes GitHub profile HTML for social media links.
func (*Client) FetchStarredRepositories ¶
func (c *Client) FetchStarredRepositories(ctx context.Context, username string) ([]time.Time, []Repository, error)
FetchStarredRepositories fetches repositories the user has starred for additional timestamp data and repository details.
func (*Client) FetchUserComments ¶
FetchUserComments fetches recent comments made by a user via GraphQL.
func (*Client) FetchUserCommitActivities ¶
func (c *Client) FetchUserCommitActivities(ctx context.Context, username string) ([]CommitActivity, error)
FetchUserCommitActivities fetches commit activities with repository information using GraphQL.
func (*Client) FetchUserCommitActivitiesGraphQL ¶
func (c *Client) FetchUserCommitActivitiesGraphQL(ctx context.Context, username string, maxCommits int) ([]CommitActivity, error)
FetchUserCommitActivitiesGraphQL fetches commit activities using REST API fallback. NOTE: GitHub's GraphQL search API doesn't support COMMIT type, so we use REST API.
func (*Client) FetchUserCommitActivitiesWithLimit ¶
func (c *Client) FetchUserCommitActivitiesWithLimit(ctx context.Context, username string, maxPages int) ([]CommitActivity, error)
FetchUserCommitActivitiesWithLimit fetches commit activities with repository info and configurable page limit.
func (*Client) FetchUserCommits ¶
FetchUserCommits fetches commit timestamps for a user's recent commits across their repositories.
func (*Client) FetchUserCommitsWithLimit ¶
func (c *Client) FetchUserCommitsWithLimit(ctx context.Context, username string, maxPages int) ([]time.Time, error)
FetchUserCommitsWithLimit fetches commit timestamps with a configurable page limit.
func (*Client) FetchUserEnhancedGraphQL ¶
func (c *Client) FetchUserEnhancedGraphQL( ctx context.Context, username string, ) (*User, []Repository, []PullRequest, []Issue, error)
FetchUserEnhancedGraphQL fetches comprehensive user data using our enhanced GraphQL implementation This replaces multiple REST API calls with a single GraphQL query.
func (*Client) FetchUserGists ¶
FetchUserGists fetches gist timestamps for a user.
func (*Client) FetchUserGistsDetails ¶
FetchUserGistsDetails fetches full gist objects with descriptions for a user.
func (*Client) FetchUserRepositories ¶
FetchUserRepositories fetches public repositories owned by a user.
type Comment ¶
type Comment struct {
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
HTMLURL string `json:"html_url"`
Repository string `json:"repository"` // Repository name (owner/repo)
}
Comment represents a GitHub comment (issue or commit).
type CommentDataResponse ¶
type CommentDataResponse struct {
User struct {
// Issue comments (includes comments on both issues and PRs)
IssueComments struct {
Nodes []struct {
CreatedAt time.Time `json:"createdAt"`
Body string `json:"body"`
URL string `json:"url"`
} `json:"nodes"`
PageInfo struct {
EndCursor string `json:"endCursor"`
HasNextPage bool `json:"hasNextPage"`
} `json:"pageInfo"`
} `json:"issueComments"`
// Commit comments
CommitComments struct {
Nodes []struct {
CreatedAt time.Time `json:"createdAt"`
Commit struct {
URL string `json:"url"`
} `json:"commit"`
Body string `json:"body"`
} `json:"nodes"`
PageInfo struct {
EndCursor string `json:"endCursor"`
HasNextPage bool `json:"hasNextPage"`
} `json:"pageInfo"`
} `json:"commitComments"`
} `json:"user"`
}
CommentDataResponse for paginated comments.
type CommitActivity ¶
type CommitActivity struct {
AuthorDate time.Time `json:"author_date"`
Repository string `json:"repository"`
AuthorName string `json:"author_name"`
AuthorEmail string `json:"author_email"`
CommitterName string `json:"committer_name"`
CommitterEmail string `json:"committer_email"`
RepositoryID int `json:"repository_id"`
}
CommitActivity represents a commit with repository information.
type Gist ¶
type Gist struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID string `json:"id"`
Description string `json:"description"`
HTMLURL string `json:"html_url"`
Public bool `json:"public"`
}
Gist represents a GitHub gist.
type GraphQLClient ¶
type GraphQLClient struct {
// contains filtered or unexported fields
}
GraphQLClient handles GitHub GraphQL API requests.
func NewGraphQLClient ¶
func NewGraphQLClient(token string, cachedHTTPDo func(context.Context, *http.Request) (*http.Response, error), logger *slog.Logger) *GraphQLClient
NewGraphQLClient creates a new GraphQL client.
func (*GraphQLClient) FetchActivityData ¶
func (c *GraphQLClient) FetchActivityData(ctx context.Context, username string, prCursor, issueCursor string) (*ActivityDataResponse, error)
FetchActivityData fetches PRs and Issues in a single paginated query.
func (*GraphQLClient) FetchComments ¶
func (c *GraphQLClient) FetchComments(ctx context.Context, username string, issueCursor, commitCursor string) (*CommentDataResponse, error)
FetchComments fetches both issue comments (which include PR comments) and commit comments.
func (*GraphQLClient) FetchUserProfile ¶
func (c *GraphQLClient) FetchUserProfile(ctx context.Context, username string) (*UserProfileResponse, error)
FetchUserProfile fetches all non-paginated user data in a single query.
type GraphQLError ¶
GraphQLError represents an error in a GraphQL response.
type GraphQLResponse ¶
type GraphQLResponse struct {
Data json.RawMessage `json:"data"`
Errors []GraphQLError `json:"errors,omitempty"`
}
GraphQLResponse represents the response from a GraphQL query.
type Issue ¶
type Issue struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
HTMLURL string `json:"html_url"`
RepoName string
Number int `json:"number"`
}
Issue represents a GitHub issue.
type IssueSearchItem ¶
type IssueSearchItem struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
HTMLURL string `json:"html_url"`
Repository struct {
FullName string `json:"full_name"`
} `json:"repository"`
Number int `json:"number"`
}
IssueSearchItem represents a GitHub issue search result.
type Organization ¶
type Organization struct {
Login string `json:"login"`
Name string `json:"name"`
Description string `json:"description"`
Location string `json:"location"`
Blog string `json:"blog"`
}
Organization represents a GitHub organization.
type PRSearchItem ¶
type PRSearchItem struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
HTMLURL string `json:"html_url"`
Repository struct {
FullName string `json:"full_name"`
} `json:"repository"`
Number int `json:"number"`
}
PRSearchItem represents a GitHub pull request search result.
type PublicEvent ¶
type PublicEvent struct {
ID string `json:"id"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
Repo struct {
Name string `json:"name"`
URL string `json:"url"`
} `json:"repo"`
Payload json.RawMessage `json:"payload"`
}
PublicEvent represents a GitHub public event.
type PullRequest ¶
type PullRequest struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
MergedAt *time.Time `json:"merged_at"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
HTMLURL string `json:"html_url"`
RepoName string
Number int `json:"number"`
}
PullRequest represents a GitHub pull request.
type Repository ¶
type Repository struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
PushedAt time.Time `json:"pushed_at"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
Language string `json:"language"`
HTMLURL string `json:"html_url"`
Topics []string `json:"topics"`
StarCount int `json:"stargazers_count"`
Fork bool `json:"fork"`
}
Repository represents a GitHub repository.
type SSHKey ¶
type SSHKey struct {
CreatedAt time.Time `json:"created_at"`
Key string `json:"key"`
Title string `json:"title"`
URL string `json:"url"`
ID int `json:"id"`
Verified bool `json:"verified"`
ReadOnly bool `json:"read_only"`
}
SSHKey represents a GitHub SSH public key.
type SocialAccount ¶
type SocialAccount struct {
Provider string `json:"provider"`
URL string `json:"url"`
DisplayName string `json:"displayName"`
}
SocialAccount represents a social media account linked to GitHub profile.
type User ¶
type User struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Bio string `json:"bio"`
Blog string `json:"blog"`
Company string `json:"company"`
Email string `json:"email"`
Login string `json:"login"`
TwitterHandle string `json:"twitter_username"`
Location string `json:"location"`
Name string `json:"name"`
ProfileHTML string
SocialAccounts []SocialAccount `json:"socialAccounts,omitempty"`
Followers int `json:"followers"`
Following int `json:"following"`
PublicRepos int `json:"public_repos"`
}
User represents a GitHub user profile.
type UserProfileResponse ¶
type UserProfileResponse struct {
User struct {
Repositories struct {
Nodes []struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
PushedAt time.Time `json:"pushedAt"`
PrimaryLanguage struct {
Name string `json:"name"`
} `json:"primaryLanguage"`
Name string `json:"name"`
NameWithOwner string `json:"nameWithOwner"`
Description string `json:"description"`
URL string `json:"url"`
StargazerCount int `json:"stargazerCount"`
IsFork bool `json:"isFork"`
} `json:"nodes"`
TotalCount int `json:"totalCount"`
} `json:"repositories"`
// Pull requests
PullRequests struct {
Nodes []struct {
Title string `json:"title"`
Body string `json:"body"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
URL string `json:"url"`
State string `json:"state"`
Repository struct {
NameWithOwner string `json:"nameWithOwner"`
} `json:"repository"`
} `json:"nodes"`
TotalCount int `json:"totalCount"`
} `json:"pullRequests"`
// Issues
Issues struct {
Nodes []struct {
Title string `json:"title"`
Body string `json:"body"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
URL string `json:"url"`
State string `json:"state"`
Repository struct {
NameWithOwner string `json:"nameWithOwner"`
} `json:"repository"`
} `json:"nodes"`
TotalCount int `json:"totalCount"`
} `json:"issues"`
ContributionsCollection struct {
StartedAt time.Time `json:"startedAt"`
EndedAt time.Time `json:"endedAt"`
TotalCommitContributions int `json:"totalCommitContributions"`
TotalPullRequestContributions int `json:"totalPullRequestContributions"`
TotalIssueContributions int `json:"totalIssueContributions"`
} `json:"contributionsCollection"`
// Starred repositories
StarredRepositories struct {
Nodes []struct {
PrimaryLanguage struct {
Name string `json:"name"`
} `json:"primaryLanguage"`
Name string `json:"name"`
NameWithOwner string `json:"nameWithOwner"`
Description string `json:"description"`
URL string `json:"url"`
StargazerCount int `json:"stargazerCount"`
} `json:"nodes"`
TotalCount int `json:"totalCount"`
} `json:"starredRepositories"`
// Gists
Gists struct {
Nodes []struct {
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Description string `json:"description"`
URL string `json:"url"`
IsPublic bool `json:"isPublic"`
} `json:"nodes"`
TotalCount int `json:"totalCount"`
} `json:"gists"`
// Social accounts
SocialAccounts struct {
Nodes []struct {
Provider string `json:"provider"`
URL string `json:"url"`
DisplayName string `json:"displayName"`
} `json:"nodes"`
} `json:"socialAccounts"`
// Organizations
Organizations struct {
Nodes []struct {
Name string `json:"name"`
Login string `json:"login"`
Location string `json:"location"`
Description string `json:"description"`
} `json:"nodes"`
} `json:"organizations"`
// Statistics
Followers struct {
TotalCount int `json:"totalCount"`
} `json:"followers"`
Following struct {
TotalCount int `json:"totalCount"`
} `json:"following"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Login string `json:"login"`
Email string `json:"email"`
Location string `json:"location"`
Bio string `json:"bio"`
Company string `json:"company"`
Blog string `json:"websiteUrl"`
TwitterUsername string `json:"twitterUsername"`
} `json:"user"`
}
UserProfileResponse for non-paginated user data.