xref: /expo/tools/src/code-review/types.ts (revision af644ed4)
1import { GitFileDiff } from '../Git';
2import { PullRequest } from '../GitHub';
3
4/**
5 * See "Properties of the comments items" section on
6 * https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request
7 */
8export type ReviewComment = {
9  path: string;
10  position: number;
11  body: string;
12};
13
14/**
15 * The type representing a single pull request reviewer.
16 * An `action` is a function whose purpose is to check and review the diff.
17 */
18export type Reviewer = {
19  id: string;
20  action: (input: ReviewInput) => Promise<ReviewOutput | null>;
21};
22
23/**
24 * The result of code reviews that is being used to generate the final review comment/report.
25 */
26export type ReviewOutput = {
27  status: ReviewStatus;
28  title?: string;
29  body?: string;
30  comments?: ReviewComment[];
31};
32
33/**
34 * An input is an object that is passed to each code reviewer.
35 * It contains some data that are commonly used by all reviewers.
36 */
37export type ReviewInput = {
38  pullRequest: PullRequest;
39  diff: GitFileDiff[];
40};
41
42/**
43 * A status of the review output.
44 */
45export enum ReviewStatus {
46  /**
47   * Passive outputs are not included in the final report,
48   * but they may have some comments/suggestions which are not obligatory to apply.
49   */
50  PASSIVE = 1,
51
52  /**
53   * Warnings are included in the final report and are not obligatory to fix.
54   */
55  WARN = 2,
56
57  /**
58   * Errors are included in the final report and are obligatory to fix.
59   * It implies that the review will request for changes (will send `ReviewEvent.REQUEST_CHANGES` event).
60   */
61  ERROR = 3,
62}
63
64/**
65 * Review event that is sent during review creation/submission.
66 * The final review state depends on this event.
67 */
68export enum ReviewEvent {
69  COMMENT = 'COMMENT',
70  APPROVE = 'APPROVE',
71  REQUEST_CHANGES = 'REQUEST_CHANGES',
72}
73