143a76f73STomasz Sapetaimport { GitFileDiff } from '../Git'; 243a76f73STomasz Sapetaimport { PullRequest } from '../GitHub'; 343a76f73STomasz Sapeta 443a76f73STomasz Sapeta/** 543a76f73STomasz Sapeta * See "Properties of the comments items" section on 643a76f73STomasz Sapeta * https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request 743a76f73STomasz Sapeta */ 843a76f73STomasz Sapetaexport type ReviewComment = { 9*f657683dSTomasz Sapeta /** 10*f657683dSTomasz Sapeta * The relative path to the file that necessitates a comment. 11*f657683dSTomasz Sapeta */ 1243a76f73STomasz Sapeta path: string; 13*f657683dSTomasz Sapeta /** 14*f657683dSTomasz Sapeta * The position in the diff where you want to add a review comment. 15*f657683dSTomasz Sapeta * Note this value is not the same as the line number in the file. 16*f657683dSTomasz Sapeta * @deprecated Use `line` instead. 17*f657683dSTomasz Sapeta */ 18*f657683dSTomasz Sapeta position?: number; 19*f657683dSTomasz Sapeta /** 20*f657683dSTomasz Sapeta * The line of the blob in the pull request diff that the comment applies to. 21*f657683dSTomasz Sapeta * For a multi-line comment, the last line of the range that your comment applies to. 22*f657683dSTomasz Sapeta */ 23*f657683dSTomasz Sapeta line?: number; 24*f657683dSTomasz Sapeta /** 25*f657683dSTomasz Sapeta * The text of the review comment. 26*f657683dSTomasz Sapeta */ 2743a76f73STomasz Sapeta body: string; 2843a76f73STomasz Sapeta}; 2943a76f73STomasz Sapeta 3043a76f73STomasz Sapeta/** 31079c4431SBartłomiej Klocek * The type representing a single pull request reviewer. 32079c4431SBartłomiej Klocek * An `action` is a function whose purpose is to check and review the diff. 33079c4431SBartłomiej Klocek */ 34079c4431SBartłomiej Klocekexport type Reviewer = { 35079c4431SBartłomiej Klocek id: string; 36079c4431SBartłomiej Klocek action: (input: ReviewInput) => Promise<ReviewOutput | null>; 37079c4431SBartłomiej Klocek}; 38079c4431SBartłomiej Klocek 39079c4431SBartłomiej Klocek/** 4043a76f73STomasz Sapeta * The result of code reviews that is being used to generate the final review comment/report. 4143a76f73STomasz Sapeta */ 4243a76f73STomasz Sapetaexport type ReviewOutput = { 4343a76f73STomasz Sapeta status: ReviewStatus; 4443a76f73STomasz Sapeta title?: string; 4543a76f73STomasz Sapeta body?: string; 4643a76f73STomasz Sapeta comments?: ReviewComment[]; 4743a76f73STomasz Sapeta}; 4843a76f73STomasz Sapeta 4943a76f73STomasz Sapeta/** 5043a76f73STomasz Sapeta * An input is an object that is passed to each code reviewer. 5143a76f73STomasz Sapeta * It contains some data that are commonly used by all reviewers. 5243a76f73STomasz Sapeta */ 5343a76f73STomasz Sapetaexport type ReviewInput = { 5443a76f73STomasz Sapeta pullRequest: PullRequest; 5543a76f73STomasz Sapeta diff: GitFileDiff[]; 5643a76f73STomasz Sapeta}; 5743a76f73STomasz Sapeta 5843a76f73STomasz Sapeta/** 5943a76f73STomasz Sapeta * A status of the review output. 6043a76f73STomasz Sapeta */ 6143a76f73STomasz Sapetaexport enum ReviewStatus { 6243a76f73STomasz Sapeta /** 6343a76f73STomasz Sapeta * Passive outputs are not included in the final report, 6443a76f73STomasz Sapeta * but they may have some comments/suggestions which are not obligatory to apply. 6543a76f73STomasz Sapeta */ 6643a76f73STomasz Sapeta PASSIVE = 1, 6743a76f73STomasz Sapeta 6843a76f73STomasz Sapeta /** 6943a76f73STomasz Sapeta * Warnings are included in the final report and are not obligatory to fix. 7043a76f73STomasz Sapeta */ 7143a76f73STomasz Sapeta WARN = 2, 7243a76f73STomasz Sapeta 7343a76f73STomasz Sapeta /** 7443a76f73STomasz Sapeta * Errors are included in the final report and are obligatory to fix. 7543a76f73STomasz Sapeta * It implies that the review will request for changes (will send `ReviewEvent.REQUEST_CHANGES` event). 7643a76f73STomasz Sapeta */ 7743a76f73STomasz Sapeta ERROR = 3, 7843a76f73STomasz Sapeta} 7943a76f73STomasz Sapeta 8043a76f73STomasz Sapeta/** 8143a76f73STomasz Sapeta * Review event that is sent during review creation/submission. 8243a76f73STomasz Sapeta * The final review state depends on this event. 8343a76f73STomasz Sapeta */ 8443a76f73STomasz Sapetaexport enum ReviewEvent { 8543a76f73STomasz Sapeta COMMENT = 'COMMENT', 8643a76f73STomasz Sapeta APPROVE = 'APPROVE', 8743a76f73STomasz Sapeta REQUEST_CHANGES = 'REQUEST_CHANGES', 8843a76f73STomasz Sapeta} 89