UNPKG

code-suggester

Version:
87 lines (86 loc) 4.08 kB
import { FileDiffContent, RepoDomain, Hunk } from '../types'; import { Octokit } from '@octokit/rest'; /** * Build an error message based on invalid hunks. * Returns an empty string if the provided hunks are empty. * @param invalidHunks a map of filename to hunks that are not suggestable */ export declare function buildSummaryComment(invalidHunks: Map<string, Hunk[]>): string; /** * Multiline comment GitHub API parameters * For more information see * https://developer.github.com/v3/pulls/comments/#create-a-review-comment-for-a-pull-request */ interface MultilineComment { body: string; path: string; start_line: number; line: number; side: 'RIGHT' | 'LEFT'; start_side: 'RIGHT' | 'LEFT'; } interface SingleLineComment { body: string; path: string; line: number; side: 'RIGHT' | 'LEFT'; } type Comment = SingleLineComment | MultilineComment; /** * GitHub-defined type. The Octokit library/docs are probably behind since create review already * accept multi-line code comments. However, the API does not reflect that. */ export type PullsCreateReviewParamsComments = { path: string; position: number; body: string; }; /** * Convert the patch suggestions into GitHub parameter objects. * Use this to generate review comments * For information see: * https://developer.github.com/v3/pulls/comments/#create-a-review-comment-for-a-pull-request * @param suggestions */ export declare function buildReviewComments(suggestions: Map<string, Hunk[]>): Comment[]; /** * Make a request to GitHub to make review comments * @param octokit an authenticated octokit instance * @param suggestions code suggestions patches * @param remote the repository domain * @param pullNumber the pull request number to make a review on */ export declare function makeInlineSuggestions(octokit: Octokit, suggestions: Map<string, Hunk[]>, outOfScopeSuggestions: Map<string, Hunk[]>, remote: RepoDomain, pullNumber: number): Promise<number | null>; /** * Comment on a Pull Request * @param {Octokit} octokit authenticated octokit isntance * @param {RepoDomain} remote the Pull Request repository * @param {number} pullNumber the Pull Request number * @param {number} pageSize the number of files to comment on // TODO pagination * @param {Map<string, FileDiffContent>} diffContents the old and new contents of the files to suggest * @returns the created review's id, or null if no review was made */ export declare function createPullRequestReview(octokit: Octokit, remote: RepoDomain, pullNumber: number, pageSize: number, diffContents: Map<string, FileDiffContent> | string): Promise<number | null>; /** * For a pull request, get each remote file's patch text asynchronously * Also get the list of files whose patch data could not be returned * @param {Octokit} octokit the authenticated octokit instance * @param {RepoDomain} remote the remote repository domain information * @param {number} pullNumber the pull request number * @param {number} pageSize the number of results to return per page * @returns {Promise<Object<PatchText, string[]>>} the stringified patch data for each file and the list of files whose patch data could not be resolved */ export declare function getCurrentPullRequestPatches(octokit: Octokit, remote: RepoDomain, pullNumber: number, pageSize: number): Promise<{ patches: Map<string, string>; filesMissingPatch: string[]; }>; /** * For a pull request, get each remote file's current patch range to identify the scope of each patch as a Map. * @param {Octokit} octokit the authenticated octokit instance * @param {RepoDomain} remote the remote repository domain information * @param {number} pullNumber the pull request number * @param {number} pageSize the number of files to return per pull request list files query * @returns {Promise<Map<string, Hunk[]>>} the scope of each file in the pull request */ export declare function getPullRequestHunks(octokit: Octokit, remote: RepoDomain, pullNumber: number, pageSize: number): Promise<Map<string, Hunk[]>>; export {};