Documentation
¶
Index ¶
- func CloneRepository(session GithubSessionInterface, options CloneOptions) (*git.Repository, error)
- func CloneRepositoryNoCheckout(session GithubSessionInterface, repositoryURL, workDir, branch string) (*git.Repository, error)
- func CloneRepositorySimple(session GithubSessionInterface, repositoryURL, workDir, branch string) (*git.Repository, error)
- func CloneRepositoryWithAuth(session GithubSessionInterface, repositoryURL, workDir, branch string, ...) (*git.Repository, error)
- func CommitAllChangesWithToken(repo *git.Repository, branch, message string, githubAccessToken string) (string, error)
- func CommitChanges(repo *git.Repository, options CommitOptions) (string, error)
- func CommitChangesWithToken(repo *git.Repository, branch, message string, files []string, ...) (string, error)
- func CreateCheckRun(ctx context.Context, session GithubSessionInterface, options CheckRunOptions) error
- func CreateCheckRunSimple(ctx context.Context, session GithubSessionInterface, ...) error
- type AuthorInfo
- type CheckRunOptions
- type CloneOptions
- type CommitOptions
- type GithubConfig
- type GithubSession
- func (s *GithubSession) AuthToken() *oauth2.Token
- func (s *GithubSession) Client() *github.Client
- func (s *GithubSession) CreatePullRequest(ctx context.Context, owner, repo string, opts *PullRequestOptions) (*github.PullRequest, error)
- func (s *GithubSession) CreatePullRequestSimple(ctx context.Context, owner, repo, title, head, base string) (*github.PullRequest, error)
- type GithubSessionInterface
- type GraphQLClient
- func (g *GraphQLClient) ClearCache()
- func (g *GraphQLClient) DiscoverInstallationID(ctx context.Context, org string) (int64, error)
- func (g *GraphQLClient) GetAPIBaseURL() string
- func (g *GraphQLClient) GetCachedInstallationIDs() map[string]int64
- func (g *GraphQLClient) GetClientForOrg(ctx context.Context, org string) (*githubv4.Client, error)
- func (g *GraphQLClient) GetCommitAncestry(ctx context.Context, owner, repo, ref string, depth int) ([]string, error)
- func (g *GraphQLClient) GetGraphQLURL() string
- type GraphQLConfig
- type Installation
- type PullRequestOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneRepository ¶
func CloneRepository(session GithubSessionInterface, options CloneOptions) (*git.Repository, error)
CloneRepository clones the specified GitHub repository with the provided options
func CloneRepositoryNoCheckout ¶ added in v1.3.12
func CloneRepositoryNoCheckout(session GithubSessionInterface, repositoryURL, workDir, branch string) (*git.Repository, error)
CloneRepositoryNoCheckout is a convenience function that clones a repository without checking out files
func CloneRepositorySimple ¶ added in v1.3.11
func CloneRepositorySimple(session GithubSessionInterface, repositoryURL, workDir, branch string) (*git.Repository, error)
CloneRepositorySimple is a convenience function that clones a repository with basic options
func CloneRepositoryWithAuth ¶ added in v1.3.11
func CloneRepositoryWithAuth( session GithubSessionInterface, repositoryURL, workDir, branch string, auth *ghhttp.BasicAuth, gitOptions *git.CloneOptions, ) (*git.Repository, error)
CloneRepositoryWithAuth is a convenience function that clones a repository with custom authentication
func CommitAllChangesWithToken ¶ added in v1.3.11
func CommitAllChangesWithToken( repo *git.Repository, branch, message string, githubAccessToken string, ) (string, error)
CommitAllChangesWithToken is a convenience function that commits all changes with token authentication
func CommitChanges ¶ added in v1.3.11
func CommitChanges(repo *git.Repository, options CommitOptions) (string, error)
CommitChanges commits changes to the repository with the provided options
func CommitChangesWithToken ¶ added in v1.3.11
func CommitChangesWithToken( repo *git.Repository, branch, message string, files []string, githubAccessToken string, ) (string, error)
CommitChangesWithToken is a convenience function that creates CommitOptions with token authentication
func CreateCheckRun ¶
func CreateCheckRun(ctx context.Context, session GithubSessionInterface, options CheckRunOptions) error
CreateCheckRun creates a check run in the specified GitHub repository with the provided options
func CreateCheckRunSimple ¶ added in v1.3.11
func CreateCheckRunSimple( ctx context.Context, session GithubSessionInterface, headSHA, repo, org, name, title, conclusion, status, summary string, ) error
CreateCheckRunSimple is a convenience function that creates a basic check run
Types ¶
type AuthorInfo ¶ added in v1.3.11
AuthorInfo defines the author information for commits
func GetDefaultAuthor ¶ added in v1.3.11
func GetDefaultAuthor() AuthorInfo
GetDefaultAuthor provides a default author configuration
type CheckRunOptions ¶ added in v1.3.11
type CheckRunOptions struct {
// Required fields
HeadSHA string
Repository string
Org string
Name string
// Optional fields with defaults
Title string
Conclusion string
Status string
Summary string
Text string
// Advanced options
DetailsURL string
ExternalID string
StartedAt *time.Time
CompletedAt *time.Time
Actions []*github.CheckRunAction
Images []*github.CheckRunImage
Annotations []*github.CheckRunAnnotation
}
CheckRunOptions defines the configuration for creating check runs
type CloneOptions ¶ added in v1.3.11
type CloneOptions struct {
// Repository URL to clone
RepositoryURL string
// Local directory to clone into
WorkDir string
// Branch to clone (optional, defaults to default branch)
Branch string
// Authentication credentials (optional, will use session token if not provided)
Auth *ghhttp.BasicAuth
// Git clone options (optional, will use defaults if not provided)
GitCloneOptions *git.CloneOptions
// Progress output (optional, defaults to os.Stdout)
Progress *os.File
// Single branch clone (defaults to true)
SingleBranch bool
// Clone depth (defaults to 1 for shallow clone)
Depth int
// No checkout - clone without checking out files (defaults to false)
NoCheckout bool
}
CloneOptions defines the configuration for cloning repositories
func DefaultCloneOptions ¶ added in v1.3.11
func DefaultCloneOptions() CloneOptions
DefaultCloneOptions provides sensible defaults for cloning
type CommitOptions ¶ added in v1.3.11
type CommitOptions struct {
// Branch to commit to
Branch string
// Commit message
Message string
// Files to add to the commit (if empty, will add all changes)
Files []string
// Add all changes if true, otherwise only add specified files
AddAll bool
// Author information
Author AuthorInfo
// Authentication for pushing
Auth *ghhttp.BasicAuth
// Remote URL (optional, will use existing remote if not specified)
RemoteURL string
// Remote name (defaults to "origin")
RemoteName string
}
CommitOptions defines the configuration for committing changes
type GithubConfig ¶
type GithubConfig struct {
Pem string `mapstructure:"pem"`
AppId string `mapstructure:"app_id"`
InstallId string `mapstructure:"install_id"`
}
func GithubLoadConfig ¶
func GithubLoadConfig() (*GithubConfig, error)
type GithubSession ¶
type GithubSession struct {
// contains filtered or unexported fields
}
func NewGithubSession ¶
func NewGithubSession(pem, appID, installID string) (*GithubSession, error)
NewGithubSession creates a new Github session using the provided PEM file, App ID, and Install ID
func (*GithubSession) AuthToken ¶
func (s *GithubSession) AuthToken() *oauth2.Token
Get AuthToken returns the authentication token
func (*GithubSession) Client ¶
func (s *GithubSession) Client() *github.Client
Get Client returns the authenticated Github client
func (*GithubSession) CreatePullRequest ¶ added in v1.3.13
func (s *GithubSession) CreatePullRequest( ctx context.Context, owner, repo string, opts *PullRequestOptions, ) (*github.PullRequest, error)
CreatePullRequest creates a new pull request in the specified repository using the provided options
Example ¶
Example test demonstrating usage
// This example shows how to use the new extensible CreatePullRequest function
session := &GithubSession{} // Assume properly initialized
opts := &PullRequestOptions{
Title: "Add new feature",
Head: "feature-branch",
Base: "main",
Body: github.Ptr("This PR adds a new feature with comprehensive tests"),
Draft: github.Ptr(false),
MaintainerCanModify: github.Ptr(true),
Assignees: []string{"developer1"},
Reviewers: []string{"reviewer1", "reviewer2"},
Labels: []string{"enhancement", "needs-review"},
Milestone: github.Ptr(1),
}
ctx := context.Background()
pr, err := session.CreatePullRequest(ctx, "owner", "repo", opts)
if err != nil {
fmt.Printf("Error creating PR: %v\n", err)
return
}
fmt.Printf("Created PR #%d: %s\n", pr.GetNumber(), pr.GetTitle())
func (*GithubSession) CreatePullRequestSimple ¶ added in v1.3.13
func (s *GithubSession) CreatePullRequestSimple( ctx context.Context, owner, repo, title, head, base string, ) (*github.PullRequest, error)
CreatePullRequestSimple creates a pull request with basic options (backward compatibility)
type GithubSessionInterface ¶
GithubSessionInterface defines the interface for Github sessions
type GraphQLClient ¶ added in v1.3.41
type GraphQLClient struct {
// contains filtered or unexported fields
}
GraphQLClient wraps the GitHub GraphQL client with automatic installation discovery. It caches installation IDs and authenticated clients per organization for efficiency. This client is useful when you need to make queries across multiple organizations without knowing the installation IDs upfront.
func NewGraphQLClient ¶ added in v1.3.41
func NewGraphQLClient(cfg GraphQLConfig, log logger.Logger) (*GraphQLClient, error)
NewGraphQLClient creates a new GitHub GraphQL client with App authentication. The private key can be provided as PEM content (starts with "-----BEGIN") or as a file path.
func (*GraphQLClient) ClearCache ¶ added in v1.3.41
func (g *GraphQLClient) ClearCache()
ClearCache clears the installation and client caches. This is useful for testing or when installations change.
func (*GraphQLClient) DiscoverInstallationID ¶ added in v1.3.41
DiscoverInstallationID finds the installation ID for a given organization. Results are cached to avoid repeated API calls.
func (*GraphQLClient) GetAPIBaseURL ¶ added in v1.3.41
func (g *GraphQLClient) GetAPIBaseURL() string
GetAPIBaseURL returns the appropriate REST API base URL.
func (*GraphQLClient) GetCachedInstallationIDs ¶ added in v1.3.41
func (g *GraphQLClient) GetCachedInstallationIDs() map[string]int64
GetCachedInstallationIDs returns a copy of the cached installation IDs. This is useful for debugging or monitoring.
func (*GraphQLClient) GetClientForOrg ¶ added in v1.3.41
GetClientForOrg returns an authenticated GraphQL client for the given organization. Clients are cached per organization.
func (*GraphQLClient) GetCommitAncestry ¶ added in v1.3.41
func (g *GraphQLClient) GetCommitAncestry(ctx context.Context, owner, repo, ref string, depth int) ([]string, error)
GetCommitAncestry retrieves the commit ancestry for a given ref. Returns a slice of commit SHAs in order from newest to oldest. This is useful for finding routing slips or tracking commit history.
func (*GraphQLClient) GetGraphQLURL ¶ added in v1.3.41
func (g *GraphQLClient) GetGraphQLURL() string
GetGraphQLURL returns the appropriate GraphQL API URL.
type GraphQLConfig ¶ added in v1.3.41
type GraphQLConfig struct {
// AppID is the GitHub App ID
AppID int64
// PrivateKey is the PEM-encoded private key or path to key file
PrivateKey string
// EnterpriseURL is the GitHub Enterprise base URL (optional)
// Leave empty for github.com
EnterpriseURL string
}
GraphQLConfig holds GitHub GraphQL API authentication configuration. It supports automatic installation discovery per organization.
type Installation ¶ added in v1.3.41
type Installation struct {
ID int64 `json:"id"`
Account struct {
Login string `json:"login"`
Type string `json:"type"`
} `json:"account"`
}
Installation represents a GitHub App installation.
type PullRequestOptions ¶ added in v1.3.13
type PullRequestOptions struct {
Title string `json:"title"`
Head string `json:"head"`
Base string `json:"base"`
Body *string `json:"body,omitempty"`
Draft *bool `json:"draft,omitempty"`
MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"`
Assignees []string `json:"assignees,omitempty"`
Reviewers []string `json:"reviewers,omitempty"`
TeamReviewers []string `json:"team_reviewers,omitempty"`
Labels []string `json:"labels,omitempty"`
Milestone *int `json:"milestone,omitempty"`
}
PullRequestOptions contains options for creating a pull request
func (*PullRequestOptions) Validate ¶ added in v1.3.13
func (opts *PullRequestOptions) Validate() error
Validate validates the pull request options
Directories
¶
| Path | Synopsis |
|---|---|
|
Package githubtest provides test fixtures and mocks for testing code that uses the github package.
|
Package githubtest provides test fixtures and mocks for testing code that uses the github package. |