github

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeRateLimit  = "rate_limit"
	ErrorTypeTimeout    = "timeout"
	ErrorTypePermission = "permission"
	ErrorTypeNotFound   = "not_found"
	ErrorTypeNetwork    = "network"
	ErrorTypeUnknown    = "unknown"
)

Error type constants for GitHub API error classification

Variables

This section is empty.

Functions

func ClassifyGitHubError added in v1.1.0

func ClassifyGitHubError(err error) string

ClassifyGitHubError classifies GitHub API errors for better logging and handling. This works for any GitHub API error (REST, GraphQL, notifications, stars, etc.)

func ConvertAPIURLToWeb added in v1.1.0

func ConvertAPIURLToWeb(apiURL string) string

ConvertAPIURLToWeb converts GitHub API URLs to web URLs. Example: https://api.github.com/repos/owner/repo/issues/123 -> https://github.com/owner/repo/issues/123

func GetName added in v1.1.0

func GetName(repoFullName string) string

GetName extracts the repository name from a full repository name. Example: "owner/repo" returns "repo"

func GetOwner added in v1.1.0

func GetOwner(repoFullName string) string

GetOwner extracts the owner from a full repository name. Example: "owner/repo" returns "owner"

Types

type Client

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

Client is the main GitHub API client that wraps REST and GraphQL clients

func NewClient

func NewClient() (*Client, error)

NewClient creates a new GitHub API client using default gh CLI authentication

func NewTestClient added in v1.1.0

func NewTestClient(restClient RESTClient, graphqlClient GraphQLClient) *Client

NewTestClient creates a client with injected dependencies for testing

func (*Client) FetchNotifications

func (c *Client) FetchNotifications() ([]cache.CacheEntry, error)

FetchNotifications fetches unread GitHub notifications from the REST API. It returns a list of cache entries containing notification details. Only unread notifications are fetched (GitHub API default behavior).

func (*Client) FetchRecentStars added in v1.1.0

func (c *Client) FetchRecentStars(since time.Time) ([]cache.StarEvent, error)

FetchRecentStars fetches recent star events using GraphQL with pagination and concurrent processing. It queries all user-owned repositories and fetches stars that occurred after the 'since' timestamp. Uses a worker pool (6 workers) to fetch stars concurrently while respecting rate limits. Returns stars sorted by StarredAt time (newest first).

func (*Client) GetAuthenticatedUser added in v1.1.0

func (c *Client) GetAuthenticatedUser() (string, error)

GetAuthenticatedUser returns the username of the authenticated user

func (*Client) TestAuth

func (c *Client) TestAuth() error

TestAuth verifies that the GitHub authentication is working

type GitHubClientInterface added in v1.1.0

type GitHubClientInterface interface {
	FetchNotifications() ([]cache.CacheEntry, error)
	FetchRecentStars(since time.Time) ([]cache.StarEvent, error)
	GetAuthenticatedUser() (string, error)
	TestAuth() error
}

GitHubClientInterface defines the main client interface for testing

type GraphQLClient added in v1.1.0

type GraphQLClient interface {
	Do(query string, variables map[string]interface{}, response interface{}) error
}

GraphQLClient wraps the external GraphQL client for mocking

type RESTClient added in v1.1.0

type RESTClient interface {
	Get(path string, response interface{}) error
}

RESTClient wraps the external REST client for mocking

type ReposResponse added in v1.1.0

type ReposResponse struct {
	Viewer struct {
		Repositories struct {
			Nodes []struct {
				NameWithOwner string `json:"nameWithOwner"`
			} `json:"nodes"`
		} `json:"repositories"`
	} `json:"viewer"`
}

ReposResponse represents the GraphQL response for fetching repositories

type StarsResponse added in v1.1.0

type StarsResponse struct {
	Repository struct {
		Stargazers struct {
			Edges []struct {
				StarredAt time.Time `json:"starredAt"`
				Cursor    string    `json:"cursor"`
				Node      struct {
					Login string `json:"login"`
				} `json:"node"`
			} `json:"edges"`
			PageInfo struct {
				HasNextPage bool   `json:"hasNextPage"`
				EndCursor   string `json:"endCursor"`
			} `json:"pageInfo"`
		} `json:"stargazers"`
	} `json:"repository"`
}

StarsResponse represents the GraphQL response for fetching stargazers

Jump to

Keyboard shortcuts

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