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
use crate::model::{
    event_types::{macros::org_origin, OrgEventInfo},
    organizations::{
        events::nested::{MembershipScope, TeamChanges},
        SimpleTeam,
    },
    prelude::*,
    user::SimpleUser,
};

/// The invitation and membership fields are mutually exclusive.
///
/// [Read more](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#organization)
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct OrganizationEvent {
    pub action: OrganizationAction,
    pub invitation: Option<Value>,
    pub membership: Option<Value>,
    #[serde(flatten)]
    pub event_info: OrgEventInfo,
}

as_ref_and_deref!(OrganizationEvent, OrgEventInfo, event_info);

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

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#team>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TeamEvent {
    pub action: TeamAction,
    pub team: SimpleTeam,
    pub changes: TeamChanges,
    #[serde(flatten)]
    pub event_info: OrgEventInfo,
}

as_ref_and_deref!(TeamEvent, OrgEventInfo, event_info);

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

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#membership>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MembershipEvent {
    pub action: MembershipAction,
    pub scope: MembershipScope,
    pub member: SimpleUser,
    pub team: SimpleTeam,
    #[serde(flatten)]
    pub event_info: OrgEventInfo,
}

as_ref_and_deref!(MembershipEvent, OrgEventInfo, event_info);

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

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#org_block>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct OrgBlockEvent {
    pub action: OrgBlockAction,
    pub blocked_user: SimpleUser,
    #[serde(flatten)]
    pub event_info: OrgEventInfo,
}

as_ref_and_deref!(OrgBlockEvent, OrgEventInfo, event_info);

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

pub mod nested {
    use crate::model::{prelude::*, pull_requests::events::nested::Change};

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

    #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
    pub struct TeamChanges {
        pub description: Option<Change>,
        pub name: Option<Change>,
        pub privacy: Option<Change>,
        /// Schema:
        ///
        /// `repository[permissions][from][pull]` boolean
        ///
        /// `repository[permissions][from][push]` boolean
        pub repository: Option<Value>,
    }
}

org_origin!(OrganizationEvent);
org_origin!(MembershipEvent);
org_origin!(OrgBlockEvent);
org_origin!(TeamEvent);