github

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package github provides a client for the GitHub REST API. It supports repository operations, workflow dispatch, and artifact downloads.

Index

Constants

View Source
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

func EncryptSecret(publicKey, value string) (string, error)

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

func (*APIError) Error

func (e *APIError) Error() string

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 NewClient

func NewClient(token string) *Client

NewClient creates a new 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

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

GetPublicKey retrieves the repository's public key for encrypting secrets

func (*Client) GetRepository

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

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.

func (*Client) PollForWorkflowStart

func (c *Client) PollForWorkflowStart(ctx context.Context, owner, repo, workflowFile string, triggerTime time.Time, timeout time.Duration) (*WorkflowRun, error)

PollForWorkflowStart polls until a new workflow run appears after triggerTime

func (*Client) TriggerWorkflow

func (c *Client) TriggerWorkflow(ctx context.Context, owner, repo, workflowFile string, inputs map[string]string) error

TriggerWorkflow triggers a workflow_dispatch event

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 PublicKey

type PublicKey struct {
	KeyID string `json:"key_id"`
	Key   string `json:"key"`
}

PublicKey represents a repository's public key for encrypting secrets

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

Jump to

Keyboard shortcuts

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