github

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeFile       = "file"
	ContentEncodingBase64 = "base64"
)

Content.Type and Content.Encoding values used by the GitHub contents API.

Variables

This section is empty.

Functions

func NewVCRRESTClient

func NewVCRRESTClient(httpClient *http.Client) *vcrRESTClient

NewVCRRESTClient creates a new VCR REST client with the given HTTP client

Types

type BatchExecutor

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

BatchExecutor provides a high-level interface for batched API operations

func NewBatchExecutor

func NewBatchExecutor(client Client, workers, rateLimit int) *BatchExecutor

NewBatchExecutor creates a new batch executor

func (*BatchExecutor) FetchRepositoryMetrics

func (be *BatchExecutor) FetchRepositoryMetrics(
	ctx context.Context,
	repos []Repository,
) map[string]*RepositoryMetrics

FetchRepositoryMetrics fetches metrics for multiple repositories in parallel

type CacheEntry

type CacheEntry struct {
	Data      interface{} `json:"data"`
	CachedAt  time.Time   `json:"cached_at"`
	ExpiresAt time.Time   `json:"expires_at"`
	Type      string      `json:"type"`
}

CacheEntry represents a cached API response with metadata

type CachedClient

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

CachedClient wraps a GitHub client with caching capabilities

func NewCachedClient

func NewCachedClient(client Client, cache cache.Cache, config *config.Config) *CachedClient

NewCachedClient creates a new cached GitHub client

func (*CachedClient) GetCacheStats

func (c *CachedClient) GetCacheStats(ctx context.Context) (*cache.Stats, error)

GetCacheStats returns cache statistics

func (*CachedClient) GetCommitActivity

func (c *CachedClient) GetCommitActivity(
	ctx context.Context,
	fullName string,
) (*CommitActivity, error)

GetCommitActivity fetches commit activity with stats-level caching

func (*CachedClient) GetContributors

func (c *CachedClient) GetContributors(
	ctx context.Context,
	fullName string,
	topN int,
) ([]Contributor, error)

GetContributors fetches contributors with stats-level caching

func (*CachedClient) GetHomepageText

func (c *CachedClient) GetHomepageText(ctx context.Context, url string) (string, error)

GetHomepageText fetches homepage text with metadata-level caching

func (*CachedClient) GetIssueCounts

func (c *CachedClient) GetIssueCounts(
	ctx context.Context,
	fullName string,
) (int, int, error)

GetIssueCounts fetches issue counts with stats-level caching

func (*CachedClient) GetLanguages

func (c *CachedClient) GetLanguages(
	ctx context.Context,
	fullName string,
) (map[string]int64, error)

GetLanguages fetches languages with metadata-level caching

func (*CachedClient) GetPullCounts

func (c *CachedClient) GetPullCounts(
	ctx context.Context,
	fullName string,
) (int, int, error)

GetPullCounts fetches PR counts with stats-level caching

func (*CachedClient) GetRepositoryContent

func (c *CachedClient) GetRepositoryContent(
	ctx context.Context,
	repo Repository,
	paths []string,
) ([]Content, error)

GetRepositoryContent fetches repository content with caching

func (*CachedClient) GetRepositoryMetadata

func (c *CachedClient) GetRepositoryMetadata(
	ctx context.Context,
	repo Repository,
) (*Metadata, error)

GetRepositoryMetadata fetches repository metadata with caching

func (*CachedClient) GetStarredRepos

func (c *CachedClient) GetStarredRepos(ctx context.Context, username string) ([]Repository, error)

GetStarredRepos fetches starred repositories with caching

func (*CachedClient) GetTopics

func (c *CachedClient) GetTopics(ctx context.Context, fullName string) ([]string, error)

GetTopics fetches topics with metadata-level caching

func (*CachedClient) InvalidateCache

func (c *CachedClient) InvalidateCache(ctx context.Context, fullName string) error

InvalidateCache removes cached data for a specific repository

type Client

type Client interface {
	// GetStarredRepos fetches all starred repositories for the authenticated user.
	// It handles pagination automatically and respects rate limits.
	// The username parameter is currently unused but reserved for future use.
	GetStarredRepos(ctx context.Context, username string) ([]Repository, error)

	// GetRepositoryContent fetches specific file contents from a repository.
	// It accepts a list of file paths and returns the content for files that exist.
	// Missing files are silently skipped rather than causing an error.
	GetRepositoryContent(ctx context.Context, repo Repository, paths []string) ([]Content, error)

	// GetRepositoryMetadata fetches additional metadata for a repository including
	// commit count, contributors, and release information.
	// Partial failures are handled gracefully - if some metadata cannot be fetched,
	// the available data is still returned.
	GetRepositoryMetadata(ctx context.Context, repo Repository) (*Metadata, error)

	// GetContributors fetches the top N contributors for a repository.
	// Returns contributor login names and their contribution counts.
	GetContributors(ctx context.Context, fullName string, topN int) ([]Contributor, error)

	// GetTopics fetches the topics/tags associated with a repository.
	GetTopics(ctx context.Context, fullName string) ([]string, error)

	// GetLanguages fetches the programming languages used in a repository.
	// Returns a map of language names to byte counts.
	GetLanguages(ctx context.Context, fullName string) (map[string]int64, error)

	// GetCommitActivity fetches commit activity statistics for a repository.
	// Returns weekly commit counts for the last 52 weeks.
	GetCommitActivity(ctx context.Context, fullName string) (*CommitActivity, error)

	// GetPullCounts fetches pull request counts (open and total) for a repository.
	GetPullCounts(ctx context.Context, fullName string) (int, int, error)

	// GetIssueCounts fetches issue counts (open and total) for a repository.
	GetIssueCounts(ctx context.Context, fullName string) (int, int, error)

	// GetHomepageText fetches text content from an external homepage URL.
	// This is optional and used for additional context extraction.
	GetHomepageText(ctx context.Context, url string) (string, error)
}

Client defines the interface for GitHub API operations. It provides methods to fetch starred repositories, repository content, and additional metadata using the GitHub REST API.

func NewClient

func NewClient() (Client, error)

NewClient creates a new GitHub client using existing GitHub CLI authentication

type CommitActivity

type CommitActivity struct {
	Weeks []WeeklyCommits `json:"weeks"`
	Total int             `json:"total"`
}

CommitActivity represents weekly commit activity statistics

type Content

type Content struct {
	Path     string `json:"path"`
	Type     string `json:"type"`
	Content  string `json:"content"`
	Size     int    `json:"size"`
	Encoding string `json:"encoding"`
	SHA      string `json:"sha"`
}

Content represents file content from a repository

type Contributor

type Contributor struct {
	Login         string `json:"login"`
	Contributions int    `json:"contributions"`
	Type          string `json:"type"`
	AvatarURL     string `json:"avatar_url"`
}

Contributor represents a repository contributor

type License

type License struct {
	Key    string `json:"key"`
	Name   string `json:"name"`
	SPDXID string `json:"spdx_id"`
	URL    string `json:"url"`
}

License represents repository license information

type Metadata

type Metadata struct {
	CommitCount    int       `json:"commit_count"`
	Contributors   []string  `json:"contributors"`
	LastCommitDate time.Time `json:"last_commit_date"`
	ReleaseCount   int       `json:"release_count"`
	LatestRelease  *Release  `json:"latest_release"`
}

Metadata represents additional repository metadata

type RESTClientInterface

type RESTClientInterface interface {
	Get(path string, resp interface{}) error
}

RESTClientInterface defines the interface for REST API operations

type Release

type Release struct {
	TagName     string    `json:"tag_name"`
	Name        string    `json:"name"`
	PublishedAt time.Time `json:"published_at"`
	Prerelease  bool      `json:"prerelease"`
	Draft       bool      `json:"draft"`
}

Release represents a GitHub release

type Repository

type Repository struct {
	FullName        string    `json:"full_name"`
	Description     string    `json:"description"`
	Homepage        string    `json:"homepage"`
	Language        string    `json:"language"`
	StargazersCount int       `json:"stargazers_count"`
	ForksCount      int       `json:"forks_count"`
	UpdatedAt       time.Time `json:"updated_at"`
	CreatedAt       time.Time `json:"created_at"`
	Topics          []string  `json:"topics"`
	License         *License  `json:"license"`
	Size            int       `json:"size"`
	DefaultBranch   string    `json:"default_branch"`
	OpenIssuesCount int       `json:"open_issues_count"`
	HasWiki         bool      `json:"has_wiki"`
	HasPages        bool      `json:"has_pages"`
	Archived        bool      `json:"archived"`
	Disabled        bool      `json:"disabled"`
	Private         bool      `json:"private"`
	Fork            bool      `json:"fork"`
}

Repository represents a GitHub repository with essential metadata

type RepositoryMetrics

type RepositoryMetrics struct {
	Contributors   []Contributor
	Topics         []string
	Languages      map[string]int64
	CommitActivity *CommitActivity
	OpenPRs        int
	TotalPRs       int
	OpenIssues     int
	TotalIssues    int
}

RepositoryMetrics aggregates all metrics for a repository

type Result

type Result struct {
	ID    string
	Data  interface{}
	Error error
}

Result represents the result of a task execution

type SearchResult

type SearchResult struct {
	TotalCount        int                      `json:"total_count"`
	IncompleteResults bool                     `json:"incomplete_results"`
	Items             []map[string]interface{} `json:"items"`
}

SearchResult represents a search result from GitHub API

type Task

type Task struct {
	ID   string
	Func func(ctx context.Context) (interface{}, error)
}

Task represents a unit of work for the worker pool

type WeeklyCommits

type WeeklyCommits struct {
	Week    int64 `json:"w"` // Unix timestamp for the start of the week
	Commits int   `json:"c"` // Number of commits
	Adds    int   `json:"a"` // Lines added
	Deletes int   `json:"d"` // Lines deleted
}

WeeklyCommits represents commit counts for a specific week

type WorkerPool

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

WorkerPool manages parallel execution of GitHub API calls with rate limiting and backoff

func NewWorkerPool

func NewWorkerPool(workers, rateLimit int, backoffBase, maxBackoff time.Duration) *WorkerPool

NewWorkerPool creates a new worker pool for GitHub API calls

func (*WorkerPool) Execute

func (wp *WorkerPool) Execute(ctx context.Context, tasks []Task) []Result

Execute runs tasks in parallel with rate limiting and backoff

Jump to

Keyboard shortcuts

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