github

package
v0.0.0-...-0ad7e56 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

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

APIClient implements the GitHubClient interface using go-github

func NewAPIClient

func NewAPIClient(token string) *APIClient

NewAPIClient creates a new GitHub API client

func (*APIClient) GetRateLimit

func (a *APIClient) GetRateLimit(ctx context.Context) (*RateLimitInfo, error)

GetRateLimit returns current rate limit status

func (*APIClient) GetStarredRepositories

func (a *APIClient) GetStarredRepositories(ctx context.Context, username string, opts *StarredOptions) (*StarredResponse, error)

GetStarredRepositories fetches all starred repositories for a user

func (*APIClient) ValidateToken

func (a *APIClient) ValidateToken(ctx context.Context, token string) (bool, error)

ValidateToken validates a GitHub personal access token

func (*APIClient) ValidateUser

func (a *APIClient) ValidateUser(ctx context.Context, username string) error

ValidateUser checks if a GitHub username exists

type APIResponse

type APIResponse struct {
	RateLimit       RateLimitInfo        `json:"rate_limit"`       // Current rate limit status
	PageInfo        PageInfo             `json:"page_info"`        // Pagination metadata
	Repositories    []storage.Repository `json:"repositories"`     // Repository data from current API call
	RequestDuration time.Duration        `json:"request_duration"` // Time taken for API request
	StatusCode      int                  `json:"status_code"`      // HTTP response status code
}

APIResponse represents structured data from GitHub API calls for rate limiting and pagination

func (*APIResponse) Validate

func (a *APIResponse) Validate() error

Validate checks if the APIResponse has valid field values

type GitHubClient

type GitHubClient interface {
	// GetStarredRepositories fetches all starred repositories for a user
	// Returns paginated results with rate limit information
	GetStarredRepositories(ctx context.Context, username string, opts *StarredOptions) (*StarredResponse, error)

	// GetRateLimit returns current rate limit status
	GetRateLimit(ctx context.Context) (*RateLimitInfo, error)

	// ValidateUser checks if a GitHub username exists
	ValidateUser(ctx context.Context, username string) error
}

GitHubClient defines the interface for interacting with the GitHub API

type PageInfo

type PageInfo struct {
	HasNext    bool   `json:"has_next"`    // Whether more pages are available
	NextCursor string `json:"next_cursor"` // Cursor for next page (GitHub pagination)
	TotalCount int    `json:"total_count"` // Total items across all pages
	PerPage    int    `json:"per_page"`    // Items per page
}

PageInfo contains pagination metadata for GitHub API responses

type RateLimitError

type RateLimitError struct {
	ResetTime string
	Limit     int
	Used      int
}

RateLimitError represents an error when API rate limit is exceeded

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type RateLimitInfo

type RateLimitInfo struct {
	Limit     int       `json:"limit"`      // Maximum requests per hour
	Remaining int       `json:"remaining"`  // Requests remaining in current window
	ResetTime time.Time `json:"reset_time"` // When rate limit resets
	Used      int       `json:"used"`       // Requests used in current window
}

RateLimitInfo contains GitHub API rate limit information

type StarredOptions

type StarredOptions struct {
	Cursor    string `json:"cursor"`    // Page pagination cursor (empty for first page)
	PerPage   int    `json:"per_page"`  // Number of items per page (max 100)
	Sort      string `json:"sort"`      // Sort order: "created", "updated", "pushed", "full_name"
	Direction string `json:"direction"` // Direction: "asc" or "desc"
}

StarredOptions contains options for fetching starred repositories

type StarredResponse

type StarredResponse struct {
	Repositories []storage.Repository `json:"repositories"`
	PageInfo     PageInfo             `json:"page_info"`
	RateLimit    RateLimitInfo        `json:"rate_limit"`
}

StarredResponse represents the response from GetStarredRepositories

type UserNotFoundError

type UserNotFoundError struct {
	Username string
}

UserNotFoundError represents an error when a GitHub user doesn't exist

func (*UserNotFoundError) Error

func (e *UserNotFoundError) Error() string

Jump to

Keyboard shortcuts

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