UNPKG

8.16 kBTypeScriptView Raw
1import { Octokit, RestEndpointMethodTypes } from "@octokit/rest";
2import { HttpsProxyAgent } from "https-proxy-agent";
3import { ILabelDefinition } from "./release";
4import { ILogger } from "./utils/logger";
5import { ICommit } from "./log-parse";
6declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> & Partial<Pick<T, K>>;
7export declare type IPRInfo = Omit<RestEndpointMethodTypes["repos"]["createCommitStatus"]["parameters"], "owner" | "repo">;
8export interface IGitOptions {
9 /** Github repo owner (user) */
10 owner: string;
11 /** GitHub project to operate on */
12 repo: string;
13 /** The URL to the GitHub (public or enterprise) the project is using */
14 baseUrl?: string;
15 /** The main branch of the repo. Usually master */
16 baseBranch: string;
17 /** The URL to the GitHub graphql API (public or enterprise) the project is using */
18 graphqlBaseUrl?: string;
19 /** A token to auth to GitHub with */
20 token?: string;
21 /** An optional proxy agent to route requests through */
22 agent?: HttpsProxyAgent;
23}
24export declare const automatedCommentIdentifier = "<!-- GITHUB_RELEASE";
25/**
26 * A class to interact with the local git instance and the git remote.
27 * currently it only interfaces with GitHub.
28 */
29export default class Git {
30 /** An octokit instance to use to interact with GitHub */
31 readonly github: Octokit;
32 /** Options the git client was initialized with */
33 readonly options: IGitOptions;
34 /** The GitHub api to communicate with through octokit */
35 private readonly baseUrl;
36 /** The GitHub graphql api to communicate with through octokit */
37 private readonly graphqlBaseUrl;
38 /** A logger that uses log levels */
39 private readonly logger;
40 /** Initialize the git interface and auth with GitHub */
41 constructor(options: IGitOptions, logger?: ILogger);
42 /** Verify the write access authorization to remote repository with push dry-run. */
43 verifyAuth(url: string): Promise<boolean>;
44 /** Get the "Latest Release" from GitHub */
45 getLatestReleaseInfo(): Promise<import("@octokit/types").ReposGetLatestReleaseResponseData>;
46 /** Get the "Latest Release" or the first commit SHA as a fallback */
47 getLatestRelease(): Promise<string>;
48 /** Get the date a commit sha was created */
49 getCommitDate(sha: string): Promise<string>;
50 /** Get the first commit for the repo */
51 getFirstCommit(): Promise<string>;
52 /** Get the SHA of the latest commit */
53 getSha(short?: boolean): Promise<string>;
54 /** Get the SHA of the latest commit */
55 shaExists(sha?: string): Promise<boolean>;
56 /** Get the labels for a PR */
57 getLabels(prNumber: number): Promise<string[]>;
58 /** Get all the information about a PR or issue */
59 getPr(prNumber: number): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesGetResponseData>>;
60 /** Get information about specific commit */
61 getCommit(sha: string): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").ReposGetCommitResponseData>>;
62 /** Get the labels for a the project */
63 getProjectLabels(): Promise<string[]>;
64 /** Get the git log for a range of commits */
65 getGitLog(start: string, end?: string): Promise<ICommit[]>;
66 /** Get the GitHub user for an email. Will not work if they do not have their email set to "public". */
67 getUserByEmail(email: string): Promise<{} | undefined>;
68 /** Get collaborator permission level to the repo. */
69 getTokenPermissionLevel(): Promise<{
70 permission: string;
71 user?: undefined;
72 } | {
73 permission: string;
74 user: import("@octokit/types").UsersGetAuthenticatedResponseData;
75 }>;
76 /** Get the GitHub user for a username */
77 getUserByUsername(username: string): Promise<import("@octokit/types").UsersGetByUsernameResponseData | undefined>;
78 /** Get all the information about a PR or issue */
79 getPullRequest(pr: number): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").PullsGetResponseData>>;
80 /** Search to GitHub project's issue and pull requests */
81 searchRepo(options: RestEndpointMethodTypes["search"]["issuesAndPullRequests"]["parameters"]): Promise<import("@octokit/types").SearchIssuesAndPullRequestsResponseData>;
82 /** Run a graphql query on the GitHub project */
83 graphql<T>(query: string): Promise<T>;
84 /** Create a status (or checkmark) on a commit */
85 createStatus(prInfo: IPRInfo): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").ReposCreateCommitStatusResponseData>>;
86 /** Add a label to the project */
87 createLabel(label: ILabelDefinition): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesCreateLabelResponseData>>;
88 /** Update a label on the project */
89 updateLabel(label: ILabelDefinition): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesUpdateLabelResponseData>>;
90 /** Add a label to and issue or pull request */
91 addLabelToPr(pr: number, label: string): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesAddLabelsResponseData>>;
92 /** Add a label to and issue or pull request */
93 removeLabel(pr: number, label: string): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesRemoveLabelResponseData>>;
94 /** Lock an issue */
95 lockIssue(issue: number): Promise<import("@octokit/types").OctokitResponse<any>>;
96 /** Get information about the GitHub project */
97 getProject(): Promise<import("@octokit/types").ReposGetResponseData>;
98 /** Get all the pull requests for a project */
99 getPullRequests(options?: Partial<RestEndpointMethodTypes["pulls"]["list"]["parameters"]>): Promise<import("@octokit/types").PullsListResponseData>;
100 /** Get all the commits for a PR */
101 getCommitsForPR(pr: number): Promise<import("@octokit/types").PullsListCommitsResponseData>;
102 /** Find a comment that is using the context in a PR */
103 getCommentId(pr: number, context?: string): Promise<number>;
104 /** Delete a comment on an issue or pull request */
105 deleteComment(pr: number, context?: string): Promise<void>;
106 /** Create a comment on an issue or pull request */
107 createComment(message: string, pr: number, context?: string): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesCreateCommentResponseData>>;
108 /** Edit a comment on an issue or pull request */
109 editComment(message: string, pr: number, context?: string): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesUpdateCommentResponseData>>;
110 /** Create a comment on a pull request body */
111 addToPrBody(message: string, pr: number, context?: string): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").IssuesUpdateResponseData>>;
112 /** Create a release for the GitHub project */
113 publish(releaseNotes: string, tag: string, prerelease?: boolean): Promise<import("@octokit/types").OctokitResponse<import("@octokit/types").ReposCreateReleaseResponseData>>;
114 /** Get the latest tag in the git tree */
115 getLatestTagInBranch(since?: string): Promise<string>;
116 /** Get the tag before latest in the git tree */
117 getPreviousTagInBranch(): Promise<string>;
118 /** Get all the tags for a given branch. */
119 getTags(branch: string): Promise<string[]>;
120 /** Get the a tag that isn't in the base branch */
121 getTagNotInBaseBranch(branch: string, options?: {
122 /** Return the first tag not in baseBrach, defaults to last tag. */
123 first?: boolean;
124 }): Promise<string | undefined>;
125 /** Get the last tag that isn't in the base branch */
126 getLastTagNotInBaseBranch(branch: string): Promise<string | undefined>;
127 /** Determine the pull request for a commit hash */
128 matchCommitToPr(sha: string): Promise<{
129 labels: string[];
130 number: number;
131 state: "MERGED" | "CLOSED" | "OPEN";
132 body: string;
133 headRefName: string;
134 headRepositoryOwner: {
135 login: string;
136 };
137 } | undefined>;
138}
139export {};
140//# sourceMappingURL=git.d.ts.map
\No newline at end of file