github

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MatrixSuffix = matrixSuffix()
)

Functions

This section is empty.

Types

type Api

type Api struct {
	// Token the Authorization: Bearer token to use, defaults to environment variable: GITHUB_TOKEN or `gh auth token`
	Token string

	// BaseURL base URL to the GitHub API defaults to https://api.github.com
	BaseURL string

	// Repo is the full GitHub repository, e.g. anchore/syft
	Repo string

	// Actor is the actor executing the workflow in GitHub, the login, e.g. kzantow
	Actor string
}

func NewClient

func NewClient(params ...Param) Api

NewClient creates a new GitHub API client, looking up information automatically from the environment when run in a GitHub Actions runner

func (Api) DeleteArtifact

func (a Api) DeleteArtifact(artifactID int64) error

func (Api) DownloadArtifactDir

func (a Api) DownloadArtifactDir(runID int64, artifactNameGlob, targetDir string) error

DownloadArtifactDir downloads an artifact and extracts it to the targetDir

func (Api) DownloadBranchArtifactDir

func (a Api) DownloadBranchArtifactDir(branch, workflowName, artifactName, targetDir string) error

DownloadBranchArtifactDir downloads an artifact from the latest run on a branch and extracts it to the targetDir

func (Api) LatestWorkflowRun

func (a Api) LatestWorkflowRun(branch, workflowNameGlob string) (WorkflowRun, error)

LatestWorkflowRun returns the latest completed workflow run for a branch

func (Api) ListArtifactsForBranch

func (a Api) ListArtifactsForBranch(branch, workflowNameGlob, artifactNameGlob string) ([]Artifact, error)

ListArtifactsForBranch returns artifacts for the latest run on the given workflow

func (Api) ListArtifactsForWorkflowRun

func (a Api) ListArtifactsForWorkflowRun(runID int64, artifactNameGlob string) ([]Artifact, error)

func (Api) UploadArtifactDir

func (a Api) UploadArtifactDir(baseDir string, opts UploadArtifactOption) (int64, error)

UploadArtifactDir will compress all files in the basedir into an artifact attached to the currently running workflow. Optionally limit the files by including ArtifactFiles or ArtifactGlob, which can be relative to the baseDir. To specify a custom name, use ArtifactName

type Artifact

type Artifact struct {
	ID                 int64               `json:"id,omitempty"`
	NodeID             string              `json:"node_id,omitempty"`
	Name               string              `json:"name,omitempty"`
	SizeInBytes        int64               `json:"size_in_bytes,omitempty"`
	URL                string              `json:"url,omitempty"`
	ArchiveDownloadURL string              `json:"archive_download_url,omitempty"`
	Expired            bool                `json:"expired,omitempty"`
	CreatedAt          Timestamp           `json:"created_at,omitempty"`
	UpdatedAt          Timestamp           `json:"updated_at,omitempty"`
	ExpiresAt          Timestamp           `json:"expires_at,omitempty"`
	Digest             string              `json:"digest,omitempty"`
	WorkflowRun        ArtifactWorkflowRun `json:"workflow_run,omitempty"`
}

type ArtifactList

type ArtifactList struct {
	TotalCount int64      `json:"total_count,omitempty"`
	Artifacts  []Artifact `json:"artifacts,omitempty"`
}

type ArtifactWorkflowRun

type ArtifactWorkflowRun struct {
	ID         int64  `json:"id,omitempty"`
	HeadBranch string `json:"head_branch,omitempty"`
	HeadSHA    string `json:"head_sha,omitempty"`
}

type Event

type Event struct {
	ApiURL      string      `env:"GITHUB_API_URL"`
	Token       string      `env:"GITHUB_TOKEN"`
	Type        string      `env:"GITHUB_EVENT_NAME"`
	Ref         string      `env:"GITHUB_REF"`
	Actor       string      `env:"GITHUB_ACTOR"`
	Owner       string      `env:"GITHUB_REPOSITORY_OWNER"`
	Repo        string      `env:"GITHUB_REPOSITORY"` // Repo is the full name of the repository, including the owner
	SHA         string      `env:"GITHUB_SHA"`
	Workflow    string      `env:"GITHUB_WORKFLOW"`
	RunID       int64       `env:"GITHUB_RUN_ID"`
	RunNumber   string      `env:"GITHUB_RUN_NUMBER"`
	Job         string      `env:"GITHUB_JOB"`
	Step        string      `env:"GITHUB_STEP"`
	Action      string      `env:"GITHUB_ACTION"`
	PullRequest PullRequest `json:"pull_request"`
}

func Payload

func Payload() Event

Payload returns the current event payload

func (Event) IsPullRequest

func (e Event) IsPullRequest() bool

type HeadCommit

type HeadCommit struct {
	ID string `json:"id,omitempty"`
}

type Option

type Option func(Api)

type Param

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

func Branch

func Branch(v string) Param

func Name

func Name(v string) Param

func PerPage

func PerPage(v uint) Param

func Repo

func Repo(v string) Param

Repo is the full repository, e.g. owner/repo

func Status

func Status(v string) Param

Status in: completed, action_required, cancelled, failure, neutral, skipped, stale, success, timed_out, in_progress, queued, requested, waiting, pending

type PullRequest

type PullRequest struct {
	URL    string `json:"url,omitempty"`
	Number int    `json:"number,omitempty"`
	Head   Ref    `json:"head,omitempty"`
}

type Ref

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

type Repository

type Repository struct {
	ID          int64  `json:"id"`
	NodeID      string `json:"node_id"`
	Name        string `json:"name"`
	FullName    string `json:"full_name"`
	Private     bool   `json:"private"`
	Owner       User   `json:"owner"`
	HTMLURL     string `json:"html_url"`
	Description string `json:"description"`
	Fork        bool   `json:"fork"`
	URL         string `json:"url"`
}

type Timestamp

type Timestamp time.Time

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

type UploadArtifactOption

type UploadArtifactOption struct {
	ArtifactName  string
	Overwrite     bool
	RetentionDays uint
	Glob          string
	Files         []string
}

type User

type User struct {
	Type    string `json:"type,omitempty"`
	Login   string `json:"login,omitempty"`
	ID      int64  `json:"id,omitempty"`
	URL     string `json:"url,omitempty"`
	HtmlURL string `json:"html_url,omitempty"`
}

type WorkflowRun

type WorkflowRun struct {
	ID                 int64         `json:"id,omitempty"`
	Name               string        `json:"name,omitempty"`
	NodeID             string        `json:"node_id,omitempty"`
	HeadBranch         string        `json:"head_branch,omitempty"`
	HeadSHA            string        `json:"head_sha,omitempty"`
	Path               string        `json:"path,omitempty"`
	RunNumber          int           `json:"run_number,omitempty"`
	RunAttempt         int           `json:"run_attempt,omitempty"`
	Event              string        `json:"event,omitempty"`
	DisplayTitle       string        `json:"display_title,omitempty"`
	Status             string        `json:"status,omitempty"`
	Conclusion         string        `json:"conclusion,omitempty"` // success or failure
	WorkflowID         int64         `json:"workflow_id,omitempty"`
	CheckSuiteID       int64         `json:"check_suite_id,omitempty"`
	CheckSuiteNodeID   string        `json:"check_suite_node_id,omitempty"`
	URL                string        `json:"url,omitempty"`
	HTMLURL            string        `json:"html_url,omitempty"`
	PullRequests       []PullRequest `json:"pull_requests,omitempty"`
	CreatedAt          Timestamp     `json:"created_at,omitempty"`
	UpdatedAt          Timestamp     `json:"updated_at,omitempty"`
	RunStartedAt       Timestamp     `json:"run_started_at,omitempty"`
	PreviousAttemptURL string        `json:"previous_attempt_url,omitempty"`
	HeadCommit         HeadCommit    `json:"head_commit,omitempty"`
	Repository         Repository    `json:"repository,omitempty"`
	HeadRepository     Repository    `json:"head_repository,omitempty"`
	Actor              User          `json:"actor,omitempty"`
	TriggeringActor    User          `json:"triggering_actor,omitempty"`
}

type WorkflowRunList

type WorkflowRunList struct {
	TotalCount   int64         `json:"total_count,omitempty"`
	WorkflowRuns []WorkflowRun `json:"workflow_runs,omitempty"`
}

Jump to

Keyboard shortcuts

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