forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.09.3 MiBcd4373fTahinli5 hours ago347 commits

webhooks.rs99 lines, 2.3 KiBHistoryRawDownload
1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum WebhookEvent {
3 Push,
4 PullRequest,
5 Issues,
6 IssueComment,
7 PullRequestReview,
8 Create,
9 Delete,
10 Ping,
11 Release,
12}
13
14impl WebhookEvent {
15 pub const ALL: [WebhookEvent; 9] = [
16 WebhookEvent::Push,
17 WebhookEvent::PullRequest,
18 WebhookEvent::Issues,
19 WebhookEvent::IssueComment,
20 WebhookEvent::PullRequestReview,
21 WebhookEvent::Create,
22 WebhookEvent::Delete,
23 WebhookEvent::Ping,
24 WebhookEvent::Release,
25 ];
26}
27
28string_enum!(WebhookEvent {
29 Push = "push",
30 PullRequest = "pull_request",
31 Issues = "issues",
32 IssueComment = "issue_comment",
33 PullRequestReview = "pull_request_review",
34 Create = "create",
35 Delete = "delete",
36 Ping = "ping",
37 Release = "release",
38});
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum DeliveryState {
42 Pending,
43 Ok,
44 Failed,
45 GaveUp,
46}
47
48string_enum!(DeliveryState {
49 Pending = "pending",
50 Ok = "ok",
51 Failed = "failed",
52 GaveUp = "gave_up",
53});
54
55#[derive(Debug, Clone, PartialEq, Eq)]
56pub struct Webhook {
57 pub id: String,
58 pub repo_id: String,
59 pub url: String,
60 pub events: Vec<WebhookEvent>,
61 pub active: bool,
62 pub created_at: String,
63 pub updated_at: String,
64}
65
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct Delivery {
68 pub id: String,
69 pub hook_id: String,
70 pub guid: String,
71 pub event: WebhookEvent,
72 pub action: String,
73 pub request_headers: String,
74 pub request_body: String,
75 pub state: DeliveryState,
76 pub attempt: u32,
77 pub next_attempt_at: Option<String>,
78 pub response_status: Option<u16>,
79 pub response_headers: Option<String>,
80 pub response_body: Option<String>,
81 pub error: Option<String>,
82 pub duration_ms: Option<u64>,
83 pub created_at: String,
84 pub delivered_at: Option<String>,
85}
86
87#[derive(Debug, Clone, Default, PartialEq, Eq)]
88pub struct AttemptOutcome {
89 pub ok: bool,
90 pub status: Option<u16>,
91 pub response_headers: Option<String>,
92 pub response_body: Option<String>,
93 pub error: Option<String>,
94 pub duration_ms: Option<u64>,
95 pub next_attempt_at: Option<String>,
96 pub request_headers: Option<String>,
97}
98
99pub const MAX_RESPONSE_BODY_BYTES: usize = 64 * 1024;