xref: /expo/tools/src/code-review/types.ts (revision f657683d)
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  /**
10   * The relative path to the file that necessitates a comment.
11   */
12  path: string;
13  /**
14   * The position in the diff where you want to add a review comment.
15   * Note this value is not the same as the line number in the file.
16   * @deprecated Use `line` instead.
17   */
18  position?: number;
19  /**
20   * The line of the blob in the pull request diff that the comment applies to.
21   * For a multi-line comment, the last line of the range that your comment applies to.
22   */
23  line?: number;
24  /**
25   * The text of the review comment.
26   */
27  body: string;
28};
29
30/**
31 * The type representing a single pull request reviewer.
32 * An `action` is a function whose purpose is to check and review the diff.
33 */
34export type Reviewer = {
35  id: string;
36  action: (input: ReviewInput) => Promise<ReviewOutput | null>;
37};
38
39/**
40 * The result of code reviews that is being used to generate the final review comment/report.
41 */
42export type ReviewOutput = {
43  status: ReviewStatus;
44  title?: string;
45  body?: string;
46  comments?: ReviewComment[];
47};
48
49/**
50 * An input is an object that is passed to each code reviewer.
51 * It contains some data that are commonly used by all reviewers.
52 */
53export type ReviewInput = {
54  pullRequest: PullRequest;
55  diff: GitFileDiff[];
56};
57
58/**
59 * A status of the review output.
60 */
61export enum ReviewStatus {
62  /**
63   * Passive outputs are not included in the final report,
64   * but they may have some comments/suggestions which are not obligatory to apply.
65   */
66  PASSIVE = 1,
67
68  /**
69   * Warnings are included in the final report and are not obligatory to fix.
70   */
71  WARN = 2,
72
73  /**
74   * Errors are included in the final report and are obligatory to fix.
75   * It implies that the review will request for changes (will send `ReviewEvent.REQUEST_CHANGES` event).
76   */
77  ERROR = 3,
78}
79
80/**
81 * Review event that is sent during review creation/submission.
82 * The final review state depends on this event.
83 */
84export enum ReviewEvent {
85  COMMENT = 'COMMENT',
86  APPROVE = 'APPROVE',
87  REQUEST_CHANGES = 'REQUEST_CHANGES',
88}
89