f3_rs/pullrequest.rs
1// Copyright (C) 2023 Aravinth Manivannan <realaravinth@batsense.net>
2// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
3//
4// SPDX-License-Identifier: MIT
5
6//! Pull requests associated to a repository within a forge (Gitea, GitLab, etc.)
7use serde::{Deserialize, Serialize};
8
9use crate::{OpenCloseState, Reaction};
10
11/// Pull requests associated to a repository within a forge (Gitea, GitLab, etc.)
12#[derive(Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq)]
13pub struct PullRequest {
14 /// Unique identifier, relative to the repository
15 pub index: usize,
16
17 /// Unique identifier of the user who authored the pull request.
18 pub poster_id: usize,
19
20 /// Short description displayed as the title.
21 pub title: String,
22
23 /// Long, multiline, description
24 pub content: String,
25
26 /// Name of the milestone
27 pub milestone: Option<String>,
28
29 /// state of the pull request
30 pub state: OpenCloseState,
31
32 /// A locked pull request issue can only be modified by privileged users
33 pub is_locked: bool,
34
35 // TODO: add validation for format "date-time"
36 /// Creation time
37 pub created: String,
38
39 // TODO: add validation for format "date-time"
40 /// Last update time
41 pub updated: String,
42
43 // TODO: add validation for format "date-time"
44 /// The last time 'state' changed to 'closed'
45 pub closed: Option<String>,
46
47 /// List of labels.
48 pub labels: Option<Vec<String>>,
49
50 /// List of reactions
51 pub reactions: Option<Vec<Reaction>>,
52
53 /// List of assignees.
54 pub assignees: Option<Vec<String>>,
55
56 /// URL from which the patch of the pull request can be retrieved.
57 pub patch_url: String,
58
59 /// True if the pull request was merged
60 pub merged: bool,
61
62 // TODO: add validation for format "date-time"
63 /// The time when the pull request was merged.
64 pub merged_time: Option<String>,
65
66 /// The SHA of the merge commit
67 pub merged_commit_sha: Option<String>,
68
69 /// The changes proposed in the pull request.
70 pub head: Option<PullRequestRef>,
71
72 /// The branch where the pull request changes in the head are to be merged.
73 pub base: Option<PullRequestRef>,
74}
75
76/// PullRequest reference to a commit
77/// The location of a commit, including the URL of the repository where it can be found
78#[derive(Clone, Debug, Serialize, Deserialize, Default, Eq, PartialEq)]
79pub struct PullRequestRef {
80 /// URL of the repository where the commit is located.
81 pub clone_url: String,
82
83 /// Target branch in the repository.
84 ///
85 /// NOTE: Actual property is called "ref" but it is a keyword in Rust so we are using
86 /// "reference". However, "reference" will automatically be renamed to "ref" while serializing
87 /// and vice versa
88 #[serde(rename(serialize = "ref", deserialize = "ref"))]
89 pub reference: Option<String>,
90
91 /// SHA of the commit
92 pub sha: String,
93
94 /// Name of the project that contains the git repository.
95 pub repo_name: String,
96
97 /// Name of the user or organization that contains the project.
98 pub owner_name: String,
99}