import { Octokit, RestEndpointMethodTypes } from "@octokit/rest"; import { HttpsProxyAgent } from "https-proxy-agent"; import { ILabelDefinition } from "./release"; import { ILogger } from "./utils/logger"; import { ICommit } from "./log-parse"; declare type Omit = Pick> & Partial>; export declare type IPRInfo = Omit; export interface IGitOptions { /** Github repo owner (user) */ owner: string; /** GitHub project to operate on */ repo: string; /** The URL to the GitHub (public or enterprise) the project is using */ baseUrl?: string; /** The main branch of the repo. Usually master */ baseBranch: string; /** The URL to the GitHub graphql API (public or enterprise) the project is using */ graphqlBaseUrl?: string; /** A token to auth to GitHub with */ token?: string; /** An optional proxy agent to route requests through */ agent?: HttpsProxyAgent; } /** * A class to interact with the local git instance and the git remote. * currently it only interfaces with GitHub. */ export default class Git { /** An octokit instance to use to interact with GitHub */ readonly github: Octokit; /** Options the git client was initialized with */ readonly options: IGitOptions; /** The GitHub api to communicate with through octokit */ private readonly baseUrl; /** The GitHub graphql api to communicate with through octokit */ private readonly graphqlBaseUrl; /** A logger that uses log levels */ private readonly logger; /** Initialize the git interface and auth with GitHub */ constructor(options: IGitOptions, logger?: ILogger); /** Verify the write access authorization to remote repository with push dry-run. */ verifyAuth(url: string): Promise; /** Get the "Latest Release" from GitHub */ getLatestReleaseInfo(): Promise<{ url: string; html_url: string; assets_url: string; upload_url: string; tarball_url: string; zipball_url: string; id: number; node_id: string; tag_name: string; target_commitish: string; name: string; body: string; draft: boolean; prerelease: boolean; created_at: string; published_at: string; author: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; assets: { url: string; browser_download_url: string; id: number; node_id: string; name: string; label: string; state: string; content_type: string; size: number; download_count: number; created_at: string; updated_at: string; uploader: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; }[]; }>; /** Get the "Latest Release" or the first commit SHA as a fallback */ getLatestRelease(): Promise; /** Get the date a commit sha was created */ getCommitDate(sha: string): Promise; /** Get the first commit for the repo */ getFirstCommit(): Promise; /** Get the SHA of the latest commit */ getSha(short?: boolean): Promise; /** Get the SHA of the latest commit */ shaExists(sha?: string): Promise; /** Get the labels for a PR */ getLabels(prNumber: number): Promise; /** Get all the information about a PR or issue */ getPr(prNumber: number): Promise>; /** Get information about specific commit */ getCommit(sha: string): Promise>; /** Get the labels for a the project */ getProjectLabels(): Promise; /** Get the git log for a range of commits */ getGitLog(start: string, end?: string): Promise; /** Get the GitHub user for an email. Will not work if they do not have their email set to "public". */ getUserByEmail(email: string): Promise<{} | undefined>; /** Get collaborator permission level to the repo. */ getTokenPermissionLevel(): Promise<{ permission: string; user?: undefined; } | { permission: string; user: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; name: string; company: string; blog: string; location: string; email: string; hireable: boolean; bio: string; public_repos: number; public_gists: number; followers: number; following: number; created_at: string; updated_at: string; private_gists?: number | undefined; total_private_repos?: number | undefined; owned_private_repos?: number | undefined; disk_usage?: number | undefined; collaborators?: number | undefined; two_factor_authentication?: boolean | undefined; plan?: { name: string; space: number; private_repos: number; collaborators: number; } | undefined; }; }>; /** Get the GitHub user for a username */ getUserByUsername(username: string): Promise<{ login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; name: string; company: string; blog: string; location: string; email: string; hireable: boolean; bio: string; public_repos: number; public_gists: number; followers: number; following: number; created_at: string; updated_at: string; plan?: { name: string; space: number; collaborators: number; private_repos: number; } | undefined; } | undefined>; /** Get all the information about a PR or issue */ getPullRequest(pr: number): Promise>; /** Search to GitHub project's issue and pull requests */ searchRepo(options: RestEndpointMethodTypes["search"]["issuesAndPullRequests"]["parameters"]): Promise<{ total_count: number; incomplete_results: boolean; items: { url: string; repository_url: string; labels_url: string; comments_url: string; events_url: string; html_url: string; id: number; node_id: string; number: number; title: string; user: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; }; labels: { id: number; node_id: string; url: string; name: string; color: string; }[]; state: string; assignee: null; milestone: null; comments: number; created_at: string; updated_at: string; closed_at: null; pull_request: { html_url: null; diff_url: null; patch_url: null; }; body: string; score: number; }[]; }>; /** Run a graphql query on the GitHub project */ graphql(query: string): Promise; /** Create a status (or checkmark) on a commit */ createStatus(prInfo: IPRInfo): Promise>; /** Add a label to the project */ createLabel(label: ILabelDefinition): Promise>; /** Update a label on the project */ updateLabel(label: ILabelDefinition): Promise>; /** Add a label to and issue or pull request */ addLabelToPr(pr: number, label: string): Promise>; /** Add a label to and issue or pull request */ removeLabel(pr: number, label: string): Promise>; /** Lock an issue */ lockIssue(issue: number): Promise>; /** Get information about the GitHub project */ getProject(): Promise<{ id: number; node_id: string; name: string; full_name: string; owner: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; private: boolean; html_url: string; description: string | null; fork: boolean; url: string; archive_url: string; assignees_url: string; blobs_url: string; branches_url: string; collaborators_url: string; comments_url: string; commits_url: string; compare_url: string; contents_url: string; contributors_url: string; deployments_url: string; downloads_url: string; events_url: string; forks_url: string; git_commits_url: string; git_refs_url: string; git_tags_url: string; git_url: string; issue_comment_url: string; issue_events_url: string; issues_url: string; keys_url: string; labels_url: string; languages_url: string; merges_url: string; milestones_url: string; notifications_url: string; pulls_url: string; releases_url: string; ssh_url: string; stargazers_url: string; statuses_url: string; subscribers_url: string; subscription_url: string; tags_url: string; teams_url: string; trees_url: string; clone_url: string; mirror_url: string | null; hooks_url: string; svn_url: string; homepage: string | null; language: null; forks_count: number; stargazers_count: number; watchers_count: number; size: number; default_branch: string; open_issues_count: number; is_template?: boolean | undefined; topics?: string[] | undefined; has_issues: boolean; has_projects: boolean; has_wiki: boolean; has_pages: boolean; has_downloads: boolean; archived?: boolean | undefined; disabled?: boolean | undefined; visibility?: string | undefined; pushed_at: string; created_at: string; updated_at: string; permissions?: { pull: boolean; triage: boolean; push: boolean; maintain: boolean; admin: boolean; } | undefined; allow_rebase_merge?: boolean | undefined; template_repository?: null | undefined; temp_clone_token?: string | undefined; allow_squash_merge?: boolean | undefined; allow_merge_commit?: boolean | undefined; subscribers_count: number; network_count: number; license?: { key: string; name: string; spdx_id: string; url: string; node_id: string; } | undefined; organization?: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; } | undefined; parent?: { id: number; node_id: string; name: string; full_name: string; owner: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; private: boolean; html_url: string; description: string; fork: boolean; url: string; archive_url: string; assignees_url: string; blobs_url: string; branches_url: string; collaborators_url: string; comments_url: string; commits_url: string; compare_url: string; contents_url: string; contributors_url: string; deployments_url: string; downloads_url: string; events_url: string; forks_url: string; git_commits_url: string; git_refs_url: string; git_tags_url: string; git_url: string; issue_comment_url: string; issue_events_url: string; issues_url: string; keys_url: string; labels_url: string; languages_url: string; merges_url: string; milestones_url: string; notifications_url: string; pulls_url: string; releases_url: string; ssh_url: string; stargazers_url: string; statuses_url: string; subscribers_url: string; subscription_url: string; tags_url: string; teams_url: string; trees_url: string; clone_url: string; mirror_url: string; hooks_url: string; svn_url: string; homepage: string; language: null; forks_count: number; stargazers_count: number; watchers_count: number; size: number; default_branch: string; open_issues_count: number; is_template: boolean; topics: string[]; has_issues: boolean; has_projects: boolean; has_wiki: boolean; has_pages: boolean; has_downloads: boolean; archived: boolean; disabled: boolean; visibility: string; pushed_at: string; created_at: string; updated_at: string; permissions: { admin: boolean; push: boolean; pull: boolean; }; allow_rebase_merge: boolean; template_repository: null; temp_clone_token: string; allow_squash_merge: boolean; allow_merge_commit: boolean; subscribers_count: number; network_count: number; } | undefined; source?: { id: number; node_id: string; name: string; full_name: string; owner: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; private: boolean; html_url: string; description: string; fork: boolean; url: string; archive_url: string; assignees_url: string; blobs_url: string; branches_url: string; collaborators_url: string; comments_url: string; commits_url: string; compare_url: string; contents_url: string; contributors_url: string; deployments_url: string; downloads_url: string; events_url: string; forks_url: string; git_commits_url: string; git_refs_url: string; git_tags_url: string; git_url: string; issue_comment_url: string; issue_events_url: string; issues_url: string; keys_url: string; labels_url: string; languages_url: string; merges_url: string; milestones_url: string; notifications_url: string; pulls_url: string; releases_url: string; ssh_url: string; stargazers_url: string; statuses_url: string; subscribers_url: string; subscription_url: string; tags_url: string; teams_url: string; trees_url: string; clone_url: string; mirror_url: string; hooks_url: string; svn_url: string; homepage: string; language: null; forks_count: number; stargazers_count: number; watchers_count: number; size: number; default_branch: string; open_issues_count: number; is_template: boolean; topics: string[]; has_issues: boolean; has_projects: boolean; has_wiki: boolean; has_pages: boolean; has_downloads: boolean; archived: boolean; disabled: boolean; visibility: string; pushed_at: string; created_at: string; updated_at: string; permissions: { admin: boolean; push: boolean; pull: boolean; }; allow_rebase_merge: boolean; template_repository: null; temp_clone_token: string; allow_squash_merge: boolean; allow_merge_commit: boolean; subscribers_count: number; network_count: number; } | undefined; forks?: number | undefined; open_issues?: number | undefined; watchers?: number | undefined; code_of_conduct?: { key: string; name: string; url: string; } | undefined; }>; /** Get all the pull requests for a project */ getPullRequests(options?: Partial): Promise<{ url: string; id: number; node_id: string; html_url: string; diff_url: string; patch_url: string; issue_url: string; commits_url: string; review_comments_url: string; review_comment_url: string; comments_url: string; statuses_url: string; number: number; state: string; locked: boolean; title: string; user: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; body: string; labels: { id: number; node_id: string; url: string; name: string; description: string; color: string; default: boolean; }[]; milestone: { url: string; html_url: string; labels_url: string; id: number; node_id: string; number: number; state: string; title: string; description: string; creator: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; open_issues: number; closed_issues: number; created_at: string; updated_at: string; closed_at: string; due_on: string; }; active_lock_reason: string; created_at: string; updated_at: string; closed_at: string; merged_at: string; merge_commit_sha: string; assignee: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; assignees: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }[]; requested_reviewers: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }[]; requested_teams: { id: number; node_id: string; url: string; html_url: string; name: string; slug: string; description: string; privacy: string; permission: string; members_url: string; repositories_url: string; parent: null; }[]; head: { label: string; ref: string; sha: string; user: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; repo: { id: number; node_id: string; name: string; full_name: string; owner: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; private: boolean; html_url: string; description: string; fork: boolean; url: string; archive_url: string; assignees_url: string; blobs_url: string; branches_url: string; collaborators_url: string; comments_url: string; commits_url: string; compare_url: string; contents_url: string; contributors_url: string; deployments_url: string; downloads_url: string; events_url: string; forks_url: string; git_commits_url: string; git_refs_url: string; git_tags_url: string; git_url: string; issue_comment_url: string; issue_events_url: string; issues_url: string; keys_url: string; labels_url: string; languages_url: string; merges_url: string; milestones_url: string; notifications_url: string; pulls_url: string; releases_url: string; ssh_url: string; stargazers_url: string; statuses_url: string; subscribers_url: string; subscription_url: string; tags_url: string; teams_url: string; trees_url: string; clone_url: string; mirror_url: string; hooks_url: string; svn_url: string; homepage: string; language: null; forks_count: number; stargazers_count: number; watchers_count: number; size: number; default_branch: string; open_issues_count: number; is_template: boolean; topics: string[]; has_issues: boolean; has_projects: boolean; has_wiki: boolean; has_pages: boolean; has_downloads: boolean; archived: boolean; disabled: boolean; visibility: string; pushed_at: string; created_at: string; updated_at: string; permissions: { admin: boolean; push: boolean; pull: boolean; }; allow_rebase_merge: boolean; template_repository: null; temp_clone_token: string; allow_squash_merge: boolean; allow_merge_commit: boolean; subscribers_count: number; network_count: number; }; }; base: { label: string; ref: string; sha: string; user: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; repo: { id: number; node_id: string; name: string; full_name: string; owner: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; private: boolean; html_url: string; description: string; fork: boolean; url: string; archive_url: string; assignees_url: string; blobs_url: string; branches_url: string; collaborators_url: string; comments_url: string; commits_url: string; compare_url: string; contents_url: string; contributors_url: string; deployments_url: string; downloads_url: string; events_url: string; forks_url: string; git_commits_url: string; git_refs_url: string; git_tags_url: string; git_url: string; issue_comment_url: string; issue_events_url: string; issues_url: string; keys_url: string; labels_url: string; languages_url: string; merges_url: string; milestones_url: string; notifications_url: string; pulls_url: string; releases_url: string; ssh_url: string; stargazers_url: string; statuses_url: string; subscribers_url: string; subscription_url: string; tags_url: string; teams_url: string; trees_url: string; clone_url: string; mirror_url: string; hooks_url: string; svn_url: string; homepage: string; language: null; forks_count: number; stargazers_count: number; watchers_count: number; size: number; default_branch: string; open_issues_count: number; is_template: boolean; topics: string[]; has_issues: boolean; has_projects: boolean; has_wiki: boolean; has_pages: boolean; has_downloads: boolean; archived: boolean; disabled: boolean; visibility: string; pushed_at: string; created_at: string; updated_at: string; permissions: { admin: boolean; push: boolean; pull: boolean; }; allow_rebase_merge: boolean; template_repository: null; temp_clone_token: string; allow_squash_merge: boolean; allow_merge_commit: boolean; subscribers_count: number; network_count: number; }; }; _links: { self: { href: string; }; html: { href: string; }; issue: { href: string; }; comments: { href: string; }; review_comments: { href: string; }; review_comment: { href: string; }; commits: { href: string; }; statuses: { href: string; }; }; author_association: string; draft: boolean; }[]>; /** Get all the commits for a PR */ getCommitsForPR(pr: number): Promise<{ url: string; sha: string; node_id: string; html_url: string; comments_url: string; commit: { url: string; author: { name: string; email: string; date: string; }; committer: { name: string; email: string; date: string; }; message: string; tree: { url: string; sha: string; }; comment_count: number; verification: { verified: boolean; reason: string; signature: null; payload: null; }; }; author: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; committer: { login: string; id: number; node_id: string; avatar_url: string; gravatar_id: string; url: string; html_url: string; followers_url: string; following_url: string; gists_url: string; starred_url: string; subscriptions_url: string; organizations_url: string; repos_url: string; events_url: string; received_events_url: string; type: string; site_admin: boolean; }; parents: { url: string; sha: string; }[]; }[]>; /** Find a comment that is using the context in a PR */ getCommentId(pr: number, context?: string): Promise; /** Delete a comment on an issue or pull request */ deleteComment(pr: number, context?: string): Promise; /** Create a comment on an issue or pull request */ createComment(message: string, pr: number, context?: string): Promise>; /** Edit a comment on an issue or pull request */ editComment(message: string, pr: number, context?: string): Promise>; /** Create a comment on a pull request body */ addToPrBody(message: string, pr: number, context?: string): Promise>; /** Create a release for the GitHub projecct */ publish(releaseNotes: string, tag: string, prerelease?: boolean): Promise>; /** Get the latest tag in the git tree */ getLatestTagInBranch(since?: string): Promise; /** Get the tag before latest in the git tree */ getPreviousTagInBranch(): Promise; /** Get all the tags for a given branch. */ getTags(branch: string): Promise; /** Get the a tag that isn't in the base branch */ getTagNotInBaseBranch(branch: string, options?: { /** Return the first tag not in baseBrach, defaults to last tag. */ first?: boolean; }): Promise; /** Get the last tag that isn't in the base branch */ getLastTagNotInBaseBranch(branch: string): Promise; /** Determine the pull request for a commit hash */ matchCommitToPr(sha: string): Promise<{ labels: string[]; number: number; state: "MERGED" | "CLOSED" | "OPEN"; body: string; headRefName: string; headRepositoryOwner: { login: string; }; } | undefined>; } export {}; //# sourceMappingURL=git.d.ts.map