From 7003b3ff058b3d7deddbc8c2e0233fbec45d678b Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 3 Jan 2023 12:53:10 +0530 Subject: [PATCH] feat: define Issue --- src/issue.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 ++ 2 files changed, 92 insertions(+) create mode 100644 src/issue.rs diff --git a/src/issue.rs b/src/issue.rs new file mode 100644 index 0000000..dd9857e --- /dev/null +++ b/src/issue.rs @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2023 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +//! Issues associated to a repository within a forge (Gitea, GitLab, etc.). +use serde::{Deserialize, Serialize}; + +use crate::Reaction; + +#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] +#[serde(rename_all = "lowercase")] +/// states of an issue +pub enum IssueState { + /// A 'closed' issue will not see any activity in the future + Closed, + /// An 'open' issue will see activity in the future + Open, +} + +impl Default for IssueState { + fn default() -> Self { + Self::Open + } +} + +/// Issues associated to a repository within a forge (Gitea, GitLab, etc.). +#[derive(Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq)] +pub struct Issue { + /// Unique identifier, relative to the repository + pub index: usize, + + /// Unique identifier of the user who authored the issue. + pub poster_id: usize, + + /// Short description displayed as the title. + pub title: String, + + /// Long, multiline, description + pub content: String, + + /// Target branch in the repository. + /// + /// NOTE: Actual property is called "ref" but it is a keyword in Rust so we are using + /// "reference". However, "reference" will automatically be renamed to "ref" while serializing + /// and vice versa + #[serde(rename(serialize = "ref", deserialize = "ref"))] + pub reference: Option, + + /// Name of the milestone + pub milestone: Option, + + /// state of the issue + pub state: IssueState, + + /// A locked issue can only be modified by privileged users + pub is_locked: bool, + + // TODO: add validation for format "date-time" + /// Creating time + pub created: String, + + // TODO: add validation for format "date-time" + /// Last update time + pub updated: String, + + // TODO: add validation for format "date-time" + /// The last time 'state' changed to 'closed' + pub closed: Option, + + /// List of labels. + pub labels: Option>, + + /// Multiline content of the comment + pub reactions: Option>, + + /// List of assignees. + pub assignees: Option>, +} diff --git a/src/lib.rs b/src/lib.rs index 46c6c0b..8792154 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ //! This is an incomplete Rust port of the F3 library created by the ForgeFriends project. pub mod comment; pub mod identities; +pub mod issue; pub mod label; pub mod reaction; pub mod repository; @@ -28,6 +29,7 @@ pub mod user; pub use comment::Comment; pub use identities::Identities; +pub use issue::Issue; pub use label::Label; pub use reaction::Reaction; pub use repository::Repository;