{"modulePath":"github.com/vulnesis/cli","version":"v0.0.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package github\n\n## Constants\n\n```go\nconst (\n\tCampaignNameMax        = 50\n\tCampaignDescriptionMax = 255\n\t// CampaignAlertsMax is the most alerts one campaign can hold.\n\tCampaignAlertsMax = 1000\n)\n```\nLimits GitHub puts on a campaign.\n\n```go\nconst (\n\tCampaignOpen   = \"open\"\n\tCampaignClosed = \"closed\"\n)\n```\nCampaign states.\n\n```go\nconst DefaultAPIURL = \"https://api.github.com\"\n```\nDefaultAPIURL is github.com's REST endpoint.\n\n```go\nconst MaxSARIFUploadBytes = 10 \u003c\u003c 20\n```\nMaxSARIFUploadBytes is code scanning's limit on the gzipped document.\n\n## Variables\n\n```go\nvar ErrNoToken = errors.New(\"no GitHub token found: set GITHUB_TOKEN or run 'gh auth login'\")\n```\nErrNoToken is returned when no GitHub token can be found.\n\n```go\nvar ErrRateLimited = errors.New(\"GitHub API rate limit exhausted\")\n```\nErrRateLimited is returned when the rate limit outlasts MaxWait.\n\n## Functions\n\n```go\nfunc APIURL() string\n```\nAPIURL is GITHUB\\_API\\_URL, or github.com's.\n\n```go\nfunc AdvisoryMarker(hash string) string\n```\nAdvisoryMarker is the line that ties an advisory to the finding group it was made from.\n\n```go\nfunc CampaignEnd(t time.Time) string\n```\nCampaignEnd formats a campaign end time the way the API takes it.\n\n```go\nfunc CampaignMarker(uuid string) string\n```\nCampaignMarker is the line that ties a GitHub campaign to the Vulnetix campaign it was made from.\n\n```go\nfunc CampaignMarkerOf(description string) string\n```\nCampaignMarkerOf returns the Vulnetix campaign uuid in a description, or \"\".\n\n```go\nfunc CampaignName(name string) string\n```\nCampaignName is the GitHub name for a Vulnetix campaign, within the limit.\n\n```go\nfunc DefaultCorrelator() string\n```\nDefaultCorrelator is vulnetix/\\\u003cworkflow\u003e/\\\u003cjob\u003e from the Actions environment.\n\n```go\nfunc DownloadAsset(ctx context.Context, token string, a ReleaseAsset, destDir string) (string, error)\n```\nDownloadAsset writes an asset into destDir and returns its path.\n\n```go\nfunc EncodeSARIF(sarifJSON []byte) (string, error)\n```\nEncodeSARIF gzips and base64-encodes a SARIF document as the API wants.\n\n```go\nfunc GitHubPurl(purl string) string\n```\nGitHubPurl rewrites a package URL into the form the dependency graph accepts. GitHub Actions are pkg:githubactions/\\\u003cowner\u003e/\\\u003crepo\u003e@\\\u003cref\u003e there; this CLI's SBOMs carry pkg:github-actions/\\\u003cowner\u003e%2F\\\u003crepo\u003e@\\\u003cref\u003e, which the API rejects as an invalid type (HTTP 422) and which then fails the whole snapshot. Every other purl is returned unchanged.\n\n```go\nfunc IsPermission(err error) bool\n```\nIsPermission reports a refusal that more permissions would fix: 401, 403 (not a rate limit) or 404, which GitHub answers for a resource the token cannot see. Publishing treats these as warnings.\n\n```go\nfunc IsStatus(err error, statuses ...int) bool\n```\nIsStatus reports whether err is an APIError with one of the statuses.\n\n```go\nfunc MarkerOf(description string) string\n```\nMarkerOf returns the marker hash in an advisory's description, or \"\".\n\n```go\nfunc RejectedPurl(err error) string\n```\nRejectedPurl returns the package URL a 422 from the snapshot API names as invalid, or \"\".\n\n```go\nfunc RepoFromRemote(remote string) string\n```\nRepoFromRemote reads owner/name from a git remote URL (https or ssh), or returns \"\".\n\n```go\nfunc ResolveToken() (token, source string, err error)\n```\nResolveToken finds a GitHub token: GITHUB\\_TOKEN, then GH\\_TOKEN (the gh CLI's convention), then \\`gh auth token\\`. source names where it came from (\"env:GITHUB\\_TOKEN\", \"env:GH\\_TOKEN\", \"gh-cli\") for status output; the token itself is never printed.\n\n## Types\n\n```go\ntype APIError struct {\n\tMethod, Path string\n\tStatus       int\n\tMessage      string\n}\n```\nAPIError is a non-2xx answer.\n\n```go\nfunc (e *APIError) Error() string\n```\n\n```go\ntype AdvisoryPackage struct {\n\tEcosystem string `json:\"ecosystem\"`\n\tName      string `json:\"name,omitempty\"`\n}\n```\nAdvisoryPackage names the affected package.\n\n```go\ntype AdvisoryRequest struct {\n\tSummary         string                  `json:\"summary\"`\n\tDescription     string                  `json:\"description\"`\n\tVulnerabilities []AdvisoryVulnerability `json:\"vulnerabilities,omitempty\"`\n\tCWEIDs          []string                `json:\"cwe_ids,omitempty\"`\n\tSeverity        string                  `json:\"severity,omitempty\"`\n}\n```\nAdvisoryRequest is the create and update body. Severity and a CVSS vector are mutually exclusive in the API; only Severity is ever sent.\n\n```go\ntype AdvisoryVulnerability struct {\n\tPackage AdvisoryPackage `json:\"package\"`\n}\n```\nAdvisoryVulnerability is one affected package.\n\n```go\ntype Alert struct {\n\tNumber int    `json:\"number\"`\n\tState  string `json:\"state\"`\n\tRule   struct {\n\t\tID   string   `json:\"id\"`\n\t\tTags []string `json:\"tags\"`\n\t} `json:\"rule\"`\n\tMostRecentInstance struct {\n\t\tCategory string `json:\"category\"`\n\t\tMessage  struct {\n\t\t\tText string `json:\"text\"`\n\t\t} `json:\"message\"`\n\t\tLocation struct {\n\t\t\tPath string `json:\"path\"`\n\t\t} `json:\"location\"`\n\t} `json:\"most_recent_instance\"`\n}\n```\nAlert is a code scanning alert, reduced to what mapping needs.\n\n```go\ntype Artifact struct {\n\tID                 int64     `json:\"id\"`\n\tNodeID             string    `json:\"node_id\"`\n\tName               string    `json:\"name\"`\n\tSizeInBytes        int64     `json:\"size_in_bytes\"`\n\tURL                string    `json:\"url\"`\n\tArchiveDownloadURL string    `json:\"archive_download_url\"`\n\tExpired            bool      `json:\"expired\"`\n\tCreatedAt          time.Time `json:\"created_at\"`\n\tUpdatedAt          time.Time `json:\"updated_at\"`\n\tExpiresAt          time.Time `json:\"expires_at\"`\n}\n```\nArtifact represents a GitHub Actions artifact\n\n```go\ntype ArtifactCollector struct {\n\t// contains filtered or unexported fields\n}\n```\nArtifactCollector handles collection of GitHub Actions artifacts\n\n```go\nfunc NewArtifactCollector(token, apiURL, repository, runID string) *ArtifactCollector\n```\nNewArtifactCollector creates a new artifact collector\n\n```go\nfunc (c *ArtifactCollector) DownloadArtifact(ctx context.Context, artifact Artifact) (string, error)\n```\nDownloadArtifact downloads an artifact and extracts it to a temporary directory\n\n```go\nfunc (c *ArtifactCollector) GetRepository(ctx context.Context) (*Repository, error)\n```\nGetRepository fetches the repository's metadata.\n\n```go\nfunc (c *ArtifactCollector) GetWorkflowRun(ctx context.Context) (*WorkflowRun, error)\n```\nGetWorkflowRun fetches this run's metadata.\n\n```go\nfunc (c *ArtifactCollector) ListArtifacts(ctx context.Context) ([]Artifact, error)\n```\nListArtifacts lists all artifacts for the current workflow run\n\n```go\nfunc (c *ArtifactCollector) ListPullsForCommit(ctx context.Context, sha string) ([]PullRequestRef, error)\n```\nListPullsForCommit finds the pull requests a commit belongs to. Used on a push to a branch that has an open PR, where the event payload carries no PR number.\n\n```go\ntype ArtifactMetadata struct {\n\tRepository      string            `json:\"repository\"`\n\tRepositoryOwner string            `json:\"repository_owner\"`\n\tRunID           string            `json:\"run_id\"`\n\tRunNumber       string            `json:\"run_number\"`\n\tWorkflowName    string            `json:\"workflow_name\"`\n\tJobName         string            `json:\"job\"`\n\tSHA             string            `json:\"sha\"`\n\tRefName         string            `json:\"ref_name\"`\n\tRefType         string            `json:\"ref_type\"`\n\tEventName       string            `json:\"event_name\"`\n\tActor           string            `json:\"actor\"`\n\tServerURL       string            `json:\"server_url\"`\n\tAPIURL          string            `json:\"api_url\"`\n\tArtifacts       []string          `json:\"artifacts\"`\n\tExtraEnvVars    map[string]string `json:\"extra_env_vars,omitempty\"`\n}\n```\nArtifactMetadata contains metadata about the workflow and artifacts\n\n```go\nfunc CollectMetadata(artifactNames []string) *ArtifactMetadata\n```\nCollectMetadata collects metadata from GitHub Actions environment\n\n```go\ntype ArtifactsResponse struct {\n\tTotalCount int        `json:\"total_count\"`\n\tArtifacts  []Artifact `json:\"artifacts\"`\n}\n```\nArtifactsResponse represents the GitHub API response for artifacts\n\n```go\ntype AssetEntry struct {\n\tID                 int64  `json:\"id\"`\n\tName               string `json:\"name\"`\n\tSize               int64  `json:\"size\"`\n\tBrowserDownloadURL string `json:\"browser_download_url\"`\n}\n```\nAssetEntry is an uploaded release asset.\n\n```go\ntype Campaign struct {\n\tNumber      int    `json:\"number\"`\n\tName        string `json:\"name\"`\n\tDescription string `json:\"description\"`\n\tState       string `json:\"state\"`\n\tEndsAt      string `json:\"ends_at\"`\n\tContactLink string `json:\"contact_link\"`\n\tHTMLURL     string `json:\"html_url\"`\n}\n```\nCampaign is a GitHub security campaign as listed.\n\n```go\ntype CampaignAlerts struct {\n\tRepositoryID int   `json:\"repository_id\"`\n\tAlertNumbers []int `json:\"alert_numbers\"`\n}\n```\nCampaignAlerts names the code scanning alerts of one repository.\n\n```go\ntype CampaignCreate struct {\n\tName               string           `json:\"name\"`\n\tDescription        string           `json:\"description\"`\n\tEndsAt             string           `json:\"ends_at\"`\n\tContactLink        string           `json:\"contact_link,omitempty\"`\n\tCodeScanningAlerts []CampaignAlerts `json:\"code_scanning_alerts\"`\n\tGenerateIssues     bool             `json:\"generate_issues\"`\n}\n```\nCampaignCreate is the create body.\n\n```go\ntype CampaignPatch struct {\n\tName        string `json:\"name,omitempty\"`\n\tDescription string `json:\"description,omitempty\"`\n\tEndsAt      string `json:\"ends_at,omitempty\"`\n\tContactLink string `json:\"contact_link,omitempty\"`\n\tState       string `json:\"state,omitempty\"`\n}\n```\nCampaignPatch is the update body. Empty fields are left out and so stay as they are.\n\n```go\ntype Client struct {\n\tBaseURL string\n\tToken   string\n\tHTTP    *http.Client\n\t// MaxWait bounds the time one request spends waiting out rate limits.\n\tMaxWait time.Duration\n\t// Calls counts requests made.\n\tCalls int\n}\n```\nClient makes authenticated GitHub REST calls.\n\n```go\nfunc NewClient(token string) *Client\n```\nNewClient returns a client for GITHUB\\_API\\_URL with token.\n\n```go\nfunc (c *Client) CreateAdvisory(ctx context.Context, repo string, req AdvisoryRequest) (*RepositoryAdvisory, error)\n```\nCreateAdvisory creates a draft advisory.\n\n```go\nfunc (c *Client) CreateCampaign(ctx context.Context, org string, req CampaignCreate) (*Campaign, error)\n```\nCreateCampaign creates a campaign.\n\n```go\nfunc (c *Client) Do(ctx context.Context, method, path string, body, out any) (http.Header, error)\n```\nDo sends body (JSON-encoded unless it is \\[]byte or nil) and decodes a JSON answer into out (when non-nil). It returns the response headers.\n\n```go\nfunc (c *Client) EnsureRelease(ctx context.Context, repo, tag string, create bool) (*ReleaseInfo, bool, error)\n```\nEnsureRelease returns the release for tag. When there is none it creates it as a draft if create is set, so nothing is published by accident, and otherwise returns the 404. Needs contents: write.\n\n```go\nfunc (c *Client) GetAll(ctx context.Context, path string, out any) error\n```\nGetAll fetches every page of a list endpoint and decodes the concatenated items into out (a pointer to a slice).\n\n```go\nfunc (c *Client) ListAdvisories(ctx context.Context, repo string) ([]RepositoryAdvisory, error)\n```\nListAdvisories returns every repository advisory, all states.\n\n```go\nfunc (c *Client) ListCampaigns(ctx context.Context, org string) ([]Campaign, error)\n```\nListCampaigns returns the organization's campaigns, open and closed.\n\n```go\nfunc (c *Client) ListOpenAlerts(ctx context.Context, repo string) ([]Alert, error)\n```\nListOpenAlerts returns the repository's open code scanning alerts.\n\n```go\nfunc (c *Client) PatchCampaign(ctx context.Context, org string, number int, req CampaignPatch) (*Campaign, error)\n```\nPatchCampaign updates a campaign by its number.\n\n```go\nfunc (c *Client) RepositoryID(ctx context.Context, repo string) (int, error)\n```\nRepositoryID returns the numeric id of owner/name.\n\n```go\nfunc (c *Client) SubmitSnapshot(ctx context.Context, repo string, s *Snapshot) (*SnapshotResult, error)\n```\nSubmitSnapshot posts a snapshot.\n\n```go\nfunc (c *Client) SubmitSnapshotLenient(ctx context.Context, repo string, s *Snapshot) (*SnapshotResult, []string, error)\n```\nSubmitSnapshotLenient posts a snapshot and, when GitHub refuses one package as invalid, drops that package and posts again, so one purl the API does not know cannot cost the repository its whole dependency graph. It returns the packages it left out.\n\n```go\nfunc (c *Client) UpdateAdvisory(ctx context.Context, repo, ghsaID string, req AdvisoryRequest) (*RepositoryAdvisory, error)\n```\nUpdateAdvisory edits a draft advisory. It never sends a state, so it cannot publish one.\n\n```go\nfunc (c *Client) UploadAsset(ctx context.Context, repo string, rel *ReleaseInfo, path, name string, clobber bool) (*AssetEntry, error)\n```\nUploadAsset uploads the file at path to the release under name. An asset of the same name is replaced when clobber is set, and is an error otherwise, since GitHub refuses a duplicate name.\n\n```go\nfunc (c *Client) UploadSARIF(ctx context.Context, t Target, sarifJSON []byte, checkoutURI string) (*SARIFUpload, error)\n```\nUploadSARIF posts one SARIF document for the target commit and ref.\n\n```go\nfunc (c *Client) WaitSARIF(ctx context.Context, repo, id string, timeout, interval time.Duration) (*SARIFUpload, error)\n```\nWaitSARIF polls an upload until it is complete or failed, or until timeout. A timeout is not an error: GitHub keeps processing, and the upload stands.\n\n```go\ntype Manifest struct {\n\tName     string                     `json:\"name\"`\n\tFile     *ManifestFile              `json:\"file,omitempty\"`\n\tResolved map[string]ResolvedPackage `json:\"resolved\"`\n}\n```\nManifest is one manifest's resolved packages.\n\n```go\ntype ManifestFile struct {\n\tSourceLocation string `json:\"source_location\"`\n}\n```\nManifestFile is the manifest's path in the repository.\n\n```go\ntype PullRequestRef struct {\n\tNumber int    `json:\"number\"`\n\tState  string `json:\"state\"`\n\tBase   struct {\n\t\tRef string `json:\"ref\"`\n\t} `json:\"base\"`\n\tHead struct {\n\t\tRef string `json:\"ref\"`\n\t} `json:\"head\"`\n}\n```\nPullRequestRef is one PR a commit belongs to.\n\n```go\ntype Release struct {\n\tTagName string         `json:\"tag_name\"`\n\tAssets  []ReleaseAsset `json:\"assets\"`\n}\n```\n\n```go\nfunc FetchReleaseByTag(ctx context.Context, token, apiURL, repository, tag string) (*Release, error)\n```\nFetchReleaseByTag reads one release by its tag.\n\napiURL is a parameter rather than a constant because GitHub Enterprise serves a different host, and guessing github.com there would read the wrong instance.\n\n```go\nfunc (r *Release) AssetMatching(substr string) *ReleaseAsset\n```\nAssetMatching finds the first asset whose name contains substr, ignoring case.\n\nSubstring rather than exact match because projects spell the same file checksums.txt, SHA256SUMS and tool\\_checksums.txt, and requiring each repository to declare which would be a per-repository input for a question the release itself already answers.\n\n```go\ntype ReleaseAsset struct {\n\tName               string `json:\"name\"`\n\tBrowserDownloadURL string `json:\"browser_download_url\"`\n}\n```\n\n```go\ntype ReleaseInfo struct {\n\tID        int64        `json:\"id\"`\n\tTagName   string       `json:\"tag_name\"`\n\tUploadURL string       `json:\"upload_url\"`\n\tHTMLURL   string       `json:\"html_url\"`\n\tDraft     bool         `json:\"draft\"`\n\tAssets    []AssetEntry `json:\"assets\"`\n}\n```\nReleaseInfo is a release as the write side needs it.\n\n```go\ntype Repository struct {\n\tID            int64  `json:\"id\"`\n\tFullName      string `json:\"full_name\"`\n\tPrivate       bool   `json:\"private\"`\n\tVisibility    string `json:\"visibility\"`\n\tDefaultBranch string `json:\"default_branch\"`\n\tOwner         *User  `json:\"owner\"`\n\tLicense       *struct {\n\t\tSpdxID string `json:\"spdx_id\"`\n\t} `json:\"license\"`\n}\n```\nRepository is the subset of GET /repos/{repo} worth keeping.\n\n```go\ntype RepositoryAdvisory struct {\n\tGHSAID      string `json:\"ghsa_id\"`\n\tSummary     string `json:\"summary\"`\n\tDescription string `json:\"description\"`\n\tState       string `json:\"state\"`\n\tHTMLURL     string `json:\"html_url\"`\n}\n```\nRepositoryAdvisory is an advisory as listed.\n\n```go\ntype ResolvedPackage struct {\n\tPackageURL   string   `json:\"package_url\"`\n\tRelationship string   `json:\"relationship,omitempty\"`\n\tScope        string   `json:\"scope,omitempty\"`\n\tDependencies []string `json:\"dependencies,omitempty\"`\n}\n```\nResolvedPackage is one package in a manifest.\n\n```go\ntype SARIFUpload struct {\n\tID               string   `json:\"id\"`\n\tURL              string   `json:\"url\"`\n\tProcessingStatus string   `json:\"processing_status,omitempty\"`\n\tAnalysesURL      string   `json:\"analyses_url,omitempty\"`\n\tErrors           []string `json:\"errors,omitempty\"`\n}\n```\nSARIFUpload is one upload's id and processing state.\n\n```go\ntype Snapshot struct {\n\tVersion   int                 `json:\"version\"`\n\tSHA       string              `json:\"sha\"`\n\tRef       string              `json:\"ref\"`\n\tJob       SnapshotJob         `json:\"job\"`\n\tDetector  SnapshotDetector    `json:\"detector\"`\n\tScanned   string              `json:\"scanned\"`\n\tManifests map[string]Manifest `json:\"manifests\"`\n}\n```\nSnapshot is the dependency submission API's request body.\n\n```go\nfunc BuildSnapshot(cdxJSON []byte, o SnapshotOptions) (*Snapshot, error)\n```\nBuildSnapshot turns a CycloneDX JSON document into a snapshot.\n\n```go\nfunc (s *Snapshot) Drop(purl string) bool\n```\nDrop removes a package, and every reference to it, from the snapshot. It reports whether the package was there.\n\n```go\nfunc (s *Snapshot) ManifestCount() int\n```\nManifestCount and PackageCount summarise a snapshot.\n\n```go\nfunc (s *Snapshot) PackageCount() int\n```\n\n```go\ntype SnapshotDetector struct {\n\tName    string `json:\"name\"`\n\tVersion string `json:\"version\"`\n\tURL     string `json:\"url\"`\n}\n```\nSnapshotDetector names the tool.\n\n```go\ntype SnapshotJob struct {\n\tCorrelator string `json:\"correlator\"`\n\tID         string `json:\"id\"`\n\tHTMLURL    string `json:\"html_url,omitempty\"`\n}\n```\nSnapshotJob identifies the run; the correlator is what makes a later snapshot replace this one rather than add to it.\n\n```go\ntype SnapshotOptions struct {\n\tTarget          Target\n\tCorrelator      string\n\tJobID           string\n\tJobURL          string\n\tDetectorVersion string\n\t// DefaultManifest names the manifest for components with no\n\t// vulnetix:source-file (an SBOM this CLI did not write).\n\tDefaultManifest string\n\tNow             time.Time\n}\n```\nSnapshotOptions are the run details a snapshot carries.\n\n```go\ntype SnapshotResult struct {\n\tID        int64  `json:\"id\"`\n\tCreatedAt string `json:\"created_at\"`\n\tResult    string `json:\"result\"`\n\tMessage   string `json:\"message\"`\n}\n```\nSnapshotResult is the API's answer.\n\n```go\ntype Target struct {\n\t// Repo is owner/name.\n\tRepo string\n\t// SHA is the full commit SHA.\n\tSHA string\n\t// Ref is the full ref (refs/heads/main, refs/pull/7/merge).\n\tRef string\n}\n```\nTarget is the repository, commit and ref a publish applies to.\n\n```go\nfunc ResolveTarget(dir, repo, sha, ref string) (Target, error)\n```\nResolveTarget works out the repository, commit and ref, explicit values first, then the GitHub Actions environment (GITHUB\\_REPOSITORY, GITHUB\\_SHA, GITHUB\\_REF; on pull\\_request the merge ref and merge commit, which is what code scanning expects), then the git checkout at dir. It errors when any of the three is still unknown.\n\n```go\nfunc (t Target) Name() string\n```\n\n```go\nfunc (t Target) Owner() string\n```\nOwner and Name split Repo.\n\n```go\ntype User struct {\n\tLogin string `json:\"login\"`\n\tType  string `json:\"type\"`\n}\n```\nUser is a GitHub account reference.\n\n```go\ntype WorkflowRun struct {\n\tID              int64  `json:\"id\"`\n\tName            string `json:\"name\"`\n\tRunNumber       int    `json:\"run_number\"`\n\tRunAttempt      int    `json:\"run_attempt\"`\n\tEvent           string `json:\"event\"`\n\tStatus          string `json:\"status\"`\n\tConclusion      string `json:\"conclusion\"`\n\tHeadBranch      string `json:\"head_branch\"`\n\tHeadSHA         string `json:\"head_sha\"`\n\tHTMLURL         string `json:\"html_url\"`\n\tPath            string `json:\"path\"`\n\tActor           *User  `json:\"actor\"`\n\tTriggeringActor *User  `json:\"triggering_actor\"`\n\tPullRequests    []struct {\n\t\tNumber int `json:\"number\"`\n\t} `json:\"pull_requests\"`\n}\n```\nWorkflowRun is the subset of GET /repos/{repo}/actions/runs/{id} worth keeping.\n\n","path":"github.com/vulnesis/cli/internal/github","name":"github","synopsis":"","isRedistributable":true}
