Documentation
¶
Overview ¶
Package github provides a client for the GitHub REST API. It supports repository operations, workflow dispatch, and artifact downloads.
Index ¶
- Constants
- func EncryptSecret(publicKey, value string) (string, error)
- type APIError
- type Artifact
- type ArtifactsResponse
- type Client
- func (c *Client) CreateOrUpdateSecret(ctx context.Context, owner, repo, name, encryptedValue, keyID string) error
- func (c *Client) DownloadArtifactWithProgress(ctx context.Context, owner, repo string, artifactID int64, ...) ([]byte, error)
- func (c *Client) FindArtifactByName(ctx context.Context, owner, repo string, runID int64, name string) (*Artifact, error)
- func (c *Client) FindLatestWorkflowRun(ctx context.Context, owner, repo, workflowFile string, after time.Time) (*WorkflowRun, error)
- func (c *Client) GetPublicKey(ctx context.Context, owner, repo string) (*PublicKey, error)
- func (c *Client) GetRepository(ctx context.Context, owner, repo string) (*Repository, error)
- func (c *Client) GetWorkflowRun(ctx context.Context, owner, repo string, runID int64) (*WorkflowRun, error)
- func (c *Client) ListRunArtifacts(ctx context.Context, owner, repo string, runID int64) ([]Artifact, error)
- func (c *Client) ListWorkflowRuns(ctx context.Context, owner, repo, workflowFile string) ([]WorkflowRun, error)
- func (c *Client) PollForArtifact(ctx context.Context, owner, repo string, runID int64, artifactName string, ...) (*Artifact, error)
- func (c *Client) PollForWorkflowStart(ctx context.Context, owner, repo, workflowFile string, triggerTime time.Time, ...) (*WorkflowRun, error)
- func (c *Client) TriggerWorkflow(ctx context.Context, owner, repo, workflowFile string, ...) error
- type CreateSecretRequest
- type ProgressFunc
- type PublicKey
- type Repository
- type WorkflowDispatchRequest
- type WorkflowRun
- type WorkflowRunsResponse
Constants ¶
const ( // BaseURL is the GitHub API base URL BaseURL = "https://api.github.com" // APIVersion is the GitHub API version header value APIVersion = "2022-11-28" )
Variables ¶
This section is empty.
Functions ¶
func EncryptSecret ¶
EncryptSecret encrypts a value using NaCl sealed box for GitHub secrets. The publicKey should be base64-encoded (as returned by GetPublicKey).
Types ¶
type APIError ¶
type APIError struct {
Message string `json:"message"`
DocumentationURL string `json:"documentation_url"`
Status string `json:"status"`
}
APIError represents an error response from the GitHub API
type Artifact ¶
type Artifact struct {
ID int64 `json:"id"`
NodeID string `json:"node_id"`
Name string `json:"name"`
SizeInBytes int64 `json:"size_in_bytes"`
ArchiveDownloadURL string `json:"archive_download_url"`
Expired bool `json:"expired"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
Artifact represents a GitHub Actions artifact
type ArtifactsResponse ¶
type ArtifactsResponse struct {
TotalCount int `json:"total_count"`
Artifacts []Artifact `json:"artifacts"`
}
ArtifactsResponse is the response from listing artifacts
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a GitHub API client
func (*Client) CreateOrUpdateSecret ¶
func (c *Client) CreateOrUpdateSecret(ctx context.Context, owner, repo, name, encryptedValue, keyID string) error
CreateOrUpdateSecret creates or updates a repository secret The value should be encrypted using the repository's public key
func (*Client) DownloadArtifactWithProgress ¶
func (c *Client) DownloadArtifactWithProgress(ctx context.Context, owner, repo string, artifactID int64, progress ProgressFunc) ([]byte, error)
DownloadArtifactWithProgress downloads an artifact with progress reporting
func (*Client) FindArtifactByName ¶
func (c *Client) FindArtifactByName(ctx context.Context, owner, repo string, runID int64, name string) (*Artifact, error)
FindArtifactByName finds an artifact by name in a workflow run
func (*Client) FindLatestWorkflowRun ¶
func (c *Client) FindLatestWorkflowRun(ctx context.Context, owner, repo, workflowFile string, after time.Time) (*WorkflowRun, error)
FindLatestWorkflowRun finds the most recent workflow run created after a given time
func (*Client) GetPublicKey ¶
GetPublicKey retrieves the repository's public key for encrypting secrets
func (*Client) GetRepository ¶
GetRepository retrieves a repository by owner and name
func (*Client) GetWorkflowRun ¶
func (c *Client) GetWorkflowRun(ctx context.Context, owner, repo string, runID int64) (*WorkflowRun, error)
GetWorkflowRun retrieves a specific workflow run
func (*Client) ListRunArtifacts ¶
func (c *Client) ListRunArtifacts(ctx context.Context, owner, repo string, runID int64) ([]Artifact, error)
ListRunArtifacts lists all artifacts for a workflow run
func (*Client) ListWorkflowRuns ¶
func (c *Client) ListWorkflowRuns(ctx context.Context, owner, repo, workflowFile string) ([]WorkflowRun, error)
ListWorkflowRuns lists workflow runs for a workflow file
func (*Client) PollForArtifact ¶
func (c *Client) PollForArtifact(ctx context.Context, owner, repo string, runID int64, artifactName string, timeout time.Duration) (*Artifact, error)
PollForArtifact polls until an artifact with the given name appears in a workflow run. This allows downloading the artifact as soon as it's uploaded, without waiting for the entire workflow to complete.
type CreateSecretRequest ¶
type CreateSecretRequest struct {
EncryptedValue string `json:"encrypted_value"`
KeyID string `json:"key_id"`
}
CreateSecretRequest is the request body for creating/updating a secret
type ProgressFunc ¶
type ProgressFunc func(downloaded, total int64)
ProgressFunc is called during download with bytes downloaded and total size
type Repository ¶
type Repository struct {
ID int64 `json:"id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
Private bool `json:"private"`
HTMLURL string `json:"html_url"`
CloneURL string `json:"clone_url"`
SSHURL string `json:"ssh_url"`
DefaultRef string `json:"default_branch"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Repository represents a GitHub repository
type WorkflowDispatchRequest ¶
type WorkflowDispatchRequest struct {
Ref string `json:"ref"`
Inputs map[string]string `json:"inputs,omitempty"`
}
WorkflowDispatchRequest is the request body for triggering a workflow
type WorkflowRun ¶
type WorkflowRun struct {
ID int64 `json:"id"`
Name string `json:"name"`
HeadBranch string `json:"head_branch"`
HeadSHA string `json:"head_sha"`
Status string `json:"status"` // queued, in_progress, completed
Conclusion string `json:"conclusion"` // success, failure, cancelled, skipped
HTMLURL string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
WorkflowRun represents a GitHub Actions workflow run
type WorkflowRunsResponse ¶
type WorkflowRunsResponse struct {
TotalCount int `json:"total_count"`
WorkflowRuns []WorkflowRun `json:"workflow_runs"`
}
WorkflowRunsResponse is the response from listing workflow runs