github

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertAPIURLToWebURL

func ConvertAPIURLToWebURL(apiURL string) (string, error)

ConvertAPIURLToWebURL converts a GitHub API URL to a web URL

func ListNotifications

func ListNotifications(options NotificationOptions) error

ListNotifications fetches and displays GitHub notifications

func MarkAsRead

func MarkAsRead(id string) error

MarkAsRead marks a notification as read

Types

type BackgroundRefresher

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

BackgroundRefresher manages background refresh of notifications

func NewBackgroundRefresher

func NewBackgroundRefresher(client *Client, interval time.Duration, options NotificationOptions) *BackgroundRefresher

NewBackgroundRefresher creates a new background refresher

func (*BackgroundRefresher) ForceRefresh

func (b *BackgroundRefresher) ForceRefresh()

ForceRefresh forces an immediate refresh

func (*BackgroundRefresher) GetLastError

func (b *BackgroundRefresher) GetLastError() error

GetLastError returns the last error encountered during refresh

func (*BackgroundRefresher) GetNotifications

func (b *BackgroundRefresher) GetNotifications() []*github.Notification

GetNotifications returns the current notifications

func (*BackgroundRefresher) IsRunning

func (b *BackgroundRefresher) IsRunning() bool

IsRunning returns whether the background refresh is running

func (*BackgroundRefresher) SetInterval

func (b *BackgroundRefresher) SetInterval(interval time.Duration)

SetInterval updates the refresh interval

func (*BackgroundRefresher) SetOnUpdateCallback

func (b *BackgroundRefresher) SetOnUpdateCallback(callback func([]*github.Notification))

SetOnUpdateCallback sets a callback function to be called when notifications are updated

func (*BackgroundRefresher) SetOptions

func (b *BackgroundRefresher) SetOptions(options NotificationOptions)

SetOptions updates the notification options

func (*BackgroundRefresher) Start

func (b *BackgroundRefresher) Start()

Start starts the background refresh

func (*BackgroundRefresher) Stop

func (b *BackgroundRefresher) Stop()

Stop stops the background refresh

type CacheManager

type CacheManager struct {
	// Manager is the cache manager
	Manager *cache.Manager

	// Client is the GitHub client
	Client *Client

	// Config is the configuration
	Config *config.Config
}

CacheManager manages the GitHub API cache

func NewCacheManager

func NewCacheManager(client *Client, cfg *config.Config) (*CacheManager, error)

NewCacheManager creates a new cache manager

func (*CacheManager) Close

func (cm *CacheManager) Close() error

Close closes the cache manager

func (*CacheManager) GetNotifications

GetNotifications gets notifications from cache or API

func (*CacheManager) GetRepositoryNotifications

func (cm *CacheManager) GetRepositoryNotifications(ctx context.Context, owner, repo string, opts *github.NotificationListOptions) ([]*github.Notification, *github.Response, error)

GetRepositoryNotifications gets repository notifications from cache or API

func (*CacheManager) InvalidateNotificationsCache

func (cm *CacheManager) InvalidateNotificationsCache()

InvalidateNotificationsCache invalidates the notifications cache

func (*CacheManager) PrefetchNotificationDetails

func (cm *CacheManager) PrefetchNotificationDetails(notifications []*github.Notification)

PrefetchNotificationDetails prefetches notification details

type Client

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

Client wraps the GitHub client with authentication and additional features

func NewClient

func NewClient(ctx context.Context, opts ...ClientOption) (*Client, error)

NewClient creates a new authenticated GitHub client with enhanced features

func NewClientOrExit

func NewClientOrExit(ctx context.Context, opts ...ClientOption) *Client

NewClientOrExit creates a new authenticated GitHub client or exits on error

func NewMockClient

func NewMockClient(ctx context.Context) (*Client, *httptest.Server, error)

NewMockClient creates a new client for testing

func NewTestClient

func NewTestClient(ctx context.Context, handler http.Handler) (*Client, *httptest.Server, error)

NewTestClient creates a new client for testing with a custom handler

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*github.Response, error)

Do performs an HTTP request and returns the API response

func (*Client) FetchNotificationDetails

func (c *Client) FetchNotificationDetails(notifications []*github.Notification) error

FetchNotificationDetails fetches additional details for notifications in parallel

func (*Client) FilterNotifications

func (c *Client) FilterNotifications(notifications []*github.Notification, filterString, sortBy string) []*github.Notification

FilterNotifications filters notifications based on a filter string

func (*Client) GetAllNotifications

func (c *Client) GetAllNotifications(opts NotificationOptions) ([]*github.Notification, error)

GetAllNotifications fetches all notifications with pagination support

func (*Client) GetFilteredNotifications

func (c *Client) GetFilteredNotifications(opts NotificationOptions) ([]*github.Notification, error)

GetFilteredNotifications fetches notifications matching a filter

func (*Client) GetNotification

func (c *Client) GetNotification(id string) (*github.Notification, error)

GetNotification fetches a single notification by ID

func (*Client) GetNotificationsByOrg

func (c *Client) GetNotificationsByOrg(org string, opts NotificationOptions) ([]*github.Notification, error)

GetNotificationsByOrg fetches notifications for a specific organization

func (*Client) GetNotificationsByRepo

func (c *Client) GetNotificationsByRepo(repo string, opts NotificationOptions) ([]*github.Notification, error)

GetNotificationsByRepo fetches notifications for a specific repository

func (*Client) GetRawClient

func (c *Client) GetRawClient() *github.Client

GetRawClient returns the underlying GitHub client

func (*Client) GetThread

func (c *Client) GetThread(threadID string) (*github.Notification, *github.Response, error)

GetThread gets a notification thread

func (*Client) GetUnreadNotifications

func (c *Client) GetUnreadNotifications(opts NotificationOptions) ([]*github.Notification, error)

GetUnreadNotifications fetches only unread notifications

func (*Client) GroupNotifications

func (c *Client) GroupNotifications(ctx context.Context, notifications []*github.Notification, groupBy string) ([]*NotificationGroup, error)

GroupNotifications groups notifications by the specified field

func (*Client) ListNotifications

func (c *Client) ListNotifications(opts *github.NotificationListOptions) ([]*github.Notification, *github.Response, error)

ListNotifications lists GitHub notifications with rate limiting and retries

func (*Client) MarkAllNotificationsRead

func (c *Client) MarkAllNotificationsRead() error

MarkAllNotificationsRead marks all notifications as read

func (*Client) MarkNotificationRead

func (c *Client) MarkNotificationRead(threadID string) error

MarkNotificationRead marks a notification thread as read

func (*Client) MarkRepositoryNotificationsRead

func (c *Client) MarkRepositoryNotificationsRead(owner, repo string) error

MarkRepositoryNotificationsRead marks all notifications in a repository as read

func (*Client) MarkThreadRead

func (c *Client) MarkThreadRead(threadID string) (*github.Response, error)

MarkThreadRead marks a notification thread as read

func (*Client) OptimizedGetAllNotifications

func (c *Client) OptimizedGetAllNotifications(opts NotificationOptions) ([]*github.Notification, error)

OptimizedGetAllNotifications is an optimized version of GetAllNotifications

func (*Client) SetRawClient

func (c *Client) SetRawClient(client *github.Client)

SetRawClient sets the underlying GitHub client

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) *Client

WithContext returns a new Client with the given context

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that configures a Client

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL sets the base URL for the GitHub API

func WithCacheTTL

func WithCacheTTL(cacheTTL time.Duration) ClientOption

WithCacheTTL sets the TTL for cached responses

func WithDebug

func WithDebug(debug bool) ClientOption

WithDebug enables or disables debug logging

func WithMaxConcurrent

func WithMaxConcurrent(maxConcurrent int) ClientOption

WithMaxConcurrent sets the maximum number of concurrent requests

func WithRetryCount

func WithRetryCount(retryCount int) ClientOption

WithRetryCount sets the number of retries for failed requests

func WithRetryDelay

func WithRetryDelay(retryDelay time.Duration) ClientOption

WithRetryDelay sets the delay between retries

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets the timeout for API requests

func WithUploadURL

func WithUploadURL(uploadURL string) ClientOption

WithUploadURL sets the upload URL for the GitHub API

type Filter

type Filter struct {
	Field    string
	Operator string
	Value    string
}

Filter represents a parsed filter

type NotificationGroup

type NotificationGroup struct {
	ID            string                 `json:"id"`
	Name          string                 `json:"name"`
	Type          string                 `json:"type"`
	Count         int                    `json:"count"`
	UnreadCount   int                    `json:"unread_count"`
	Notifications []*github.Notification `json:"notifications"`
}

NotificationGroup represents a group of notifications

type NotificationOptions

type NotificationOptions struct {
	All               bool          // Include all notifications, not just unread ones
	Unread            bool          // Only include unread notifications
	RepoName          string        // Filter by repository name
	OrgName           string        // Filter by organization name
	Since             time.Time     // Only show notifications updated after this time
	Before            time.Time     // Only show notifications updated before this time
	Participating     bool          // Only show notifications in which the user is participating or mentioned
	PerPage           int           // Number of results per page
	Page              int           // Page number
	UseCache          bool          // Whether to use cached results if available
	CacheTTL          time.Duration // How long to cache results
	MaxConcurrent     int           // Maximum number of concurrent requests
	FilterString      string        // Filter string for advanced filtering
	BackgroundRefresh bool          // Whether to refresh cache in the background
	UseETag           bool          // Whether to use ETags for conditional requests
	BatchSize         int           // Size of batches for concurrent requests
	StreamResponse    bool          // Whether to stream the response
	UseOptimized      bool          // Whether to use optimized fetching
}

NotificationOptions contains options for filtering notifications

type NotificationResult

type NotificationResult struct {
	Notifications []*github.Notification
	Response      *github.Response
	Error         error
}

NotificationResult represents the result of a notification fetch operation

type NotificationStream

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

NotificationStream provides a streaming interface for notifications

func NewNotificationStream

func NewNotificationStream(client *Client, options NotificationOptions) *NotificationStream

NewNotificationStream creates a new notification stream

func (*NotificationStream) CollectAll

func (s *NotificationStream) CollectAll() ([]*github.Notification, error)

CollectAll collects all notifications from the stream and returns them as a slice

func (*NotificationStream) Errors

func (s *NotificationStream) Errors() <-chan error

Errors returns a channel of errors

func (*NotificationStream) Notifications

func (s *NotificationStream) Notifications() <-chan *github.Notification

Notifications returns a channel of notifications

func (*NotificationStream) Start

func (s *NotificationStream) Start() error

Start starts the notification stream

func (*NotificationStream) Stop

func (s *NotificationStream) Stop()

Stop stops the notification stream

Jump to

Keyboard shortcuts

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