Documentation
¶
Overview ¶
Package github provides a wrapper around the GitHub API for IssueOps operations.
Index ¶
- func DeploymentStateEmoji(state DeploymentState) string
- func GetCommitMessages(commits []Commit) []string
- func GetRateLimitReset(err error) time.Time
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsRateLimitError(err error) bool
- func WrapWithRetry[T any](ctx context.Context, config RetryConfig, operation func() (T, error)) (T, error)
- type Branch
- type Client
- func (c *Client) AddLabelToPR(ctx context.Context, prNumber int, labels []string) error
- func (c *Client) AddLabels(ctx context.Context, number int, labels []string) error
- func (c *Client) AddReaction(ctx context.Context, commentID int64, reaction string) error
- func (c *Client) AddSubIssue(ctx context.Context, parentIssueNumber int, subIssueID int64) error
- func (c *Client) CloseIssue(ctx context.Context, number int) error
- func (c *Client) CloseMilestone(ctx context.Context, number int) error
- func (c *Client) CompareCommits(ctx context.Context, base, head string) ([]Commit, error)
- func (c *Client) CreateApprovalSubIssue(ctx context.Context, parentIssueNumber int, title, body string, ...) (*Issue, error)
- func (c *Client) CreateBranch(ctx context.Context, branchName, sourceRef string) (*Branch, error)
- func (c *Client) CreateComment(ctx context.Context, number int, body string) error
- func (c *Client) CreateDeployment(ctx context.Context, opts CreateDeploymentOptions) (*Deployment, error)
- func (c *Client) CreateDeploymentStatus(ctx context.Context, opts CreateDeploymentStatusOptions) (*DeploymentStatus, error)
- func (c *Client) CreateIssue(ctx context.Context, opts CreateIssueOptions) (*Issue, error)
- func (c *Client) CreateLabel(ctx context.Context, name, color, description string) error
- func (c *Client) CreateMilestone(ctx context.Context, title, description string) (*Milestone, error)
- func (c *Client) CreateTag(ctx context.Context, opts CreateTagOptions) (*Tag, error)
- func (c *Client) DeleteBranch(ctx context.Context, branchName string) error
- func (c *Client) DeleteTag(ctx context.Context, name string) error
- func (c *Client) ExpandTeamToUsers(ctx context.Context, approvers []string) ([]string, error)
- func (c *Client) GetBranch(ctx context.Context, branchName string) (*Branch, error)
- func (c *Client) GetCommitsBetweenBranches(ctx context.Context, baseBranch, headBranch string) ([]Commit, error)
- func (c *Client) GetCommitsBetweenTags(ctx context.Context, oldTag, newTag string) ([]Commit, error)
- func (c *Client) GetCommitsSinceTag(ctx context.Context, tag, branch string) ([]Commit, error)
- func (c *Client) GetDeployment(ctx context.Context, deploymentID int64) (*Deployment, error)
- func (c *Client) GetEnvironmentDeploymentStatus(ctx context.Context, environment string) (*Deployment, *DeploymentStatus, error)
- func (c *Client) GetFileContents(ctx context.Context, owner, repo, path string) ([]byte, error)
- func (c *Client) GetFileContentsFromRepo(ctx context.Context, repoFullName, path string) ([]byte, error)
- func (c *Client) GetIssue(ctx context.Context, number int) (*Issue, error)
- func (c *Client) GetIssueByNumber(ctx context.Context, number int) (*github.Issue, *github.Response, error)
- func (c *Client) GetLatestDeploymentStatus(ctx context.Context, deploymentID int64) (*DeploymentStatus, error)
- func (c *Client) GetLatestTag(ctx context.Context) (string, error)
- func (c *Client) GetLatestTagWithPrefix(ctx context.Context, prefix string) (string, error)
- func (c *Client) GetMergedPRsBetween(ctx context.Context, base, head string) ([]PullRequest, error)
- func (c *Client) GetMilestoneByTitle(ctx context.Context, title string) (*Milestone, error)
- func (c *Client) GetPRsByLabel(ctx context.Context, label string) ([]PullRequest, error)
- func (c *Client) GetPRsByMilestone(ctx context.Context, milestoneNumber int) ([]PullRequest, error)
- func (c *Client) GetPRsMergedToBranch(ctx context.Context, branchName string) ([]PullRequest, error)
- func (c *Client) GetParentIssue(ctx context.Context, subIssueNumber int) (*github.Issue, error)
- func (c *Client) GetPreviousTag(ctx context.Context, currentTag string) (string, error)
- func (c *Client) GetTeamMembers(ctx context.Context, team string) ([]TeamMember, error)
- func (c *Client) GitHubClient() *github.Client
- func (c *Client) IsSubIssue(ctx context.Context, issueNumber int) (bool, error)
- func (c *Client) IsUserInTeam(ctx context.Context, team, user string) (bool, error)
- func (c *Client) ListComments(ctx context.Context, number int) ([]IssueComment, error)
- func (c *Client) ListDeployments(ctx context.Context, environment string, ref string) ([]Deployment, error)
- func (c *Client) ListSubIssues(ctx context.Context, parentIssueNumber int) ([]*github.Issue, error)
- func (c *Client) ListTags(ctx context.Context, limit int) ([]string, error)
- func (c *Client) Owner() string
- func (c *Client) RemoveLabelFromPR(ctx context.Context, prNumber int, label string) error
- func (c *Client) RemoveSubIssue(ctx context.Context, parentIssueNumber int, subIssueID int64) error
- func (c *Client) ReopenIssue(ctx context.Context, number int) error
- func (c *Client) Repo() string
- func (c *Client) TagExists(ctx context.Context, name string) (bool, error)
- func (c *Client) UpdateIssueBody(ctx context.Context, number int, body string) error
- func (c *Client) UpdateIssueTitle(ctx context.Context, number int, title string) error
- type Commit
- type CreateDeploymentOptions
- type CreateDeploymentStatusOptions
- type CreateIssueOptions
- type CreateTagOptions
- type Deployment
- type DeploymentState
- type DeploymentStatus
- type Issue
- type IssueComment
- type Milestone
- type PRWithLabels
- type PullRequest
- type RetryConfig
- type SubIssueRequest
- type SubIssueResponse
- type SubIssueState
- type Tag
- type TeamMember
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeploymentStateEmoji ¶
func DeploymentStateEmoji(state DeploymentState) string
DeploymentStateEmoji returns an emoji for a deployment state.
func GetCommitMessages ¶
GetCommitMessages extracts just the commit messages from a list of commits.
func GetRateLimitReset ¶
GetRateLimitReset returns the time when the rate limit resets.
func IsForbidden ¶
IsForbidden returns true if the error is a 403 Forbidden error.
func IsNotFound ¶
IsNotFound returns true if the error is a 404 Not Found error.
func IsRateLimitError ¶
IsRateLimitError checks if an error is a GitHub rate limit error.
func WrapWithRetry ¶
func WrapWithRetry[T any](ctx context.Context, config RetryConfig, operation func() (T, error)) (T, error)
WrapWithRetry wraps an operation with retry logic for rate limits. This is useful for operations that don't go through the HTTP transport.
Types ¶
type Branch ¶
type Branch struct {
Name string `json:"name"`
SHA string `json:"sha"`
Protected bool `json:"protected"`
}
Branch represents a Git branch.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the GitHub API client with IssueOps-specific operations.
func NewClientWithToken ¶
NewClientWithToken creates a new GitHub client with explicit parameters.
func NewClientWithTokenAndRetry ¶
func NewClientWithTokenAndRetry(ctx context.Context, token, owner, repo string, retryConfig RetryConfig) (*Client, error)
NewClientWithTokenAndRetry creates a new GitHub client with explicit parameters and retry config.
func (*Client) AddLabelToPR ¶
AddLabelToPR adds a label to a PR.
func (*Client) AddReaction ¶
AddReaction adds a reaction to an issue comment.
func (*Client) AddSubIssue ¶
AddSubIssue links an existing issue as a sub-issue of a parent issue. This uses the GitHub Sub-Issues API: POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues Available since December 2024.
func (*Client) CloseIssue ¶
CloseIssue closes an issue.
func (*Client) CloseMilestone ¶
CloseMilestone closes a milestone.
func (*Client) CompareCommits ¶
CompareCommits compares two refs and returns the commits between them. base is the older ref, head is the newer ref.
func (*Client) CreateApprovalSubIssue ¶
func (c *Client) CreateApprovalSubIssue(ctx context.Context, parentIssueNumber int, title, body string, labels, assignees []string) (*Issue, error)
CreateApprovalSubIssue creates a new issue and links it as a sub-issue of a parent. This is a convenience method that combines CreateIssue + AddSubIssue.
func (*Client) CreateBranch ¶
CreateBranch creates a new branch from a source ref.
func (*Client) CreateComment ¶
CreateComment adds a comment to an issue.
func (*Client) CreateDeployment ¶
func (c *Client) CreateDeployment(ctx context.Context, opts CreateDeploymentOptions) (*Deployment, error)
CreateDeployment creates a new deployment.
func (*Client) CreateDeploymentStatus ¶
func (c *Client) CreateDeploymentStatus(ctx context.Context, opts CreateDeploymentStatusOptions) (*DeploymentStatus, error)
CreateDeploymentStatus creates a status for a deployment.
func (*Client) CreateIssue ¶
CreateIssue creates a new issue in the repository.
func (*Client) CreateLabel ¶
CreateLabel creates a label if it doesn't exist.
func (*Client) CreateMilestone ¶
func (c *Client) CreateMilestone(ctx context.Context, title, description string) (*Milestone, error)
CreateMilestone creates a new milestone.
func (*Client) DeleteBranch ¶
DeleteBranch deletes a branch.
func (*Client) ExpandTeamToUsers ¶
ExpandTeamToUsers converts team references to individual user logins. For non-team references (plain usernames), returns them as-is.
func (*Client) GetCommitsBetweenBranches ¶
func (c *Client) GetCommitsBetweenBranches(ctx context.Context, baseBranch, headBranch string) ([]Commit, error)
GetCommitsBetweenBranches returns commits in head branch that are not in base branch.
func (*Client) GetCommitsBetweenTags ¶
func (c *Client) GetCommitsBetweenTags(ctx context.Context, oldTag, newTag string) ([]Commit, error)
GetCommitsBetweenTags gets all commits between two tags.
func (*Client) GetCommitsSinceTag ¶
GetCommitsSinceTag gets all commits since a tag on a branch.
func (*Client) GetDeployment ¶
GetDeployment retrieves a deployment by ID.
func (*Client) GetEnvironmentDeploymentStatus ¶
func (c *Client) GetEnvironmentDeploymentStatus(ctx context.Context, environment string) (*Deployment, *DeploymentStatus, error)
GetEnvironmentDeploymentStatus returns the status of the latest deployment to an environment.
func (*Client) GetFileContents ¶
GetFileContents fetches the contents of a file from a repository.
func (*Client) GetFileContentsFromRepo ¶
func (c *Client) GetFileContentsFromRepo(ctx context.Context, repoFullName, path string) ([]byte, error)
GetFileContentsFromRepo fetches file contents from any repo (for external config). The repo parameter should be in "owner/repo" format.
func (*Client) GetIssueByNumber ¶
func (c *Client) GetIssueByNumber(ctx context.Context, number int) (*github.Issue, *github.Response, error)
GetIssueByNumber retrieves the full GitHub issue object by number. Returns the underlying github.Issue which includes the ID field.
func (*Client) GetLatestDeploymentStatus ¶
func (c *Client) GetLatestDeploymentStatus(ctx context.Context, deploymentID int64) (*DeploymentStatus, error)
GetLatestDeploymentStatus gets the latest status for a deployment.
func (*Client) GetLatestTag ¶
GetLatestTag returns the latest semver tag.
func (*Client) GetLatestTagWithPrefix ¶
GetLatestTagWithPrefix returns the latest tag matching a specific prefix. This is useful for environment-specific tags like "dev-v1.0.0", "staging-v1.0.0".
func (*Client) GetMergedPRsBetween ¶
GetMergedPRsBetween returns PRs merged between two refs. Note: Requires pull-requests: read permission in the workflow.
func (*Client) GetMilestoneByTitle ¶
GetMilestoneByTitle finds a milestone by its title.
func (*Client) GetPRsByLabel ¶
GetPRsByLabel returns all merged PRs with a specific label.
func (*Client) GetPRsByMilestone ¶
GetPRsByMilestone returns all PRs assigned to a milestone.
func (*Client) GetPRsMergedToBranch ¶
func (c *Client) GetPRsMergedToBranch(ctx context.Context, branchName string) ([]PullRequest, error)
GetPRsMergedToBranch returns PRs merged to a specific branch.
func (*Client) GetParentIssue ¶
GetParentIssue retrieves the parent issue for a given sub-issue. GET /repos/{owner}/{repo}/issues/{issue_number}/parent
func (*Client) GetPreviousTag ¶
GetPreviousTag returns the tag before the given tag.
func (*Client) GetTeamMembers ¶
GetTeamMembers retrieves all members of a team. The team can be specified as "team-slug" or "org/team-slug".
func (*Client) GitHubClient ¶
GitHubClient returns the underlying go-github client for advanced operations.
func (*Client) IsSubIssue ¶
IsSubIssue checks if an issue is a sub-issue (has a parent).
func (*Client) IsUserInTeam ¶
IsUserInTeam checks if a user is a member of a team.
func (*Client) ListComments ¶
ListComments retrieves all comments on an issue.
func (*Client) ListDeployments ¶
func (c *Client) ListDeployments(ctx context.Context, environment string, ref string) ([]Deployment, error)
ListDeployments lists deployments for the repository.
func (*Client) ListSubIssues ¶
ListSubIssues retrieves all sub-issues for a given parent issue. GET /repos/{owner}/{repo}/issues/{issue_number}/sub_issues
func (*Client) ListTags ¶
ListTags lists tags in the repository, ordered by creation date (newest first).
func (*Client) RemoveLabelFromPR ¶
RemoveLabelFromPR removes a label from a PR.
func (*Client) RemoveSubIssue ¶
RemoveSubIssue removes a sub-issue from its parent. DELETE /repos/{owner}/{repo}/issues/{issue_number}/sub_issue
func (*Client) ReopenIssue ¶
ReopenIssue reopens a closed issue.
func (*Client) UpdateIssueBody ¶
UpdateIssueBody updates the body of an issue.
type Commit ¶
type Commit struct {
SHA string `json:"sha"`
Message string `json:"message"`
Author string `json:"author"`
Date string `json:"date"`
URL string `json:"url"`
}
Commit represents a Git commit.
type CreateDeploymentOptions ¶
type CreateDeploymentOptions struct {
Ref string // Git ref (branch, tag, SHA)
Environment string // Target environment (e.g., "production", "staging")
Description string // Description of the deployment
AutoMerge bool // Auto-merge the default branch into the ref
RequiredContexts []string // Required status contexts (empty = no required contexts)
Payload string // JSON payload with extra information
TransientEnv bool // Mark environment as transient (will be destroyed)
ProductionEnv bool // Mark as production environment
}
CreateDeploymentOptions contains options for creating a deployment.
type CreateDeploymentStatusOptions ¶
type CreateDeploymentStatusOptions struct {
DeploymentID int64
State DeploymentState
Description string
LogURL string // URL to deployment logs or approval issue
Environment string
EnvironmentURL string // URL to the deployed environment
AutoInactive bool // Mark previous deployments as inactive
}
CreateDeploymentStatusOptions contains options for creating a deployment status.
type CreateIssueOptions ¶
CreateIssueOptions contains options for creating an issue.
type CreateTagOptions ¶
type CreateTagOptions struct {
Name string // Tag name (e.g., "v1.2.3")
SHA string // Commit SHA to tag (empty = use default branch HEAD)
Message string // Tag message
}
CreateTagOptions contains options for creating a tag.
type Deployment ¶
type Deployment struct {
ID int64 `json:"id"`
SHA string `json:"sha"`
Ref string `json:"ref"`
Environment string `json:"environment"`
Description string `json:"description"`
Creator string `json:"creator"`
URL string `json:"url"`
}
Deployment represents a GitHub deployment.
type DeploymentState ¶
type DeploymentState string
DeploymentState represents the state of a deployment.
const ( DeploymentStatePending DeploymentState = "pending" DeploymentStateQueued DeploymentState = "queued" DeploymentStateInProgress DeploymentState = "in_progress" DeploymentStateSuccess DeploymentState = "success" DeploymentStateFailure DeploymentState = "failure" DeploymentStateError DeploymentState = "error" DeploymentStateInactive DeploymentState = "inactive" )
type DeploymentStatus ¶
type DeploymentStatus struct {
ID int64 `json:"id"`
State DeploymentState `json:"state"`
Description string `json:"description"`
LogURL string `json:"log_url"`
Environment string `json:"environment"`
}
DeploymentStatus represents the status of a deployment.
type Issue ¶
type Issue struct {
Number int
Title string
Body string
State string
HTMLURL string
Labels []string
}
Issue represents a GitHub issue.
type IssueComment ¶
IssueComment represents a comment on a GitHub issue.
type Milestone ¶
type Milestone struct {
Number int `json:"number"`
Title string `json:"title"`
Description string `json:"description"`
State string `json:"state"` // "open" or "closed"
OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"`
URL string `json:"url"`
}
Milestone represents a GitHub milestone.
type PRWithLabels ¶
type PRWithLabels struct {
PullRequest
Labels []string `json:"labels"`
}
PRWithLabels represents a PR with its labels for filtering.
type PullRequest ¶
type PullRequest struct {
Number int `json:"number"`
Title string `json:"title"`
Author string `json:"author"`
URL string `json:"url"`
MergedAt string `json:"merged_at,omitempty"`
MergeSHA string `json:"merge_sha,omitempty"`
}
PullRequest represents a GitHub pull request.
type RetryConfig ¶
type RetryConfig struct {
// MaxRetries is the maximum number of retry attempts.
MaxRetries int
// InitialBackoff is the initial backoff duration.
InitialBackoff time.Duration
// MaxBackoff is the maximum backoff duration.
MaxBackoff time.Duration
// BackoffMultiplier is multiplied to backoff after each retry.
BackoffMultiplier float64
}
RetryConfig configures retry behavior for API calls.
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns sensible defaults for retry configuration.
type SubIssueRequest ¶
type SubIssueRequest struct {
SubIssueID int64 `json:"sub_issue_id"`
}
SubIssueRequest represents a request to add a sub-issue to a parent issue.
type SubIssueResponse ¶
type SubIssueResponse struct {
ID int64 `json:"id"`
Number int `json:"number"`
Title string `json:"title"`
State string `json:"state"`
HTMLURL string `json:"html_url"`
Assignees []*github.User `json:"assignees,omitempty"`
}
SubIssueResponse represents the response from sub-issue operations.
type SubIssueState ¶
type SubIssueState struct {
IssueNumber int `json:"issue_number"`
Stage string `json:"stage"`
Status string `json:"status"` // "pending", "approved", "denied"
ClosedBy string `json:"closed_by,omitempty"`
ClosedAt string `json:"closed_at,omitempty"`
}
SubIssueState represents the state of a sub-issue for approval tracking.
type TeamMember ¶
type TeamMember struct {
Login string
}
TeamMember represents a member of a GitHub team.