github

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatContainerID

func FormatContainerID(owner, repo string) string

FormatContainerID formats owner and repo into a container ID.

func ParseContainerID

func ParseContainerID(containerID string) (owner, repo string, err error)

ParseContainerID parses a container ID into owner and repo. Format: "owner/repo"

Types

type BlobContent added in v0.2.1

type BlobContent struct {
	SHA      string `json:"sha"`
	Content  string `json:"content"`
	Encoding string `json:"encoding"`
	Size     int64  `json:"size"`
	URL      string `json:"url"`
}

BlobContent represents a git blob from GitHub.

type Builder

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

Builder creates GitHub connectors.

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new GitHub connector builder.

func NewBuilderWithConfig

func NewBuilderWithConfig(config *Config) *Builder

NewBuilderWithConfig creates a builder with custom configuration.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, tokenProvider driven.TokenProvider, containerID string) (driven.Connector, error)

Build creates a GitHub connector scoped to a specific repository. containerID format: "owner/repo"

func (*Builder) OAuthConfig

func (b *Builder) OAuthConfig() *driven.OAuthConfig

OAuthConfig returns OAuth configuration for GitHub.

func (*Builder) SupportsContainerSelection

func (b *Builder) SupportsContainerSelection() bool

SupportsContainerSelection returns true - GitHub supports repository selection.

func (*Builder) SupportsOAuth

func (b *Builder) SupportsOAuth() bool

SupportsOAuth returns true - GitHub supports OAuth2.

func (*Builder) Type

func (b *Builder) Type() domain.ProviderType

Type returns the provider type.

type Client

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

Client provides GitHub API operations.

func NewClient

func NewClient(tokenProvider driven.TokenProvider, baseURL string) *Client

NewClient creates a new GitHub API client.

func (*Client) GetBlob added in v0.2.1

func (c *Client) GetBlob(ctx context.Context, owner, repo, sha string) (*BlobContent, error)

GetBlob gets a git blob by SHA (raw file content).

func (*Client) GetFileContent

func (c *Client) GetFileContent(ctx context.Context, owner, repo, path string) (*FileContent, error)

GetFileContent gets the content of a file.

func (*Client) GetIssue added in v0.2.1

func (c *Client) GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)

GetIssue gets a single issue by number.

func (*Client) GetPullRequest added in v0.2.1

func (c *Client) GetPullRequest(ctx context.Context, owner, repo string, number int) (*PullRequest, error)

GetPullRequest gets a single pull request by number.

func (*Client) GetRepository

func (c *Client) GetRepository(ctx context.Context, owner, repo string) (*Repository, error)

GetRepository gets repository information.

func (*Client) GetTree

func (c *Client) GetTree(ctx context.Context, owner, repo, sha string) ([]*TreeEntry, error)

GetTree gets the repository tree (file listing).

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context) (*User, error)

GetUser gets the authenticated user's information.

func (*Client) ListAccessibleRepos

func (c *Client) ListAccessibleRepos(ctx context.Context, cursor string) (*ListReposResponse, error)

ListAccessibleRepos lists all repositories accessible to the authenticated user.

func (*Client) ListIssues

func (c *Client) ListIssues(ctx context.Context, owner, repo string, since *time.Time, cursor string) ([]*Issue, string, error)

ListIssues lists issues for a repository.

func (*Client) ListPullRequests

func (c *Client) ListPullRequests(ctx context.Context, owner, repo string, cursor string) ([]*PullRequest, string, error)

ListPullRequests lists pull requests for a repository.

func (*Client) ValidateRepoAccess

func (c *Client) ValidateRepoAccess(ctx context.Context, owner, repo string) error

ValidateRepoAccess checks if the authenticated user has access to a repository.

type Commit

type Commit struct {
	SHA     string        `json:"sha"`
	Message string        `json:"message"`
	Author  *CommitAuthor `json:"author"`
	Date    time.Time     `json:"date"`
}

Commit represents a GitHub commit.

type CommitAuthor

type CommitAuthor struct {
	Name  string    `json:"name"`
	Email string    `json:"email"`
	Date  time.Time `json:"date"`
}

CommitAuthor represents commit author info.

type Config

type Config struct {
	// APIBaseURL is the base URL for GitHub API.
	// Defaults to https://api.github.com for github.com.
	// For GitHub Enterprise, use https://<hostname>/api/v3
	APIBaseURL string

	// PerPage is the number of items to fetch per page.
	// Maximum is 100.
	PerPage int

	// MaxRetries is the maximum number of retry attempts for rate-limited requests.
	MaxRetries int

	// IncludeFiles enables indexing of repository files.
	IncludeFiles bool

	// IncludeIssues enables indexing of issues.
	IncludeIssues bool

	// IncludePRs enables indexing of pull requests.
	IncludePRs bool

	// IncludeDiscussions enables indexing of discussions.
	IncludeDiscussions bool

	// IncludeWiki enables indexing of wiki pages.
	IncludeWiki bool

	// FileExtensions is a list of file extensions to index.
	// Empty means all text-based files.
	FileExtensions []string

	// ExcludePaths is a list of path patterns to exclude.
	ExcludePaths []string

	// MaxFileSize is the maximum file size in bytes to fetch.
	// Default is 1MB.
	MaxFileSize int64

	// Concurrency is the number of concurrent file content fetches.
	// Default is 10.
	Concurrency int
}

Config contains configuration for the GitHub connector.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default GitHub connector configuration.

type Connector

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

Connector fetches documents from a single GitHub repository.

func NewConnector

func NewConnector(tokenProvider driven.TokenProvider, owner, repo string, config *Config) *Connector

NewConnector creates a GitHub connector scoped to a specific repository.

func (*Connector) FetchChanges

func (c *Connector) FetchChanges(ctx context.Context, source *domain.Source, cursor string) ([]*domain.Change, string, error)

FetchChanges fetches document changes from the repository. For initial sync (empty cursor), it fetches all content. For incremental sync, it fetches changes since the cursor timestamp.

func (*Connector) FetchDocument

func (c *Connector) FetchDocument(ctx context.Context, source *domain.Source, externalID string) (*domain.Document, string, error)

FetchDocument fetches a single document by external ID.

func (*Connector) TestConnection

func (c *Connector) TestConnection(ctx context.Context, source *domain.Source) error

TestConnection tests the connection to the repository.

func (*Connector) Type

func (c *Connector) Type() domain.ProviderType

Type returns the provider type.

func (*Connector) ValidateConfig

func (c *Connector) ValidateConfig(config domain.SourceConfig) error

ValidateConfig validates source configuration.

type ContainerLister

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

ContainerLister lists GitHub repositories accessible with an installation's credentials.

func NewContainerLister

func NewContainerLister(tokenProvider driven.TokenProvider, baseURL string) *ContainerLister

NewContainerLister creates a ContainerLister with the given token provider.

func (*ContainerLister) ListContainers

func (l *ContainerLister) ListContainers(ctx context.Context, cursor string, _ string) ([]*driven.Container, string, error)

ListContainers lists all repositories accessible to the authenticated user. Returns repositories as containers in the format "owner/repo".

type ContainerListerFactory

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

ContainerListerFactory creates ContainerListers for GitHub installations.

func NewContainerListerFactory

func NewContainerListerFactory(
	installationStore driven.ConnectionStore,
	tokenFactory driven.TokenProviderFactory,
	baseURL string,
) *ContainerListerFactory

NewContainerListerFactory creates a factory for GitHub container listers.

func (*ContainerListerFactory) Create

func (f *ContainerListerFactory) Create(ctx context.Context, installationID string) (driven.ContainerLister, error)

Create creates a ContainerLister for a GitHub installation.

type FileContent

type FileContent struct {
	Name     string `json:"name"`
	Path     string `json:"path"`
	SHA      string `json:"sha"`
	Size     int64  `json:"size"`
	Content  string `json:"content"`
	Encoding string `json:"encoding"`
	HTMLURL  string `json:"html_url"`
}

FileContent represents file content from GitHub.

type Issue

type Issue struct {
	ID        int64      `json:"id"`
	Number    int        `json:"number"`
	Title     string     `json:"title"`
	Body      string     `json:"body"`
	State     string     `json:"state"`
	HTMLURL   string     `json:"html_url"`
	User      *User      `json:"user"`
	Labels    []Label    `json:"labels"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	ClosedAt  *time.Time `json:"closed_at"`
	Comments  int        `json:"comments"`
	IsPR      bool       `json:"-"` // Set based on pull_request field presence
}

Issue represents a GitHub issue.

type Label

type Label struct {
	Name  string `json:"name"`
	Color string `json:"color"`
}

Label represents a GitHub label.

type ListReposResponse

type ListReposResponse struct {
	Repos      []*Repository
	NextCursor string
}

ListReposResponse is the response from listing repositories.

type OAuthConfig

type OAuthConfig struct {
	ClientID     string
	ClientSecret string
}

OAuthConfig contains OAuth configuration for GitHub.

type OAuthHandler

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

OAuthHandler handles OAuth operations for GitHub.

func NewOAuthHandler

func NewOAuthHandler() *OAuthHandler

NewOAuthHandler creates a new GitHub OAuth handler.

func (*OAuthHandler) BuildAuthURL

func (h *OAuthHandler) BuildAuthURL(clientID, redirectURI, state, codeChallenge string, scopes []string) string

BuildAuthURL constructs the GitHub OAuth authorization URL.

func (*OAuthHandler) DefaultConfig

func (h *OAuthHandler) DefaultConfig() connectors.OAuthDefaults

DefaultConfig returns GitHub's default OAuth configuration.

func (*OAuthHandler) ExchangeCode

func (h *OAuthHandler) ExchangeCode(ctx context.Context, clientID, clientSecret, code, redirectURI, codeVerifier string) (*driven.OAuthToken, error)

ExchangeCode exchanges an authorization code for tokens.

func (*OAuthHandler) GetUserInfo

func (h *OAuthHandler) GetUserInfo(ctx context.Context, accessToken string) (*driven.OAuthUserInfo, error)

GetUserInfo fetches the authenticated user's information.

func (*OAuthHandler) RefreshToken

func (h *OAuthHandler) RefreshToken(ctx context.Context, clientID, clientSecret, refreshToken string) (*driven.OAuthToken, error)

RefreshToken refreshes an expired access token. Note: GitHub OAuth tokens don't expire by default, but GitHub Apps use refresh tokens.

type PRBranch

type PRBranch struct {
	Ref string `json:"ref"`
	SHA string `json:"sha"`
}

PRBranch represents a PR branch reference.

type PullRequest

type PullRequest struct {
	ID        int64      `json:"id"`
	Number    int        `json:"number"`
	Title     string     `json:"title"`
	Body      string     `json:"body"`
	State     string     `json:"state"`
	HTMLURL   string     `json:"html_url"`
	User      *User      `json:"user"`
	Head      *PRBranch  `json:"head"`
	Base      *PRBranch  `json:"base"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	MergedAt  *time.Time `json:"merged_at"`
	ClosedAt  *time.Time `json:"closed_at"`
}

PullRequest represents a GitHub pull request.

type Repository

type Repository struct {
	ID            int64            `json:"id"`
	Owner         string           `json:"-"` // Populated from FullName, not JSON
	OwnerInfo     *RepositoryOwner `json:"owner"`
	Name          string           `json:"name"`
	FullName      string           `json:"full_name"`
	Description   string           `json:"description"`
	Private       bool             `json:"private"`
	Archived      bool             `json:"archived"`
	HTMLURL       string           `json:"html_url"`
	DefaultBranch string           `json:"default_branch"`
}

Repository represents a GitHub repository.

type RepositoryOwner

type RepositoryOwner struct {
	Login string `json:"login"`
	ID    int64  `json:"id"`
}

RepositoryOwner represents the owner object in GitHub API responses.

type TokenRefresher

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

TokenRefresher implements driven.TokenRefresher for GitHub.

func NewTokenRefresher

func NewTokenRefresher(clientID, clientSecret string) *TokenRefresher

NewTokenRefresher creates a GitHub token refresher.

type TreeEntry

type TreeEntry struct {
	Path string `json:"path"`
	Mode string `json:"mode"`
	Type string `json:"type"` // "blob" or "tree"
	Size int64  `json:"size"`
	SHA  string `json:"sha"`
	URL  string `json:"url"`
}

TreeEntry represents a file in a repository tree.

type User

type User struct {
	ID        int64  `json:"id"`
	Login     string `json:"login"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	HTMLURL   string `json:"html_url"`
	AvatarURL string `json:"avatar_url"`
}

User represents a GitHub user.

Jump to

Keyboard shortcuts

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