Documentation
¶
Index ¶
- Constants
- Variables
- func ErrCloningRepo(err error) error
- func ErrFetchingGitBlob(err error, path string) error
- func ErrFetchingGitTree(err error, ref string) error
- func ErrInvalidBaseURL(err error, baseURL string) error
- func ErrInvalidSizeFile(err error) error
- func ErrNoFileInterceptor() error
- func ErrResolvingGitRef(err error, ref string) error
- func ErrRootNotFound(root, ref string) error
- func ErrSymlinkedRoot(root, ref string) error
- type CandidateFile
- type DirInterceptor
- type Directory
- type File
- type FileInterceptor
- type Git
- func (g *Git) BaseURL(baseurl string) *Git
- func (g *Git) Branch(branch string) *Git
- func (g *Git) FetchCandidates(ctx context.Context, candidates []CandidateFile) error
- func (g *Git) ListInterestingFiles(ctx context.Context) (InterestingFiles, error)
- func (g *Git) MaxFileSize(size int64) *Git
- func (g *Git) Owner(owner string) *Git
- func (g *Git) ReferenceName(refName string) *Git
- func (g *Git) RegisterDirInterceptor(i DirInterceptor) *Git
- func (g *Git) RegisterFileInterceptor(i FileInterceptor) *Git
- func (g *Git) RegisterProgressHook(h ProgressHook) *Git
- func (g *Git) Repo(repo string) *Git
- func (g *Git) Root(root string) *Git
- func (g *Git) ShowLogs() *Git
- func (g *Git) Timeout(d time.Duration) *Git
- func (g *Git) Token(token string) *Git
- func (g *Git) UseGithubAPI() *Git
- func (g *Git) Walk() error
- func (g *Git) WalkContext(ctx context.Context) error
- type Github
- func (g *Github) Branch(branch string) *Github
- func (g *Github) Owner(owner string) *Github
- func (g *Github) RegisterDirInterceptor(i GithubDirInterceptor) *Github
- func (g *Github) RegisterFileInterceptor(i GithubFileInterceptor) *Github
- func (g *Github) RegisterProgressHook(h ProgressHook) *Github
- func (g *Github) Repo(repo string) *Github
- func (g *Github) Root(root string) *Github
- func (g *Github) Token(token string) *Github
- func (g *Github) Walk() error
- func (g *Github) WalkContext(ctx context.Context) error
- type GithubContentAPI
- type GithubDirInterceptor
- type GithubDirectoryContentAPI
- type GithubFileInterceptor
- type InterestingFiles
- type ProgressHook
- type ProgressStage
- type ProgressUpdate
Constants ¶
const ( ScoreHelmChartDefinition = 100 ScoreKustomization = 90 ScoreDockerCompose = 80 ScoreMesheryDesign = 70 ScoreChartArchive = 60 ScoreGenericYAML = 20 ScoreGenericJSON = 10 )
Relevance scores assigned to a candidate from its path alone. A larger score ranks earlier. They are exported so that callers rendering a picker can group or threshold candidates the same way the walker ranks them.
Variables ¶
var ( ErrInvalidSizeFileCode = "meshkit-11241" ErrCloningRepoCode = "meshkit-11242" ErrResolvingGitRefCode = "meshkit-11328" ErrFetchingGitTreeCode = "meshkit-11329" ErrFetchingGitBlobCode = "meshkit-11330" ErrInvalidBaseURLCode = "meshkit-11331" ErrNoFileInterceptorCode = "meshkit-11332" ErrRootNotFoundCode = "meshkit-11333" ErrSymlinkedRootCode = "meshkit-11334" )
Functions ¶
func ErrCloningRepo ¶
func ErrFetchingGitBlob ¶ added in v1.0.24
ErrFetchingGitBlob is returned when a selected blob could not be downloaded.
func ErrFetchingGitTree ¶ added in v1.0.24
ErrFetchingGitTree is returned when the recursive Git Trees API call fails.
func ErrInvalidBaseURL ¶ added in v1.0.24
ErrInvalidBaseURL is returned when the configured base URL cannot be used for the GitHub API, either because it does not parse or because it names a host other than github.com.
func ErrInvalidSizeFile ¶
func ErrNoFileInterceptor ¶ added in v1.0.24
func ErrNoFileInterceptor() error
ErrNoFileInterceptor is returned when files are fetched with no interceptor registered to receive them.
func ErrResolvingGitRef ¶ added in v1.0.24
ErrResolvingGitRef is returned when a branch, tag or reference name could not be resolved to a commit SHA through the GitHub API.
func ErrRootNotFound ¶ added in v1.0.24
ErrRootNotFound is returned when the configured root names no file or directory in the repository at the reference being walked.
func ErrSymlinkedRoot ¶ added in v1.0.24
ErrSymlinkedRoot is returned when the configured root is a symbolic link and the listing route, which has no clone to read it through, cannot serve it.
Types ¶
type CandidateFile ¶ added in v1.0.24
type CandidateFile struct {
// Path is the repository-relative path of the file.
Path string `json:"path,omitempty"`
// Name is the base name of Path.
Name string `json:"name,omitempty"`
// SHA is the blob SHA, suitable for a later blob fetch.
SHA string `json:"sha,omitempty"`
// Size is the blob size in bytes as reported by the tree.
Size int64 `json:"size,omitempty"`
// Kind is the IaC file type inferred from the path. It is empty when the
// path is interesting but not distinctive enough to name a type.
Kind core.IaCFileTypes `json:"kind,omitempty"`
// Score is the relevance score used for the ranking.
Score int `json:"score,omitempty"`
}
CandidateFile is a single interesting file described from Git tree metadata alone. No blob has been downloaded to produce it, so Kind is inferred from the path and is a hint, not an identification: the authoritative answer comes from files.IdentifyFile once the contents are in hand.
type DirInterceptor ¶
type File ¶
type File struct {
Name string `json:"name,omitempty"`
Content string `json:"content,omitempty"`
Path string `json:"path,omitempty"`
}
func WalkLocalDirectory ¶
type FileInterceptor ¶
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git represents the Git Walker
func (*Git) BaseURL ¶
BaseURL sets git repository base URL and returns a pointer to the same Git instance
func (*Git) Branch ¶
Branch sets git repository branch which will be cloned and returns a pointer to the same Git instance
func (*Git) FetchCandidates ¶ added in v1.0.24
func (g *Git) FetchCandidates(ctx context.Context, candidates []CandidateFile) error
FetchCandidates downloads the blob behind each candidate and hands it to the registered file interceptor, in the order given. Candidates usually come from ListInterestingFiles, filtered down to whatever the user selected.
Downloads overlap, up to blobFetchConcurrency at a time, but the interceptor is still called once at a time and in order, so it does not have to be safe for concurrent use.
File.Path on the intercepted file is the repository-relative path, not a local filesystem path: nothing is written to disk on this route.
The repository must be on github.com, for the reason ListInterestingFiles gives, and a file interceptor must be registered: a fetch with nowhere to deliver to is refused rather than reported as an import of no files.
func (*Git) ListInterestingFiles ¶ added in v1.0.24
func (g *Git) ListInterestingFiles(ctx context.Context) (InterestingFiles, error)
ListInterestingFiles resolves the configured reference to a commit, lists that commit's tree recursively in a single request, and returns the ranked candidate files. No blob is downloaded, so the result is cheap enough to render an import picker from.
The listing is always recursive, because a picker is asking what the repository holds: with no Root configured that is the whole repository, and a Root narrows which subtree is listed, never how deep. Walk keeps its own historical meaning for Root - the named directory only, unless the caller asked for "/**" - and is unaffected by this.
A truncated listing is reported through InterestingFiles.Truncated rather than as an error: the candidates returned are still usable, they are just not the whole repository.
The repository must be on github.com. There is no clone to fall back to on this route, and the access token must never travel to a host the caller did not configure.
func (*Git) MaxFileSize ¶
BaseURL sets git repository base URL and returns a pointer to the same Git instance
func (*Git) ReferenceName ¶
func (*Git) RegisterDirInterceptor ¶
func (g *Git) RegisterDirInterceptor(i DirInterceptor) *Git
func (*Git) RegisterFileInterceptor ¶
func (g *Git) RegisterFileInterceptor(i FileInterceptor) *Git
func (*Git) RegisterProgressHook ¶ added in v1.0.24
func (g *Git) RegisterProgressHook(h ProgressHook) *Git
RegisterProgressHook registers a callback invoked as the walk advances through its stages. The hook is called synchronously, so it should return promptly.
func (*Git) Root ¶
Root sets git repository root node from where Git walker needs to start traversing and returns a pointer to the same Git instance
If the root parameter ends with a "/**" then github walker will run in "traversal" mode, ie. it will look into each sub directory of the root node If path will be prefixed with "/" if not already.
A root of "" or "/" scopes nothing: a walk reads the repository root exactly as it always has, and ListInterestingFiles reads it as the whole repository.
func (*Git) Timeout ¶ added in v1.0.24
Timeout bounds the whole traversal. A zero duration, the default, leaves the traversal bounded only by the context passed to WalkContext.
func (*Git) Token ¶ added in v1.0.24
Token sets the GitHub App or OAuth access token used to authenticate against the GitHub API and against the go-git clone, so private repositories are reachable and the authenticated rate limit applies.
The token is never logged, never placed in an error message and never reported through the progress hook.
func (*Git) UseGithubAPI ¶ added in v1.0.24
UseGithubAPI opts the walker into the hybrid GitHub crawl: Trees API plus selective blob downloads, with a go-git clone as the fallback. It is off by default so existing callers keep the clone-and-filter behaviour.
func (*Git) Walk ¶
Walk will initiate traversal process.
It is equivalent to WalkContext with a background context and is retained for callers that predate context support.
func (*Git) WalkContext ¶ added in v1.0.24
WalkContext initiates the traversal process under ctx.
When UseGithubAPI has been enabled and the configured base URL points at github.com, the traversal runs over the Git Trees API: the reference is resolved to a commit, the tree is listed once recursively, the entries are filtered and ranked, and only the surviving blobs are downloaded. Every other case - a non-github.com host, a truncated tree, or the API path not being enabled - walks a go-git clone exactly as Walk always has.
type Github ¶
type Github struct {
// contains filtered or unexported fields
}
Github represents the Github Walker
func (*Github) Branch ¶
Branch sets github repository branch which will be traversed and returns a pointer to the same Github instance
func (*Github) Owner ¶
Owner sets github repository owner and returns a pointer to the same Github instance
func (*Github) RegisterDirInterceptor ¶
func (g *Github) RegisterDirInterceptor(i GithubDirInterceptor) *Github
RegisterFileInterceptor takes in a directory interceptor which will be invoked on each "directory" node and it returns pointer to the same github instance
Github Walker walks the nodes concurrently so if the interceptor is reading or writing to any variable from a higher namespace then those operations should be done in thread safe manner in order to avoid data races
func (*Github) RegisterFileInterceptor ¶
func (g *Github) RegisterFileInterceptor(i GithubFileInterceptor) *Github
RegisterFileInterceptor takes in a file interceptor which will be invoked on each "file" node and it returns pointer to the same github instance
Github Walker walks the nodes concurrently so if the interceptor is reading or writing to any variable from a higher namespace then those operations should be done in thread safe manner in order to avoid data races
func (*Github) RegisterProgressHook ¶ added in v1.0.24
func (g *Github) RegisterProgressHook(h ProgressHook) *Github
RegisterProgressHook registers a callback invoked as the walk advances. The hook is called from the goroutine walking the node, so an implementation that touches shared state must do so in a thread safe manner.
func (*Github) Root ¶
Root sets github repository root node from where Github walker needs to start traversing and returns a pointer to the same Github instance
If the root parameter ends with a "/**" then github walker will run in "traversal" mode, ie. it will look into each sub directory of the root node
If the root node ends with an extension, then that file will be returned and github walker will not traverse deeper
func (*Github) Token ¶ added in v1.0.24
Token sets the GitHub App or OAuth access token used to authenticate the Contents API calls, so private repositories are reachable and the authenticated rate limit applies.
The token is never logged and never placed in an error message.
type GithubContentAPI ¶
type GithubContentAPI struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
SHA string `json:"sha,omitempty"`
Size int64 `json:"size,omitempty"`
URL string `json:"url,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
GitURL string `json:"git_url,omitempty"`
DownloadURL string `json:"download_url,omitempty"`
Type string `json:"type,omitempty"`
// Content will be empty when the path is of a directory
Content string `json:"content,omitempty"`
// Encoding will be empty when the path is of a directory
Encoding string `json:"encoding,omitempty"`
}
GithubContentAPI represents Github API v3 response to /repos/{owner}/{repo}/contents/{path}?ref={branch}
type GithubDirInterceptor ¶
type GithubDirInterceptor func(GithubDirectoryContentAPI) error
GithubDirInterceptor represents function signature which will be used on "dir" nodes when the github walker traverses the paths
type GithubDirectoryContentAPI ¶
type GithubDirectoryContentAPI []GithubContentAPI
GithubDirectoryContentAPI represents Github API v3 response to /repos/{owner}/{repo}/contents/{path}?ref={branch} when "path" is of a directory
type GithubFileInterceptor ¶
type GithubFileInterceptor func(GithubContentAPI) error
GithubFileInterceptor represents function signature which will be used on "file" nodes when the github walker traverses the paths
type InterestingFiles ¶ added in v1.0.24
type InterestingFiles struct {
// CommitSHA is the commit the tree was listed from.
CommitSHA string `json:"commitSha,omitempty"`
// Truncated reports that GitHub could not return the whole tree in one
// response, so Candidates is incomplete and a clone is needed to see
// every file.
Truncated bool `json:"truncated,omitempty"`
// Candidates is ranked most interesting first.
Candidates []CandidateFile `json:"candidates,omitempty"`
}
InterestingFiles is the ranked candidate listing for one commit.
type ProgressHook ¶ added in v1.0.24
type ProgressHook func(ProgressUpdate)
ProgressHook receives ProgressUpdate values as a walk advances. How it is delivered differs per walker and is documented on each RegisterProgressHook: Git calls it one update at a time, while Github calls it from every goroutine its fan-out walks a node with. An implementation that touches shared state must therefore be safe for concurrent use.
type ProgressStage ¶ added in v1.0.24
type ProgressStage string
ProgressStage names the phase of a walk a ProgressUpdate describes.
const ( ProgressStageResolveRef ProgressStage = "resolve-ref" ProgressStageListTree ProgressStage = "list-tree" ProgressStageRank ProgressStage = "rank" ProgressStageFetchBlob ProgressStage = "fetch-blob" ProgressStageClone ProgressStage = "clone" )
Progress stages reported through a ProgressHook.
type ProgressUpdate ¶ added in v1.0.24
type ProgressUpdate struct {
Stage ProgressStage `json:"stage,omitempty"`
Message string `json:"message,omitempty"`
Current int `json:"current,omitempty"`
Total int `json:"total,omitempty"`
}
ProgressUpdate describes how far a walk has advanced. Current and Total are only meaningful for stages that iterate over a known number of items, such as blob downloads; they are zero elsewhere.
An update never carries the access token.