data

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 19 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 ClientMock

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

func (*ClientMock) Do

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

type Dependency

type Dependency struct {
	PackageName  string
	Requirements string
}

type DependencyManifestsPage

type DependencyManifestsPage struct {
	Repository struct {
		DependencyGraphManifests struct {
			TotalCount int
		}
	} `graphql:"repository(owner: $owner, name: $name)"`
}

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) 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) IsMFARequiredForAdministrativeActions

func (r *GitHubRepositoryMetadata) IsMFARequiredForAdministrativeActions() *bool

func (*GitHubRepositoryMetadata) IsPublic

func (r *GitHubRepositoryMetadata) IsPublic() bool

func (*GitHubRepositoryMetadata) OrganizationBlogURL

func (r *GitHubRepositoryMetadata) OrganizationBlogURL() *string

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})"`
	} `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
					Object *struct {
						Blob struct {
							IsBinary    *bool
							IsTruncated bool
						} `graphql:"... on Blob"`
						Tree struct {
							Entries []struct {
								Name   string
								Type   string
								Path   string
								Object *struct {
									Blob struct {
										IsBinary    *bool
										IsTruncated bool
									} `graphql:"... on Blob"`
									Tree struct {
										Entries []struct {
											Name   string
											Type   string
											Path   string
											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 HttpClient

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

type ManifestNode

type ManifestNode struct {
	Filename     string
	Dependencies []Dependency
}

type Payload

type Payload struct {
	*GraphqlRepoData
	*RestData
	Config                   *config.Config
	SuspectedBinaries        []string
	RepositoryMetadata       RepositoryMetadata
	DependencyManifestsCount int
	IsCodeRepo               bool
	SecurityPosture          SecurityPosture
	// contains filtered or unexported fields
}

func NewPayloadWithHTTPMock

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

func (*Payload) GetSuspectedBinaries

func (p *Payload) GetSuspectedBinaries() (suspectedBinaries []string, err error)

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
}

func (*RepoContent) GetSubdirContentByPath

func (c *RepoContent) GetSubdirContentByPath(r *RestData, path string) (RepoContent, error)

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
	IsMFARequiredForAdministrativeActions() *bool
	IsDefaultBranchProtected() *bool
	DefaultBranchRequiresPRReviews() *bool
	IsDefaultBranchProtectedFromDeletion() *bool
}

type RestData

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

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

func (*RestData) GetDirectoryContent

func (r *RestData) GetDirectoryContent(path string) (dirContent []*github.RepositoryContent, err error)

func (*RestData) GetFileContent

func (r *RestData) GetFileContent(path string) (content *github.RepositoryContent, err error)

func (*RestData) GetRulesets

func (r *RestData) GetRulesets(branchName string) []Ruleset

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 Ruleset

type Ruleset struct {
	Type       string `json:"type"`
	Parameters struct {
		RequiredChecks []struct {
			Context string `json:"context"`
		} `json:"required_status_checks"`
	} `json:"parameters"`
}

type SecurityPosture

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

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

type WorkflowPermissions

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

Jump to

Keyboard shortcuts

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