1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use crate::model::{
    commits::association::Association,
    issues::{milestones::Milestone, Label},
    prelude::*,
    pull_requests::nested::{AutoMerge, HeadBase, Links},
    user::SimpleUser,
};

pub type Pulls = Vec<SimplePullRequest>;

/// Only used when getting pull requests in a list.
///
/// If you aren't listing multiple pull requests, please use [`PullRequest`]
/// instead.
///
/// <https://docs.github.com/en/rest/pulls/pulls#list-pull-requests=>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SimplePullRequest {
    #[serde(rename = "_links")]
    pub links: Links,
    pub assignee: Option<SimpleUser>,
    pub labels: Vec<Label>,
    pub base: HeadBase,
    pub body: Option<String>,
    pub closed_at: Option<String>,
    pub comments_url: String,
    pub commits_url: String,
    pub created_at: String,
    pub diff_url: String,
    pub head: HeadBase,
    pub html_url: String,
    pub id: i64,
    pub node_id: String,
    pub issue_url: String,
    pub merge_commit_sha: Option<String>,
    pub merged_at: Option<String>,
    pub milestone: Option<Milestone>,
    pub number: i64,
    pub patch_url: String,
    pub review_comment_url: String,
    pub review_comments_url: String,
    pub statuses_url: String,
    pub state: PullRequestState,
    pub locked: bool,
    pub title: String,
    pub updated_at: String,
    pub url: String,
    pub user: SimpleUser,
    pub author_association: Association,
    pub auto_merge: Option<AutoMerge>,
}

/// <https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request=>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PullRequest {
    pub additions: i64,
    pub changed_files: i64,
    pub comments: i64,
    pub commits: i64,
    pub deletions: i64,
    pub mergeable: Option<bool>,
    // Variants are not documented
    pub mergeable_state: String,
    pub merged: bool,
    pub maintainer_can_modify: bool,
    pub merged_by: Option<SimpleUser>,
    pub review_comments: i64,
    #[serde(flatten)]
    pub shared: SimplePullRequest,
}

as_ref_and_deref!(PullRequest, SimplePullRequest, shared);

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PullRequestState {
    Closed,
    #[default]
    Open,
}

pub mod nested {
    use serde::{Deserialize, Serialize};

    use crate::model::{as_ref_and_deref, repositories::nested::Repo, user::SimpleUser};

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct HeadBase {
        pub label: String,
        #[serde(rename = "ref")]
        pub ref_field: String,
        pub repo: HeadRepo,
        pub sha: String,
        pub user: SimpleUser,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct HeadRepo {
        pub subscribers_url: String,
        pub subscription_url: String,
        #[serde(flatten)]
        pub common: Repo,
    }

    as_ref_and_deref!(HeadRepo, Repo, common);

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Links {
        pub comments: HRef,
        pub commits: HRef,
        pub statuses: HRef,
        pub html: HRef,
        pub issue: HRef,
        pub review_comments: HRef,
        pub review_comment: HRef,
        #[serde(rename = "self")]
        pub self_field: HRef,
    }

    #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct HRef {
        pub href: String,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct AutoMerge {
        enabled_by: SimpleUser,
        merge_method: String,
        commit_title: String,
        commit_message: String,
    }
}