/// import { PreviewState } from '@staticcms/core/constants/enums'; import { WorkflowStatus } from '@staticcms/core/constants/publishModes'; import { PullRequestState } from './types'; import type { AuthScheme, DataFile, PersistOptions, UnpublishedEntry } from '@staticcms/core'; import type { ApiRequest, FetchError } from '@staticcms/core/lib/util'; import type AssetProxy from '@staticcms/core/valueObjects/AssetProxy'; import type { Semaphore } from 'semaphore'; import type { GitCreateCommitResponse, GitCreateRefResponse, GitCreateTreeParamsTree, GitCreateTreeResponse, GitHubAuthor, GitHubCommitter, GitHubCompareCommit, GitHubCompareCommits, GitHubPull, GitHubUser, GitListMatchingRefsResponseItem, GitUpdateRefResponse, PullsCreateResponse, PullsMergeResponse, PullsUpdateBranchResponse, ReposCompareCommitsResponse, ReposCompareCommitsResponseFilesItem, ReposGetBranchResponse, TreeFile } from './types'; export declare const API_NAME = "GitHub"; export declare const MOCK_PULL_REQUEST = -1; export interface Config { apiRoot?: string; token?: string; authScheme?: AuthScheme; branch?: string; useOpenAuthoring?: boolean; openAuthoringEnabled?: boolean; repo?: string; originRepo?: string; squashMerges: boolean; initialWorkflowStatus: WorkflowStatus; cmsLabelPrefix: string; } type Override = Pick> & U; type TreeEntry = Override; interface MetaDataObjects { entry: { path: string; sha: string; }; files: MediaFile[]; } export interface Metadata { type: string; objects: MetaDataObjects; branch: string; status: string; collection: string; commitMessage: string; version?: string; user: string; title?: string; description?: string; timeStamp: string; } export interface BlobArgs { sha: string; repoURL: string; parseText: boolean; } type Param = string | number | undefined; export type Options = RequestInit & { params?: Record | string[]>; }; type MediaFile = { sha: string; path: string; }; export type Diff = { path: string; newFile: boolean; sha: string; binary: boolean; }; export default class API { apiRoot: string; token: string; authScheme: AuthScheme; branch: string; useOpenAuthoring?: boolean; openAuthoringEnabled?: boolean; repo: string; originRepo: string; repoOwner: string; repoName: string; originRepoOwner: string; originRepoName: string; repoURL: string; originRepoURL: string; mergeMethod: string; initialWorkflowStatus: WorkflowStatus; cmsLabelPrefix: string; _userPromise?: Promise; _metadataSemaphore?: Semaphore; commitAuthor?: {}; constructor(config: Config); static DEFAULT_COMMIT_MESSAGE: string; user(): Promise<{ name: string; login: string; }>; getUser(): Promise; hasWriteAccess(): Promise; reset(): void; requestHeaders(headers?: {}): Promise>; parseJsonResponse(response: Response): Promise; urlFor(path: string, options: Options): string; parseResponse(response: Response): Promise; handleRequestError(error: FetchError, responseStatus: number): void; buildRequest(req: ApiRequest): ApiRequest; request(path: string, options?: Options, parser?: (response: Response) => Promise): Promise; nextUrlProcessor(): (url: string) => string; requestAllPages(url: string, options?: Options): Promise; generateContentKey(collectionName: string, slug: string): string; getContentKeySlug(contentKey: string): string; parseContentKey(contentKey: string): { collection: string; slug: string; }; readFile(path: string, sha?: string | null, { branch, repoURL, parseText, }?: { branch?: string; repoURL?: string; parseText?: boolean; }): Promise; readFileMetadata(path: string, sha: string | null | undefined): Promise; fetchBlobContent({ sha, repoURL, parseText }: BlobArgs): Promise; listFiles(path: string, { repoURL, branch, depth }?: { repoURL?: string | undefined; branch?: string | undefined; depth?: number | undefined; }, folderSupport?: boolean): Promise<{ type: string; id: string; name: string; path: string; size: number; }[]>; persistFiles(dataFiles: DataFile[], mediaFiles: AssetProxy[], options: PersistOptions): Promise; getFileSha(path: string, { repoURL, branch }?: { repoURL?: string | undefined; branch?: string | undefined; }): Promise; deleteFiles(paths: string[], message: string): Promise; createRef(type: string, name: string, sha: string): Promise; patchRef(type: string, name: string, sha: string, opts?: { force?: boolean; }): Promise; deleteRef(type: string, name: string): Promise; getDefaultBranch(): Promise; assertCmsBranch(branchName: string): boolean; patchBranch(branchName: string, sha: string, opts?: { force?: boolean; }): Promise; getHeadReference(head: string): Promise; toBase64(str: string): Promise; uploadBlob(item: { raw?: string; sha?: string; toBase64?: () => Promise; }): Promise<{ raw?: string | undefined; sha?: string | undefined; toBase64?: (() => Promise) | undefined; }>; updateTree(baseSha: string, files: { path: string; sha: string | null; newPath?: string; }[], branch?: string): Promise<{ parentSha: string; sha: string; tree: { mode: string; path: string; sha: string; size: number; type: string; url: string; }[]; url: string; }>; createTree(baseSha: string, tree: TreeEntry[]): Promise; commit(message: string, changeTree: { parentSha?: string; sha: string; }): Promise; createCommit(message: string, treeSha: string, parents: string[], author?: GitHubAuthor, committer?: GitHubCommitter): Promise; /** * Editorial Workflow */ listUnpublishedBranches(): Promise; getOpenAuthoringBranches(): Promise; filterOpenAuthoringBranches: (branch: string) => Promise<{ branch: string; filter: boolean; }>; getPullRequests(head: string | undefined, state: PullRequestState, predicate: (pr: GitHubPull) => boolean): Promise; deleteBranch(branchName: string): Promise; getBranchPullRequest(branch: string): Promise; getOpenAuthoringPullRequest(branch: string, pullRequests: GitHubPull[]): Promise; getBranch(branch: string): Promise; retrieveUnpublishedEntryData(contentKey: string): Promise; getDifferences(from: string, to: string): Promise; getPullRequestAuthor(pullRequest: GitHubPull): Promise; diffFromFile(diff: ReposCompareCommitsResponseFilesItem): Promise; publishUnpublishedEntry(collectionName: string, slug: string): Promise; mergePR(pullrequest: GitHubPull): Promise; forceMergePR(pullRequest: GitHubPull): Promise; deleteUnpublishedEntry(collectionName: string, slug: string): Promise; closePR(number: number): Promise; updatePullRequestLabels(number: number, labels: string[]): Promise; setPullRequestStatus(pullRequest: GitHubPull, newStatus: WorkflowStatus): Promise; createPR(title: string, head: string): Promise; openPR(number: number): Promise; updateUnpublishedEntryStatus(collectionName: string, slug: string, newStatus: WorkflowStatus): Promise; /** * Retrieve statuses for a given SHA. Unrelated to the editorial workflow * concept of entry "status". Useful for things like deploy preview links. */ getStatuses(collectionName: string, slug: string): Promise<{ context: string; target_url: string; state: PreviewState; }[]>; editorialWorkflowGit(files: TreeFile[], slug: string, mediaFilesList: MediaFile[], options: PersistOptions): Promise; backupBranch(branchName: string): Promise; createBranch(branchName: string, sha: string): Promise; createBranchAndPullRequest(branchName: string, sha: string, commitMessage: string): Promise; /** * Rebase an array of commits one-by-one, starting from a given base SHA */ rebaseCommits(baseCommit: GitHubCompareCommit, commits: GitHubCompareCommits): Promise<{ author: { avatar_url: string; events_url: string; followers_url: string; following_url: string; gists_url: string; gravatar_id: string; html_url: string; id: number; login: string; node_id: string; organizations_url: string; received_events_url: string; repos_url: string; site_admin: boolean; starred_url: string; subscriptions_url: string; type: string; url: string; }; comments_url: string; commit: { author: { date: string; email: string; name: string; }; comment_count: number; committer: { date: string; email: string; name: string; }; message: string; tree: { sha: string; url: string; }; url: string; verification: { payload: null; reason: string; signature: null; verified: boolean; }; }; committer: { avatar_url: string; events_url: string; followers_url: string; following_url: string; gists_url: string; gravatar_id: string; html_url: string; id: number; login: string; node_id: string; organizations_url: string; received_events_url: string; repos_url: string; site_admin: boolean; starred_url: string; subscriptions_url: string; type: string; url: string; }; html_url: string; node_id: string; parents: { sha: string; url: string; }[]; sha: string; url: string; }>; rebaseSingleCommit(baseCommit: GitHubCompareCommit, commit: GitHubCompareCommit): Promise<{ author: { avatar_url: string; events_url: string; followers_url: string; following_url: string; gists_url: string; gravatar_id: string; html_url: string; id: number; login: string; node_id: string; organizations_url: string; received_events_url: string; repos_url: string; site_admin: boolean; starred_url: string; subscriptions_url: string; type: string; url: string; }; comments_url: string; commit: { author: { date: string; email: string; name: string; }; comment_count: number; committer: { date: string; email: string; name: string; }; message: string; tree: { sha: string; url: string; }; url: string; verification: { payload: null; reason: string; signature: null; verified: boolean; }; }; committer: { avatar_url: string; events_url: string; followers_url: string; following_url: string; gists_url: string; gravatar_id: string; html_url: string; id: number; login: string; node_id: string; organizations_url: string; received_events_url: string; repos_url: string; site_admin: boolean; starred_url: string; subscriptions_url: string; type: string; url: string; }; html_url: string; node_id: string; parents: { sha: string; url: string; }[]; sha: string; url: string; }>; rebaseBranch(branch: string): Promise<{ author: { avatar_url: string; events_url: string; followers_url: string; following_url: string; gists_url: string; gravatar_id: string; html_url: string; id: number; login: string; node_id: string; organizations_url: string; received_events_url: string; repos_url: string; site_admin: boolean; starred_url: string; subscriptions_url: string; type: string; url: string; }; comments_url: string; commit: { author: { date: string; email: string; name: string; }; comment_count: number; committer: { date: string; email: string; name: string; }; message: string; tree: { sha: string; url: string; }; url: string; verification: { payload: null; reason: string; signature: null; verified: boolean; }; }; committer: { avatar_url: string; events_url: string; followers_url: string; following_url: string; gists_url: string; gravatar_id: string; html_url: string; id: number; login: string; node_id: string; organizations_url: string; received_events_url: string; repos_url: string; site_admin: boolean; starred_url: string; subscriptions_url: string; type: string; url: string; }; html_url: string; node_id: string; parents: { sha: string; url: string; }[]; sha: string; url: string; }>; getUnpublishedEntrySha(collection: string, slug: string): Promise; } export {};