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
use crate::model::{
    event_types::{macros::repo_origin, RepoEventInfo},
    prelude::*,
    releases::Release,
};

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

as_ref_and_deref!(ReleaseEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[strum(serialize_all = "snake_case")]
pub enum ReleaseAction {
    Published,
    Unpublished,
    Created,
    Edited,
    Deleted,
    #[strum(serialize = "prereleased")]
    PreReleased,
    Released,
}

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#create>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CreateEvent {
    #[serde(rename = "ref")]
    pub ref_field: String,
    pub ref_type: RefType,
    pub master_branch: String,
    pub description: String,
    pub pusher_type: String,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(CreateEvent, RepoEventInfo, event_info);

/// <https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#delete>
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DeleteEvent {
    #[serde(rename = "ref")]
    pub ref_field: String,
    pub ref_type: RefType,
    pub pusher_type: String,
    #[serde(flatten)]
    pub event_info: RepoEventInfo,
}

as_ref_and_deref!(DeleteEvent, RepoEventInfo, event_info);

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EnumString, EnumVariantNames)]
#[strum(serialize_all = "snake_case")]
pub enum RefType {
    Branch,
    Tag,
}

repo_origin!(ReleaseEvent);
repo_origin!(CreateEvent);
repo_origin!(DeleteEvent);