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
use crate::model::{
    event_types::{macros::repo_origin, RepoEventInfo},
    issues::{
        comments::IssueComment,
        events::{CommentChanges, IssueCommentAction},
    },
    prelude::*,
    pull_requests::{events::nested::IssueChanges, PullRequest},
};

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PullRequestEvent {
    pub action: PullRequestAction,
    pub number: i64,
    pub pull_request: PullRequest,
    pub changes: Option<IssueChanges>,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(PullRequestEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
pub enum PullRequestAction {
    Assigned,
    AutoMergeDisabled,
    AutoMergeEnabled,
    // = merged/closed
    Closed,
    ConvertedToDraft,
    Edited,
    Labeled,
    Locked,
    Opened,
    ReadyForReview,
    Reopened,
    ReviewRequested,
    ReviewRequestRemoved,
    Synchronize,
    Unassigned,
    Unlabeled,
    Unlocked,
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request_review>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PullRequestReviewEvent {
    pub action: PullRequestAction,
    pub changes: Option<CommentChanges>,
    pub pull_request: PullRequest,
    pub review: Value,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(PullRequestReviewEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[strum(serialize_all = "snake_case")]
pub enum PullRequestReviewAction {
    Submitted,
    Edited,
    Dismissed,
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request_review_comment>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PullRequestReviewCommentEvent {
    pub action: IssueCommentAction,
    pub changes: Option<CommentChanges>,
    pub pull_request: PullRequest,
    pub comment: IssueComment,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(PullRequestReviewCommentEvent, RepoEventInfo, event_info);

pub mod nested {
    use crate::model::prelude::*;

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct IssueChanges {
        pub title: Option<Change>,
        pub body: Option<Change>,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct Change {
        pub from: String,
    }
}

repo_origin!(PullRequestEvent);
repo_origin!(PullRequestReviewEvent);
repo_origin!(PullRequestReviewCommentEvent);