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
use crate::model::{
    event_types::{macros::repo_origin, Event, RepoEventInfo},
    misc::deployments::{nested::MarketplacePurchase, Deployment, DeploymentStatus},
    prelude::*,
    pull_requests::events::nested::Change,
    user::SimpleUser,
};

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#deployment>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DeploymentEvent {
    pub action: DeploymentAction,
    pub deployment: Deployment,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(DeploymentEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
pub enum DeploymentAction {
    Created,
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#deployment_status>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DeploymentStatusEvent {
    pub action: DeploymentStatusAction,
    pub deployment_status: DeploymentStatus,
    pub deployment: Deployment,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(DeploymentStatusEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
pub enum DeploymentStatusAction {
    Created,
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#marketplace_purchase>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MarketplacePurchaseEvent {
    pub action: MarketplacePurchaseAction,
    pub effective_date: String,
    pub sender: SimpleUser,
    pub marketplace_purchase: MarketplacePurchase,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
pub enum MarketplacePurchaseAction {
    Purchased,
    PendingChange,
    PendingChangeCancelled,
    Changed,
    Cancelled,
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#sponsorship>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SponsorshipEvent {
    pub action: SponsorshipAction,
    pub effective_date: String,
    pub changes: SponsorshipChanges,
    pub sender: SimpleUser,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
pub enum SponsorshipAction {
    /// `Created` is only triggered after the payment is processed.
    Created,
    Cancelled,
    Edited,
    TierChanged,
    PendingCancellation,
    PendingTierChange,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SponsorshipChanges {
    pub tier: Option<Change>,
    pub privacy_level: Option<Change>,
}

impl Event<'_> for SponsorshipEvent {
    type Origin = SimpleUser;
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#meta>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MetaEvent {
    pub action: MetaAction,
    pub hook_id: usize,
    pub hook: Value,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(MetaEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[serde(rename_all = "snake_case")]
pub enum MetaAction {
    Deleted,
}

repo_origin!(MetaEvent);
repo_origin!(DeploymentEvent);
repo_origin!(DeploymentStatusEvent);