diff --git a/src/lib.rs b/src/lib.rs index d6aa99c..6759843 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ pub mod issue; pub mod label; pub mod milestone; pub mod project; +pub mod pullrequest; pub mod reaction; pub mod repository; pub mod topic; @@ -37,6 +38,7 @@ pub use issue::Issue; pub use label::Label; pub use milestone::Milestone; pub use project::Project; +pub use pullrequest::PullRequest; pub use reaction::Reaction; pub use repository::Repository; pub use topic::Topic; diff --git a/src/pullrequest.rs b/src/pullrequest.rs new file mode 100644 index 0000000..61a711f --- /dev/null +++ b/src/pullrequest.rs @@ -0,0 +1,110 @@ +/* + * 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 . + */ +//! Pull requests associated to a repository within a forge (Gitea, GitLab, etc.) +use serde::{Deserialize, Serialize}; + +use crate::{OpenCloseState, Reaction}; + +/// Pull requests associated to a repository within a forge (Gitea, GitLab, etc.) +#[derive(Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq)] +pub struct PullRequest { + /// Unique identifier, relative to the repository + pub index: usize, + + /// Unique identifier of the user who authored the pull request. + pub poster_id: usize, + + /// Short description displayed as the title. + pub title: String, + + /// Long, multiline, description + pub content: String, + + /// Name of the milestone + pub milestone: Option, + + /// state of the pull request + pub state: OpenCloseState, + + /// A locked pull request issue can only be modified by privileged users + pub is_locked: bool, + + // TODO: add validation for format "date-time" + /// Creation 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>, + + /// List of reactions + pub reactions: Option>, + + /// List of assignees. + pub assignees: Option>, + + /// URL from which the patch of the pull request can be retrieved. + pub patch_url: String, + + /// True if the pull request was merged + pub merged: bool, + + // TODO: add validation for format "date-time" + /// The time when the pull request was merged. + pub merged_time: Option, + + /// The SHA of the merge commit + pub merged_commit_sha: Option, + + /// The changes proposed in the pull request. + pub head: Option, + + /// The branch where the pull request changes in the head are to be merged. + pub base: Option, +} + +/// PullRequest reference to a commit +/// The location of a commit, including the URL of the repository where it can be found +#[derive(Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq)] +pub struct PullRequestRef { + /// URL of the repository where the commit is located. + pub clone_url: 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, + + /// SHA of the commit + pub sha: String, + + /// Name of the project that contains the git repository. + pub repo_name: String, + + /// Name of the user or organization that contains the project. + pub owner_name: String, +}