f3-rs 0.1.0

Rust port of the Friendly Forge Format
Documentation
// Copyright (C) 2023  Aravinth Manivannan <realaravinth@batsense.net>
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: MIT

//! A set of review comments on a pull/merge request.
use serde::{Deserialize, Serialize};

use crate::Reaction;

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "UPPERCASE")]
/// State of the review.
pub enum ReviewState {
    Pending,
    Approved,
    ChangesRequested,
    Commented,
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
/// A set of review comments on a pull/merge request.
pub struct Review {
    /// Unique identifier of the review
    pub index: usize,

    /// Unique identifier of the pull/merge request targeted by the review.
    pub issue_index: usize,

    /// Unique identifer of review author.
    pub reviewer_id: usize,

    /// True if a positive review counts to reach the required threshold.
    pub official: Option<bool>,

    /// SHA of the commit targeted by the review.
    pub commit_id: String,

    /// Cover message of the review.
    pub content: String,

    // TODO: add validation for format "date-time"
    /// Creation time
    pub created_at: String,

    /// State of the review.
    pub state: ReviewState,

    /// Review comments inserted on a specific line of the commit.
    pub comments: Option<Vec<ReviewComment>>,
}

/// A comment in the context of a review.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct ReviewComment {
    /// Unique identifier of the review comment.
    pub index: usize,

    /// Unique identifier of the review comment replied to.
    pub in_reply_to: usize,

    /// The text of the review comment
    pub content: String,

    /// The relative path to the file that necessitates a comment.
    pub tree_path: String,

    /// The hunk being commented on, which is the same as the patch only in a different format.
    pub diff_hunk: String,

    /// The patch being commented on, which is the same as the diff_hunk only in a different
    /// format.
    pub patch: String,

    /// Equals the number of lines down from the first '@@' hunk header in the file you want to add
    /// a comment. The line just below the '@@' line is position 1, the next line is position 2,
    /// and so on. The position in the diff continues to increase through lines of whitespace and
    /// additional hunks until the beginning of a new file.",
    pub position: usize,

    /// The line number of the comment in the tree_path
    pub line: usize,

    /// The SHA of the commit needing a comment. Not using the latest commit SHA may render your
    /// comment outdated if a subsequent commit modifies the line you specify as the position.
    pub commit_id: String,

    /// Unique identifier of the user who authored the comment.
    pub poster_id: usize,

    // TODO: add validation for format "date-time"
    /// Creation time
    pub created_at: String,

    // TODO: add validation for format "date-time"
    /// Last update time
    pub updated_at: String,

    /// List of reactions
    pub reactions: Option<Vec<Reaction>>,
}