import { Octokit } from '@octokit/rest'; import { RequestError } from '@octokit/request-error'; export declare const DEFAULT_FILE_MODE = "100644"; export declare class FileNotFoundError extends Error { path: string; constructor(path: string); } export declare class BranchNotFoundError extends FileNotFoundError { originalError: RequestError; constructor(path: string, originalError: RequestError); } export interface Repository { readonly owner: string; readonly repo: string; } export interface GitHubFileContents { sha: string; content: string; parsedContent: string; mode: string; } /** * This class is a read-through cache aimed at minimizing the * number of API requests needed to fetch file data/contents. * It lazy-caches data as it reads and will return cached data * for resources already fetched. */ export declare class RepositoryFileCache { private octokit; private repository; private cache; /** * Instantiate a new loading cache instance * * @param {Octokit} octokit An authenticated octokit instance * @param {Repository} repository The repository we are fetching data for */ constructor(octokit: Octokit, repository: Repository); /** * Fetch file contents for given path on a given branch. If the * data has already been fetched, return a cached copy. * * @param {string} path Path to the file * @param {string} branch Branch to fetch the file from * @returns {GitHubFileContents} The file contents */ getFileContents(path: string, branch: string): Promise; /** * Find all files with a given filename. * * @param {string} filename The filename of the files to search for. * @param {string} branch The name of the branch to search on. * @param {string} pathPrefix If set, limit results to files that begin * with this path prefix. Also if set, returns the path relative to * the path prefix. * @returns {string[]} Paths to the files (relative to path prefix) */ findFilesByFilename(filename: string, branch: string, pathPrefix?: string): Promise; /** * Find all files with a given file extension. * * @param {string} filename The file extension (excluding `.`) of the * files to search for. Example: `yaml`. * @param {string} branch The name of the branch to search on. * @param {string} pathPrefix If set, limit results to files that begin * with this path prefix. Also if set, returns the path relative to * the path prefix. * @returns {string[]} Paths to the files (relative to path prefix) */ findFilesByExtension(extension: string, branch: string, pathPrefix?: string): Promise; /** * Find all files matching a given glob. * * @param {string} glob The glob to match. * @param {string} branch The name of the branch to search on. * @param {string} pathPrefix If set, limit results to files that begin * with this path prefix. Also if set, returns the path relative to * the path prefix. * @returns {string[]} Paths to the files (relative to path prefix) */ findFilesByGlob(glob: string, branch: string, pathPrefix?: string): Promise; /** * Helper to find or create a BranchFileCache * @param {string} branch The branch the cache is for * @returns {BranchFileCache} The branch file cache */ private getBranchFileCache; } /** * This class is a read-through cache for a single branch aimed * at minimizing the number of API requests needed to fetch file * data/contents. It lazy-caches data as it reads and will return * cached data for resources already fetched. */ export declare class BranchFileCache { private octokit; private repository; private branch; private cache; private treeCache; /** * Instantiate a new loading cache instance * * @param {Octokit} octokit An authenticated octokit instance * @param {Repository} repository The repository we are fetching data for * @param {string} branch The branch we are fetching data from */ constructor(octokit: Octokit, repository: Repository, branch: string); /** * Fetch file contents for given path. If the data has already been * fetched, return the cached copy. * * @param {string} path Path to the file * @param {string} branch Branch to fetch the file from * @returns {GitHubFileContents} The file contents */ getFileContents(path: string): Promise; /** * Find all files with a given filename. * * @param {string} filename The filename of the files to search for. * @param {string} pathPrefix If set, limit results to files that begin * with this path prefix. Also if set, returns the path relative to * the path prefix. * @returns {string[]} Paths to the files (relative to path prefix) */ findFilesByFilename(filename: string, pathPrefix?: string): Promise; /** * Find all files with a given file extension. * * @param {string} filename The file extension (excluding `.`) of the * files to search for. Example: `yaml`. * @param {string} pathPrefix If set, limit results to files that begin * with this path prefix. Also if set, returns the path relative to * the path prefix. * @returns {string[]} Paths to the files (relative to path prefix) */ findFilesByExtension(extension: string, pathPrefix?: string): Promise; /** * Find all files matching a given glob. * * @param {string} glob The glob to match. * @param {string} pathPrefix If set, limit results to files that begin * with this path prefix. Also if set, returns the path relative to * the path prefix. * @returns {string[]} Paths to the files (relative to path prefix) */ findFilesByGlob(glob: string, pathPrefix?: string): Promise; /** * Actually fetch the file contents. Uses the tree API to fetch file * data. * * @param {string} path Path to the file */ private fetchFileContents; /** * Return the full recursive git tree. If already fetched, return * the cached version. If the tree is too big, return null. * * @returns {TreeEntry[]} The tree entries */ private getFullTree; /** * Returns the git tree for a given SHA. If already fetched, return * the cached version. If possible, return the entire contents of the * (sub)tree. This will limit the number * * @param {string} sha The tree SHA * @returns {CachedTree} The tree entries and whether the subtree response * was complete or not (recursive: true means that we have all the files) */ private getTree; /** * Fetch the git tree via the GitHub API * * @param {string} sha The tree SHA * @param {boolean} recursive Whether to make a recursive call or not * @returns {TreeResponse} The tree response */ private fetchTree; /** * Async iterator for iterating over all files in the repository. * * @param {string} ref The starting git tree reference. Can be a tree SHA or * a branch reference. * @param {string} pathPrefix If set, limit results to files that begin * with this path prefix. */ private treeEntryIterator; /** * Fetch the git blob from the GitHub API and convert into a * GitHubFileContents object. * * @param {string} blobSha The git blob SHA * @param {TreeEntry} treeEntry The associated tree object */ private fetchContents; }