data

package
v0.27.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIBase = "https://api.github.com"

Functions

func Loader

func Loader(config *config.Config) (payload any, err error)

Types

type BinaryAnalysis added in v0.27.0

type BinaryAnalysis struct {
	Suspected    []string // OSPS-QA-05.01: suspected executable binary artifacts
	Unreviewable []string // OSPS-QA-05.02: unreviewable binary artifacts
	Err          error
}

BinaryAnalysis holds information about binaries found in the repo

type ClientMock

type ClientMock struct {
	Response *http.Response
	Err      error
}

func (*ClientMock) Do

func (c *ClientMock) Do(req *http.Request) (*http.Response, error)

type GitHubRepositoryMetadata

type GitHubRepositoryMetadata struct {
	Releases []ReleaseData
	// contains filtered or unexported fields
}

func (*GitHubRepositoryMetadata) DefaultBranchRequiresPRReviews added in v0.19.0

func (r *GitHubRepositoryMetadata) DefaultBranchRequiresPRReviews() *bool

func (*GitHubRepositoryMetadata) HasBranchRules added in v0.27.0

func (r *GitHubRepositoryMetadata) HasBranchRules() bool

HasBranchRules reports whether any ruleset at all applies to the default branch, which determines whether rulesets or branch protection are treated as the authoritative source for status check requirements.

func (*GitHubRepositoryMetadata) IsActive

func (r *GitHubRepositoryMetadata) IsActive() bool

func (*GitHubRepositoryMetadata) IsDefaultBranchProtected added in v0.19.0

func (r *GitHubRepositoryMetadata) IsDefaultBranchProtected() *bool

func (*GitHubRepositoryMetadata) IsDefaultBranchProtectedFromDeletion added in v0.19.0

func (r *GitHubRepositoryMetadata) IsDefaultBranchProtectedFromDeletion() *bool

func (*GitHubRepositoryMetadata) IsPublic

func (r *GitHubRepositoryMetadata) IsPublic() bool

func (*GitHubRepositoryMetadata) OrganizationBlogURL

func (r *GitHubRepositoryMetadata) OrganizationBlogURL() *string

func (*GitHubRepositoryMetadata) RequiredStatusCheckContexts added in v0.27.0

func (r *GitHubRepositoryMetadata) RequiredStatusCheckContexts() []string

RequiredStatusCheckContexts returns the names of the status checks that the default branch's rulesets mark as required.

func (*GitHubRepositoryMetadata) RulesetsObserved added in v0.27.0

func (r *GitHubRepositoryMetadata) RulesetsObserved() bool

RulesetsObserved reports whether the ruleset lookup for the default branch actually completed. The rulesets REST API is publicly readable, so a nil value means the fetch failed rather than that no rulesets exist — this lets callers tell "observed, none configured" from "never observed".

func (*GitHubRepositoryMetadata) ViewerCanAdminister added in v0.27.0

func (r *GitHubRepositoryMetadata) ViewerCanAdminister() bool

ViewerCanAdminister reports whether the scanning token holds admin on the repository. GitHub exposes classic branch protection (the GraphQL BranchProtectionRule and RefUpdateRule objects) only to admins; for any other token they come back as zero values indistinguishable from "no protection". Callers gate on this to tell an observed absence of protection apart from an invisible one.

type GraphqlRepoData

type GraphqlRepoData struct {
	Repository struct {
		Name                    string
		HasDiscussionsEnabled   bool
		HasIssuesEnabled        bool
		IsSecurityPolicyEnabled bool

		Object struct {
			Tree struct {
				Entries []struct {
					Name string
					Type string // "blob" for files, "tree" for directories
					Path string
				}
			} `graphql:"... on Tree"`
		} `graphql:"object(expression: \"HEAD:\")"`

		DefaultBranchRef struct {
			Name          string
			RefUpdateRule struct {
				AllowsDeletions              bool
				AllowsForcePushes            bool
				RequiredApprovingReviewCount int
			}
			BranchProtectionRule struct {
				RestrictsPushes             bool // This didn't give an accurate result
				RequiresApprovingReviews    bool // This gave an accurate result
				RequiresCommitSignatures    bool
				RequiresStatusChecks        bool
				RequireLastPushApproval     bool
				RequiredStatusCheckContexts []string
			}

			Target struct {
				OID    string `graphql:"oid"` // Latest commit SHA
				Commit struct {
					Status struct {
						State    string // Overall commit status
						Contexts []struct {
							Context     string
							Description string
							State       string
							TargetURL   string `graphql:"targetUrl"`
						}
					} `graphql:"status"` // Classic status API

					AssociatedPullRequests struct {
						Nodes []struct {
							StatusCheckRollup struct {
								Commit struct {
									CheckSuites struct {
										Nodes []struct {
											CheckRuns struct {
												Nodes []struct {
													Name string `graphql:"name"`
												}
											} `graphql:"checkRuns(first: 25)"`
										}
									} `graphql:"checkSuites(first: 25)"`
								}
							}
						}
					} `graphql:"associatedPullRequests(last: 1)"`
				} `graphql:"... on Commit"`
			} `graphql:"target"`
		}
		LicenseInfo struct {
			Name   string
			SpdxId string
			Url    string
		}
		LatestRelease struct {
			Description string
		}
		ContributingGuidelines struct {
			Body string
		}
		Releases struct {
			Nodes []struct {
				TagName string
				Name    string
				Assets  struct {
					Nodes []struct {
						Name        string
						ContentType string
					}
				} `graphql:"releaseAssets(first: 100)"`
			}
		} `graphql:"releases(first: 1, orderBy: {field: CREATED_AT, direction: DESC})"`

		// Selected here rather than in its own query: it targets the same
		// repository node, so it costs nothing extra to fetch alongside.
		DependencyGraphManifests struct {
			TotalCount int
		}
	} `graphql:"repository(owner: $owner, name: $name)"`
}

GraphqlRepoData is used in a query to get general repository information

type GraphqlRepoTree

type GraphqlRepoTree struct {
	Repository struct {
		Object struct {
			Tree struct {
				Entries []struct {
					Name   string
					Type   string
					Path   string
					Mode   int
					Object *struct {
						Blob struct {
							IsBinary    *bool
							IsTruncated bool
						} `graphql:"... on Blob"`
						Tree struct {
							Entries []struct {
								Name   string
								Type   string
								Path   string
								Mode   int
								Object *struct {
									Blob struct {
										IsBinary    *bool
										IsTruncated bool
									} `graphql:"... on Blob"`
									Tree struct {
										Entries []struct {
											Name   string
											Type   string
											Path   string
											Mode   int
											Object *struct {
												Blob struct {
													IsBinary    *bool
													IsTruncated bool
												} `graphql:"... on Blob"`
											} `graphql:"object"`
										}
									} `graphql:"... on Tree"`
								} `graphql:"object"`
							}
						} `graphql:"... on Tree"`
					} `graphql:"object"`
				}
			} `graphql:"... on Tree"`
		} `graphql:"object(expression: $branch)"`
	} `graphql:"repository(owner: $owner, name: $name)"`
}

type GraphqlWorkflowFiles added in v0.27.0

type GraphqlWorkflowFiles struct {
	Repository struct {
		Object struct {
			Tree struct {
				Entries []WorkflowTreeEntry
			} `graphql:"... on Tree"`
		} `graphql:"object(expression: $expression)"`
	} `graphql:"repository(owner: $owner, name: $name)"`
}

GraphqlWorkflowFiles is the query for a single directory's entries, selecting each entry's name, path, and full text in one round trip.

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Payload

type Payload struct {
	*GraphqlRepoData
	*RestData
	*pluginkit.APICallCounter // Enable Privateer benchmarking for API calls

	Config                   *config.Config
	RepositoryMetadata       RepositoryMetadata
	DependencyManifestsCount int
	IsCodeRepo               bool
	SecurityPosture          SecurityPosture
	Binaries                 BinaryAnalysis
	// contains filtered or unexported fields
}

func NewPayloadWithHTTPMock

func NewPayloadWithHTTPMock(base Payload, body []byte, statusCode int, httpErr error) Payload

func (*Payload) GetWorkflowFiles added in v0.27.0

func (p *Payload) GetWorkflowFiles() ([]WorkflowFile, error)

GetWorkflowFiles returns the decoded contents of every file in .github/workflows using a single GraphQL call, cached for reuse across the several build/release checks that inspect workflows.

type ReleaseAsset

type ReleaseAsset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
}

type ReleaseData

type ReleaseData struct {
	Id      int            `json:"id"`
	Name    string         `json:"name"`
	TagName string         `json:"tag_name"`
	URL     string         `json:"url"`
	Assets  []ReleaseAsset `json:"assets"`
}

type RepoContent

type RepoContent struct {
	Content    []*github.RepositoryContent
	SubContent map[string]RepoContent
}

type RepoSecurityPosture

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

func (*RepoSecurityPosture) DefinesPolicyForHandlingSecrets

func (rsp *RepoSecurityPosture) DefinesPolicyForHandlingSecrets() bool

func (*RepoSecurityPosture) PreventsPushingSecrets

func (rsp *RepoSecurityPosture) PreventsPushingSecrets() bool

func (*RepoSecurityPosture) ScansForSecrets

func (rsp *RepoSecurityPosture) ScansForSecrets() bool

type RepositoryMetadata

type RepositoryMetadata interface {
	IsActive() bool
	IsPublic() bool
	OrganizationBlogURL() *string
	IsDefaultBranchProtected() *bool
	DefaultBranchRequiresPRReviews() *bool
	IsDefaultBranchProtectedFromDeletion() *bool
	HasBranchRules() bool
	RequiredStatusCheckContexts() []string
	RulesetsObserved() bool
	ViewerCanAdminister() bool
}

type RestData

type RestData struct {
	Config              *config.Config
	WorkflowsEnabled    bool
	WorkflowPermissions WorkflowPermissions
	Insights            si.SecurityInsights
	InsightsError       bool
	Releases            []ReleaseData

	HttpClient HttpClient `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func (*RestData) FindFile added in v0.27.0

func (r *RestData) FindFile(names ...string) string

FindFile returns the repository path of the first of the given filenames found in the repository root or .github directory, matched case-insensitively. It reuses the REST contents fetched during Setup, so once .github has been probed it costs no additional API call. Returns "" when none of the names is present.

It exists so evaluation steps in other packages can run deterministic filesystem fallbacks without reaching into RestData's unexported checkFile.

func (*RestData) HasSupportMarkdown

func (r *RestData) HasSupportMarkdown() bool

returns true when a file with case insensitive name matching support.md is found in the root or forge directories or when the readme.md contains a heading named "Support"

func (*RestData) IsCodeRepo

func (r *RestData) IsCodeRepo() (bool, error)

IsCodeRepo returns true if the repository contains any programming languages.

TODO: Consider using GitHub Linguist metadata (https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml) to distinguish between programming, markup, data, and prose content types for more nuanced repository classification.

func (*RestData) MakeApiCall

func (r *RestData) MakeApiCall(endpoint string, isGithub bool) (body []byte, err error)

func (*RestData) Setup

func (r *RestData) Setup() error

type SecurityPosture

type SecurityPosture interface {
	PreventsPushingSecrets() bool
	ScansForSecrets() bool
	DefinesPolicyForHandlingSecrets() bool
}

SecurityPosture defines an interface for accessing security-related metadata about a repository.

type WorkflowBlob added in v0.27.0

type WorkflowBlob struct {
	Text        string
	IsTruncated bool
}

type WorkflowBlobObject added in v0.27.0

type WorkflowBlobObject struct {
	Blob WorkflowBlob `graphql:"... on Blob"`
}

type WorkflowFile added in v0.27.0

type WorkflowFile struct {
	Name      string
	Path      string
	Content   string
	Truncated bool
}

WorkflowFile is a single workflow definition with its contents already decoded.

Truncated marks a file GitHub declined to return in full. It is reported rather than dropped so callers can tell "inspected and clean" apart from "never inspected" — see checkAllWorkflows.

type WorkflowPermissions

type WorkflowPermissions struct {
	DefaultPermissions    string `json:"default_workflow_permissions"`
	CanApprovePullRequest bool   `json:"can_approve_pull_request_reviews"`
}

type WorkflowTreeEntry added in v0.27.0

type WorkflowTreeEntry struct {
	Name   string
	Path   string
	Type   string
	Mode   int
	Object *WorkflowBlobObject `graphql:"object"`
}

WorkflowTreeEntry is one entry in the fetched directory. Type is "blob" for files; Object is nil for entries with no inspectable contents.

Jump to

Keyboard shortcuts

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