git_bot_feedback/comments/review_comments.rs
1use super::DEFAULT_MARKER;
2
3/// A struct to describe a Pull Request review.
4///
5/// Each review is considered to be about the PR event's changes.
6/// There is no support for posting reviews on older/outdated PR events.
7#[derive(Debug, PartialEq, Eq, Clone)]
8pub struct ReviewOptions {
9 /// The course of action that the PR review suggests.
10 pub action: ReviewAction,
11
12 /// A summary of the PR review.
13 ///
14 /// This is an overview of the review's comments.
15 pub summary: String,
16
17 /// A list of comments for changes to the PR.
18 pub comments: Vec<ReviewComment>,
19
20 /// A string used to mark/identify each comment (and [`Self::summary`]) as a
21 /// comment submitted by this software.
22 ///
23 /// User comments may be indistinguishable from bot/generated comments if
24 /// this value is not unique enough.
25 ///
26 /// If the git server employs Markdown syntax for comments, then
27 /// it is recommended to set this to an HTML comment that is unique to
28 /// your CI application:
29 ///
30 /// ```markdown
31 /// <!-- my-cool-CI-app-name -->
32 /// ```
33 ///
34 /// The default value for this is an HTML comment generated from
35 /// this crate's name and version along with the compile-tome's datetime.
36 /// For example:
37 ///
38 /// ```markdown
39 /// <!-- git-bot-feedback/0.1.0/Jul-14-2025_17-00 -->
40 /// ```
41 pub marker: String,
42
43 /// Allow posting reviews on draft Pull Requests?
44 pub allow_draft: bool,
45
46 /// Allow posting reviews on closed Pull Requests?
47 pub allow_closed: bool,
48
49 /// Permanently delete PR review outdated comments instead of hiding them.
50 ///
51 /// Here be dragons!
52 /// Use with extreme caution when asserting this flag.
53 /// Setting this flag as `true` will permanently
54 /// delete PR review comments that may be pivotal to a thread of discussion.
55 ///
56 /// Note, this does not apply to PR review summary comments nor threads of
57 /// discussion within a review.
58 pub delete_review_comments: bool,
59}
60
61impl Default for ReviewOptions {
62 fn default() -> Self {
63 Self {
64 action: ReviewAction::default(),
65 summary: Default::default(),
66 comments: Default::default(),
67 marker: DEFAULT_MARKER.to_string(),
68 allow_draft: false,
69 allow_closed: false,
70 delete_review_comments: false,
71 }
72 }
73}
74
75/// A enumeration of possible recommended actions for a Pull Request review.
76#[derive(Debug, PartialEq, Eq, Clone, Default)]
77pub enum ReviewAction {
78 /// Approve the current Pull Request's changes.
79 Approve,
80
81 /// Request changes to the current Pull Request's proposal.
82 RequestChanges,
83
84 /// Comment on the current Pull Request's changes without explicitly approving or requesting changes.
85 #[default]
86 Comment,
87}
88
89/// A struct to describe a single comment in a Pull Request review.
90#[derive(Debug, PartialEq, Eq, Clone, Hash)]
91pub struct ReviewComment {
92 /// The file's line number in the diff that begins the the focus of the comment's concerns.
93 pub line_start: Option<u32>,
94
95 /// The file's line number in the diff that ends the focus of the comment's concerns.
96 pub line_end: u32,
97
98 /// The actual comment.
99 ///
100 /// This text can include a code block that demonstrates a suggested change(s).
101 ///
102 /// Typically, the comment should not begin with the [`ReviewOptions::marker`] value.
103 /// That is managed by the git-bot-feedback library.
104 pub comment: String,
105
106 /// The file that this comment pertains to.
107 pub path: String,
108}