github_types/
events.rs

1// Copyright (c) 2019 Jason White
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21//! Events are used by repository webhooks.
22//!
23//! See: https://developer.github.com/v3/activity/events/types/
24
25use derive_more::From;
26use serde::{
27    de::{self, Deserializer},
28    Deserialize,
29};
30
31use std::fmt;
32use std::str::FromStr;
33
34use crate::{
35    AppEvent, Comment, DateTime, Installation, Issue, Label, Oid, PullRequest,
36    Repository, Review, ShortRepo, User,
37};
38
39/// GitHub events that are specified in the X-Github-Event header.
40#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
41pub enum EventType {
42    /// (Special event.) Any time any event is triggered (Wildcard Event).
43    Wildcard,
44
45    /// (Special event.) Sent when a webhook is added.
46    Ping,
47
48    /// Triggered when a check run is `created`, `rerequested`, `completed`, or
49    /// has a `requested_action`.
50    CheckRun,
51
52    /// Triggered when a check suite is `completed`, `requested`, or
53    /// `rerequested`.
54    CheckSuite,
55
56    /// Any time a Commit is commented on.
57    CommitComment,
58
59    /// Triggered when the body or comment of an issue or pull request includes
60    /// a URL that matches a configured content reference domain. Only GitHub
61    /// Apps can receive this event.
62    ContentReference,
63
64    /// Any time a Branch or Tag is created.
65    Create,
66
67    /// Any time a Branch or Tag is deleted.
68    Delete,
69
70    /// Any time a Repository has a new deployment created from the API.
71    Deployment,
72
73    /// Any time a deployment for a Repository has a status update from the
74    /// API.
75    DeploymentStatus,
76
77    /// Any time a Repository is forked.
78    Fork,
79
80    /// Triggered when someone revokes their authorization of a GitHub App.
81    GitHubAppAuthorization,
82
83    /// Any time a Wiki page is updated.
84    Gollum,
85
86    /// Any time a GitHub App is installed or uninstalled.
87    Installation,
88
89    /// Same as `Installation`, but deprecated. This event is sent alongside
90    /// the `Installation` event, but can always be ignored.
91    IntegrationInstallation,
92
93    /// Any time a repository is added or removed from an installation.
94    InstallationRepositories,
95
96    /// Same as `InstallationRepositories`, but deprecated. This event is sent
97    /// alongside the `InstallationRepositories` event, but can always be
98    /// ignored.
99    IntegrationInstallationRepositories,
100
101    /// Any time a comment on an issue is created, edited, or deleted.
102    IssueComment,
103
104    /// Any time an Issue is assigned, unassigned, labeled, unlabeled,
105    /// opened, edited, milestoned, demilestoned, closed, or reopened.
106    Issues,
107
108    /// Any time a Label is created, edited, or deleted.
109    Label,
110
111    /// Any time a user purchases, cancels, or changes their GitHub
112    /// Marketplace plan.
113    MarketplacePurchase,
114
115    /// Any time a User is added or removed as a collaborator to a
116    /// Repository, or has their permissions modified.
117    Member,
118
119    /// Any time a User is added or removed from a team. Organization hooks
120    /// only.
121    Membership,
122
123    /// Any time a Milestone is created, closed, opened, edited, or deleted.
124    Milestone,
125
126    /// Any time a user is added, removed, or invited to an Organization.
127    /// Organization hooks only.
128    Organization,
129
130    /// Any time an organization blocks or unblocks a user. Organization
131    /// hooks only.
132    OrgBlock,
133
134    /// Any time a Pages site is built or results in a failed build.
135    PageBuild,
136
137    /// Any time a Project Card is created, edited, moved, converted to an
138    /// issue, or deleted.
139    ProjectCard,
140
141    /// Any time a Project Column is created, edited, moved, or deleted.
142    ProjectColumn,
143
144    /// Any time a Project is created, edited, closed, reopened, or deleted.
145    Project,
146
147    /// Any time a Repository changes from private to public.
148    Public,
149
150    /// Any time a pull request is assigned, unassigned, labeled, unlabeled,
151    /// opened, edited, closed, reopened, or synchronized (updated due to a
152    /// new push in the branch that the pull request is tracking). Also any
153    /// time a pull request review is requested, or a review request is
154    /// removed.
155    PullRequest,
156
157    /// Any time a comment on a pull request's unified diff is created,
158    /// edited, or deleted (in the Files Changed tab).
159    PullRequestReviewComment,
160
161    /// Any time a pull request review is submitted, edited, or dismissed.
162    PullRequestReview,
163
164    /// Any Git push to a Repository, including editing tags or branches.
165    /// Commits via API actions that update references are also counted.
166    /// This is the default event.
167    Push,
168
169    /// Any time a Release is published in a Repository.
170    Release,
171
172    /// Any time a Repository is created, deleted (organization hooks
173    /// only), archived, unarchived, made public, or made private.
174    Repository,
175
176    /// Triggered when a successful, cancelled, or failed repository import
177    /// finishes for a GitHub organization or a personal repository. To receive
178    /// this event for a personal repository, you must create an empty
179    /// repository prior to the import. This event can be triggered using
180    /// either the GitHub Importer or the Source imports API.
181    RepositoryImport,
182
183    /// Triggered when a security alert is created, dismissed, or resolved.
184    RepositoryVulnerabilityAlert,
185
186    /// Triggered when a new security advisory is published, updated, or
187    /// withdrawn. A security advisory provides information about
188    /// security-related vulnerabilities in software on GitHub. Security
189    /// Advisory webhooks are available to GitHub Apps only.
190    SecurityAdvisory,
191
192    /// Any time a Repository has a status update from the API.
193    Status,
194
195    /// Any time a team is created, deleted, modified, or added to or
196    /// removed from a repository. Organization hooks only
197    Team,
198
199    /// Any time a team is added or modified on a Repository.
200    TeamAdd,
201
202    /// Any time a User stars a Repository.
203    Watch,
204}
205
206impl EventType {
207    /// Returns a static string for the event name.
208    pub fn name(self) -> &'static str {
209        match self {
210            EventType::Wildcard => "*",
211            EventType::Ping => "ping",
212            EventType::CheckRun => "check_run",
213            EventType::CheckSuite => "check_suite",
214            EventType::CommitComment => "commit_comment",
215            EventType::ContentReference => "content_reference",
216            EventType::Create => "create",
217            EventType::Delete => "delete",
218            EventType::Deployment => "deployment",
219            EventType::DeploymentStatus => "deployment_status",
220            EventType::Fork => "fork",
221            EventType::GitHubAppAuthorization => "github_app_authorization",
222            EventType::Gollum => "gollum",
223            EventType::Installation => "installation",
224            EventType::IntegrationInstallation => "integration_installation",
225            EventType::InstallationRepositories => "installation_repositories",
226            EventType::IntegrationInstallationRepositories => {
227                "integration_installation_repositories"
228            }
229            EventType::IssueComment => "issue_comment",
230            EventType::Issues => "issues",
231            EventType::Label => "label",
232            EventType::MarketplacePurchase => "marketplace_purchase",
233            EventType::Member => "member",
234            EventType::Membership => "membership",
235            EventType::Milestone => "milestone",
236            EventType::Organization => "organization",
237            EventType::OrgBlock => "org_block",
238            EventType::PageBuild => "page_build",
239            EventType::ProjectCard => "project_card",
240            EventType::ProjectColumn => "project_column",
241            EventType::Project => "project",
242            EventType::Public => "public",
243            EventType::PullRequest => "pull_request",
244            EventType::PullRequestReview => "pull_request_review",
245            EventType::PullRequestReviewComment => {
246                "pull_request_review_comment"
247            }
248            EventType::Push => "push",
249            EventType::Release => "release",
250            EventType::Repository => "repository",
251            EventType::RepositoryImport => "repository_import",
252            EventType::RepositoryVulnerabilityAlert => {
253                "repository_vulnerability_alert"
254            }
255            EventType::SecurityAdvisory => "security_advisory",
256            EventType::Status => "status",
257            EventType::Team => "team",
258            EventType::TeamAdd => "team_add",
259            EventType::Watch => "watch",
260        }
261    }
262}
263
264impl FromStr for EventType {
265    type Err = &'static str;
266
267    fn from_str(s: &str) -> Result<Self, Self::Err> {
268        match s {
269            "*" => Ok(EventType::Wildcard),
270            "ping" => Ok(EventType::Ping),
271            "check_run" => Ok(EventType::CheckRun),
272            "check_suite" => Ok(EventType::CheckSuite),
273            "commit_comment" => Ok(EventType::CommitComment),
274            "content_reference" => Ok(EventType::ContentReference),
275            "create" => Ok(EventType::Create),
276            "delete" => Ok(EventType::Delete),
277            "deployment" => Ok(EventType::Deployment),
278            "deployment_status" => Ok(EventType::DeploymentStatus),
279            "fork" => Ok(EventType::Fork),
280            "github_app_authorization" => Ok(EventType::GitHubAppAuthorization),
281            "gollum" => Ok(EventType::Gollum),
282            "installation" => Ok(EventType::Installation),
283            "integration_installation" => {
284                Ok(EventType::IntegrationInstallation)
285            }
286            "installation_repositories" => {
287                Ok(EventType::InstallationRepositories)
288            }
289            "integration_installation_repositories" => {
290                Ok(EventType::IntegrationInstallationRepositories)
291            }
292            "issue_comment" => Ok(EventType::IssueComment),
293            "issues" => Ok(EventType::Issues),
294            "label" => Ok(EventType::Label),
295            "marketplace_purchase" => Ok(EventType::MarketplacePurchase),
296            "member" => Ok(EventType::Member),
297            "membership" => Ok(EventType::Membership),
298            "milestone" => Ok(EventType::Milestone),
299            "organization" => Ok(EventType::Organization),
300            "org_block" => Ok(EventType::OrgBlock),
301            "page_build" => Ok(EventType::PageBuild),
302            "project_card" => Ok(EventType::ProjectCard),
303            "project_column" => Ok(EventType::ProjectColumn),
304            "project" => Ok(EventType::Project),
305            "public" => Ok(EventType::Public),
306            "pull_request" => Ok(EventType::PullRequest),
307            "pull_request_review_comment" => {
308                Ok(EventType::PullRequestReviewComment)
309            }
310            "pull_request_review" => Ok(EventType::PullRequestReview),
311            "push" => Ok(EventType::Push),
312            "release" => Ok(EventType::Release),
313            "repository" => Ok(EventType::Repository),
314            "repository_import" => Ok(EventType::RepositoryImport),
315            "repository_vulnerability_alert" => {
316                Ok(EventType::RepositoryVulnerabilityAlert)
317            }
318            "security_advisory" => Ok(EventType::SecurityAdvisory),
319            "status" => Ok(EventType::Status),
320            "team" => Ok(EventType::Team),
321            "team_add" => Ok(EventType::TeamAdd),
322            "watch" => Ok(EventType::Watch),
323            _ => Err("invalid GitHub event"),
324        }
325    }
326}
327
328impl<'de> Deserialize<'de> for EventType {
329    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
330    where
331        D: Deserializer<'de>,
332    {
333        let s = String::deserialize(deserializer)?;
334        FromStr::from_str(&s).map_err(de::Error::custom)
335    }
336}
337
338impl fmt::Display for EventType {
339    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
340        f.write_str(self.name())
341    }
342}
343
344/// An event with a corresponding payload.
345///
346/// For documentation on each of these events, see:
347/// https://developer.github.com/v3/activity/events/types/
348#[derive(
349    Deserialize, From, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
350)]
351#[allow(clippy::large_enum_variant)]
352pub enum Event {
353    Ping(PingEvent),
354    // CheckRun(CheckRunEvent),
355    // CheckSuite(CheckSuiteEvent),
356    CommitComment(CommitCommentEvent),
357    // ContentReference(ContentReferenceEvent),
358    Create(CreateEvent),
359    Delete(DeleteEvent),
360    // Deployment(DeploymentEvent),
361    // DeploymentStatus(DeploymentStatusEvent),
362    // Fork(ForkEvent),
363    GitHubAppAuthorization(GitHubAppAuthorizationEvent),
364    Gollum(GollumEvent),
365    Installation(InstallationEvent),
366    InstallationRepositories(InstallationRepositoriesEvent),
367    IntegrationInstallation(IntegrationInstallationEvent),
368    IntegrationInstallationRepositories(
369        IntegrationInstallationRepositoriesEvent,
370    ),
371    IssueComment(IssueCommentEvent),
372    Issues(IssuesEvent),
373    Label(LabelEvent),
374    // MarketplacePurchase(MarketplacePurchaseEvent),
375    // Member(MemberEvent),
376    // Membership(MembershipEvent),
377    // Milestone(MilestoneEvent),
378    // Organization(OrganizationEvent),
379    // OrgBlock(OrgBlockEvent),
380    // PageBuild(PageBuildEvent),
381    // ProjectCard(ProjectCardEvent),
382    // ProjectColumn(ProjectColumnEvent),
383    // Project(ProjectEvent),
384    // Public(PublicEvent),
385    PullRequest(PullRequestEvent),
386    PullRequestReview(PullRequestReviewEvent),
387    PullRequestReviewComment(PullRequestReviewCommentEvent),
388    Push(PushEvent),
389    // Release(ReleaseEvent),
390    Repository(RepositoryEvent),
391    // RepositoryImport(RepositoryImportEvent),
392    // RepositoryVulnerabilityAlert(RepositoryVulnerabilityAlertEvent),
393    // SecurityAdvisory(SecurityAdvisoryEvent),
394    // Status(StatusEvent),
395    // Team(TeamEvent),
396    // TeamAdd(TeamAddEvent),
397    Watch(WatchEvent),
398}
399
400impl AppEvent for Event {
401    fn installation(&self) -> Option<u64> {
402        match self {
403            Event::Ping(e) => e.installation(),
404            Event::CommitComment(e) => e.installation(),
405            Event::Create(e) => e.installation(),
406            Event::Delete(e) => e.installation(),
407            Event::GitHubAppAuthorization(e) => e.installation(),
408            Event::Gollum(e) => e.installation(),
409            Event::Installation(e) => e.installation(),
410            Event::InstallationRepositories(e) => e.installation(),
411            Event::IntegrationInstallation(e) => e.installation(),
412            Event::IntegrationInstallationRepositories(e) => e.installation(),
413            Event::IssueComment(e) => e.installation(),
414            Event::Issues(e) => e.installation(),
415            Event::Label(e) => e.installation(),
416            Event::PullRequest(e) => e.installation(),
417            Event::PullRequestReview(e) => e.installation(),
418            Event::PullRequestReviewComment(e) => e.installation(),
419            Event::Push(e) => e.installation(),
420            Event::Repository(e) => e.installation(),
421            Event::Watch(e) => e.installation(),
422        }
423    }
424}
425
426/// The App installation ID.
427#[derive(
428    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
429)]
430pub struct InstallationId {
431    pub id: u64,
432}
433
434#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
435#[serde(tag = "type")]
436pub enum Hook {
437    Repository(RepoHook),
438    App(AppHook),
439}
440
441#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
442pub struct RepoHook {
443    pub id: u64,
444    pub name: String,
445    pub active: bool,
446    pub events: Vec<EventType>,
447    pub config: HookConfig,
448    pub updated_at: DateTime,
449    pub created_at: DateTime,
450    pub url: String,
451    pub test_url: String,
452    pub ping_url: String,
453}
454
455#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
456pub struct HookConfig {
457    pub content_type: String,
458    pub insecure_ssl: String,
459    pub secret: String,
460    pub url: String,
461}
462
463#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
464pub struct AppHook {
465    pub id: u64,
466    pub name: String,
467    pub active: bool,
468    pub events: Vec<Event>,
469    pub config: HookConfig,
470    pub updated_at: DateTime,
471    pub created_at: DateTime,
472    pub integration_id: u64,
473    pub app_id: u64,
474}
475
476#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
477pub struct PingEvent {
478    pub zen: String,
479    pub hook_id: u64,
480    pub hook: Hook,
481    pub repository: Option<Repository>,
482    pub sender: Option<User>,
483}
484
485impl AppEvent for PingEvent {}
486
487#[derive(
488    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
489)]
490#[serde(rename_all = "snake_case")]
491pub enum CommitCommentAction {
492    Created,
493}
494
495#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
496pub struct CommitCommentEvent {
497    pub action: CommitCommentAction,
498
499    /// The comment in question.
500    pub comment: Comment,
501
502    /// The repository associated with this event.
503    pub repository: Repository,
504
505    /// The user who triggered the event.
506    pub sender: User,
507
508    /// The App installation ID. This is only present for GitHub App events.
509    pub installation: Option<InstallationId>,
510}
511
512impl AppEvent for CommitCommentEvent {
513    fn installation(&self) -> Option<u64> {
514        self.installation.map(|i| i.id)
515    }
516}
517
518#[derive(
519    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
520)]
521#[serde(rename_all = "snake_case")]
522pub enum CreateRefType {
523    Repository,
524    Branch,
525    Tag,
526}
527
528#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
529pub struct CreateEvent {
530    /// The Git ref type.
531    pub ref_type: CreateRefType,
532
533    /// The Git ref string.
534    ///
535    /// `None` if only a repository was created.
536    #[serde(rename = "ref")]
537    pub git_ref: Option<String>,
538
539    /// The name of the repository's default branch (usually `master`).
540    pub master_branch: String,
541
542    /// The repository's current description.
543    pub description: Option<String>,
544
545    /// The repository associated with this event.
546    pub repository: Repository,
547
548    /// The user who triggered the event.
549    pub sender: User,
550
551    /// The App installation ID. This is only present for GitHub App events.
552    pub installation: Option<InstallationId>,
553}
554
555impl AppEvent for CreateEvent {
556    fn installation(&self) -> Option<u64> {
557        self.installation.map(|i| i.id)
558    }
559}
560
561#[derive(
562    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
563)]
564#[serde(rename_all = "snake_case")]
565pub enum DeleteRefType {
566    Branch,
567    Tag,
568}
569
570#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
571pub struct DeleteEvent {
572    /// The Git ref type.
573    pub ref_type: DeleteRefType,
574
575    /// The Git ref string.
576    #[serde(rename = "ref")]
577    pub git_ref: String,
578
579    /// The repository associated with this event.
580    pub repository: Repository,
581
582    /// The user who triggered the event.
583    pub sender: User,
584
585    /// The App installation ID. This is only present for GitHub App events.
586    pub installation: Option<InstallationId>,
587}
588
589impl AppEvent for DeleteEvent {
590    fn installation(&self) -> Option<u64> {
591        self.installation.map(|i| i.id)
592    }
593}
594
595#[derive(
596    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
597)]
598#[serde(rename_all = "snake_case")]
599pub enum GitHubAppAuthorizationAction {
600    Revoked,
601}
602
603/// Triggered when someone revokes their authorization of a GitHub App. A GitHub
604/// App receives this webhook by default and cannot unsubscribe from this event.
605#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
606pub struct GitHubAppAuthorizationEvent {
607    pub action: GitHubAppAuthorizationAction,
608
609    /// The user who triggered the event.
610    pub sender: User,
611
612    /// The App installation ID.
613    pub installation: InstallationId,
614}
615
616impl AppEvent for GitHubAppAuthorizationEvent {
617    fn installation(&self) -> Option<u64> {
618        Some(self.installation.id)
619    }
620}
621
622#[derive(
623    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
624)]
625#[serde(rename_all = "snake_case")]
626pub enum PageAction {
627    Created,
628    Edited,
629}
630
631#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
632pub struct PageEvent {
633    pub page_name: String,
634    pub title: String,
635    pub summary: Option<String>,
636    pub action: PageAction,
637    pub sha: Oid,
638    pub html_url: String,
639}
640
641#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
642pub struct GollumEvent {
643    /// The pages that were created or edited.
644    pub pages: Vec<PageEvent>,
645
646    /// The repository for which the action took place.
647    pub repository: Repository,
648
649    /// The user who triggered the event.
650    pub sender: User,
651
652    /// The App installation ID. This is only present for GitHub App events.
653    pub installation: Option<InstallationId>,
654}
655
656impl AppEvent for GollumEvent {
657    fn installation(&self) -> Option<u64> {
658        self.installation.map(|i| i.id)
659    }
660}
661
662#[derive(
663    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
664)]
665#[serde(rename_all = "snake_case")]
666pub enum InstallationAction {
667    Created,
668    Deleted,
669    NewPermissionsAccepted,
670}
671
672#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
673pub struct InstallationEvent {
674    pub action: InstallationAction,
675    pub installation: Installation,
676    pub sender: User,
677}
678
679impl AppEvent for InstallationEvent {
680    fn installation(&self) -> Option<u64> {
681        Some(self.installation.id)
682    }
683}
684
685#[derive(
686    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
687)]
688#[serde(rename_all = "snake_case")]
689pub enum InstallationRepositoriesAction {
690    Added,
691    Removed,
692}
693
694#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
695pub struct InstallationRepositoriesEvent {
696    pub action: InstallationRepositoriesAction,
697    pub installation: Installation,
698    pub repository_selection: String,
699    pub repositories_added: Vec<ShortRepo>,
700    pub repositories_removed: Vec<ShortRepo>,
701    pub sender: User,
702}
703
704impl AppEvent for InstallationRepositoriesEvent {
705    fn installation(&self) -> Option<u64> {
706        Some(self.installation.id)
707    }
708}
709
710/// Event deprecated by GitHub. Use `InstallationEvent` instead.
711#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
712pub struct IntegrationInstallationEvent;
713
714impl AppEvent for IntegrationInstallationEvent {
715    fn installation(&self) -> Option<u64> {
716        None
717    }
718}
719
720/// Event deprecated by GitHub. Use `InstallationRepositoriesEvent` instead.
721#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
722pub struct IntegrationInstallationRepositoriesEvent;
723
724impl AppEvent for IntegrationInstallationRepositoriesEvent {
725    fn installation(&self) -> Option<u64> {
726        None
727    }
728}
729
730#[derive(
731    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
732)]
733#[serde(rename_all = "snake_case")]
734pub enum IssueCommentAction {
735    Created,
736    Edited,
737    Deleted,
738}
739
740#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
741pub struct IssueCommentEvent {
742    /// The action that was performed.
743    pub action: IssueCommentAction,
744
745    /// The issue associated with the comment.
746    pub issue: Issue,
747
748    /// The comment in question.
749    pub comment: Comment,
750
751    /// The repository associated with this event.
752    pub repository: Repository,
753
754    /// The user who triggered the event.
755    pub sender: User,
756
757    /// The App installation ID. This is only present for GitHub App events.
758    pub installation: Option<InstallationId>,
759}
760
761impl AppEvent for IssueCommentEvent {
762    fn installation(&self) -> Option<u64> {
763        self.installation.map(|i| i.id)
764    }
765}
766
767#[derive(
768    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
769)]
770#[serde(rename_all = "snake_case")]
771pub enum IssueAction {
772    Opened,
773    Edited,
774    Deleted,
775    Transferred,
776    Pinned,
777    Unpinned,
778    Closed,
779    Reopened,
780    Assigned,
781    Unassigned,
782    Labeled,
783    Unlabeled,
784    Milestoned,
785    Demilestoned,
786}
787
788#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
789pub struct ChangeFrom {
790    pub from: String,
791}
792
793#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
794pub struct IssueChanges {
795    /// A change to the body, if any.
796    pub body: Option<ChangeFrom>,
797
798    /// A change to the title, if any.
799    pub title: Option<ChangeFrom>,
800}
801
802#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
803pub struct IssuesEvent {
804    /// The action that was performed.
805    pub action: IssueAction,
806
807    /// The issue itself.
808    pub issue: Issue,
809
810    /// Changes to the issues (if the action is `Edited`).
811    pub changes: Option<IssueChanges>,
812
813    /// The label that was added or removed (if the action is `Labeled` or
814    /// `Unlabeled`).
815    pub label: Option<Label>,
816
817    /// The optional user who was assigned or unassigned from the issue (if the
818    /// action is `Assigned` or `Unassigned`).
819    pub assignee: Option<User>,
820
821    /// The repository associated with this event.
822    pub repository: Repository,
823
824    /// The user who triggered the event.
825    pub sender: User,
826
827    /// The App installation ID. This is only present for GitHub App events.
828    pub installation: Option<InstallationId>,
829}
830
831impl AppEvent for IssuesEvent {
832    fn installation(&self) -> Option<u64> {
833        self.installation.map(|i| i.id)
834    }
835}
836
837#[derive(
838    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
839)]
840#[serde(rename_all = "snake_case")]
841pub enum LabelAction {
842    Created,
843    Edited,
844    Deleted,
845}
846
847#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
848pub struct LabelChanges {
849    /// A change to the body, if any.
850    pub color: Option<ChangeFrom>,
851
852    /// A change to the title, if any.
853    pub name: Option<ChangeFrom>,
854}
855
856#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
857pub struct LabelEvent {
858    /// The action that was performed.
859    pub action: LabelAction,
860
861    /// The label itself.
862    pub label: Label,
863
864    /// Changes to the issues (if the action is `Edited`).
865    pub changes: Option<LabelChanges>,
866
867    /// The repository associated with this event.
868    pub repository: Repository,
869
870    /// The user who triggered the event.
871    pub sender: User,
872
873    /// The App installation ID. This is only present for GitHub App events.
874    pub installation: Option<InstallationId>,
875}
876
877impl AppEvent for LabelEvent {
878    fn installation(&self) -> Option<u64> {
879        self.installation.map(|i| i.id)
880    }
881}
882
883#[derive(
884    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
885)]
886#[serde(rename_all = "snake_case")]
887pub enum PullRequestAction {
888    Assigned,
889    Unassigned,
890    ReviewRequested,
891    ReviewRequestRemoved,
892    Labeled,
893    Unlabeled,
894    Opened,
895    Edited,
896    Closed,
897    ReadyForReview,
898    Locked,
899    Unlocked,
900    Reopened,
901    Synchronize,
902}
903
904#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
905pub struct PullRequestEvent {
906    /// The action that was performed. Can be one of "assigned", "unassigned",
907    /// "review_requested", "review_request_removed", "labeled", "unlabeled",
908    /// "opened", "edited", "closed", or "reopened". If the action is "closed"
909    /// and the `merged` key is `false`, the pull request was closed with
910    /// unmerged commits. If the action is "closed" and the `merged` key is
911    /// `true`, the pull request was merged. While webhooks are also triggered
912    /// when a pull request is synchronized, Events API timelines don't include
913    /// pull request events with the "synchronize" action.
914    pub action: PullRequestAction,
915
916    /// The pull request number.
917    pub number: u64,
918
919    /// The pull request itself.
920    pub pull_request: PullRequest,
921
922    /// The repository associated with this event.
923    pub repository: Repository,
924
925    /// The user who triggered the event.
926    pub sender: User,
927
928    /// The App installation ID. This is only present for GitHub App events.
929    pub installation: Option<InstallationId>,
930}
931
932impl AppEvent for PullRequestEvent {
933    fn installation(&self) -> Option<u64> {
934        self.installation.map(|i| i.id)
935    }
936}
937
938#[derive(
939    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
940)]
941#[serde(rename_all = "snake_case")]
942pub enum PullRequestReviewAction {
943    Submitted,
944    Edited,
945    Dismissed,
946}
947
948#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
949pub struct PullRequestReviewChanges {
950    pub body: Option<ChangeFrom>,
951}
952
953#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
954pub struct PullRequestReviewEvent {
955    /// The action that was performed.
956    pub action: PullRequestReviewAction,
957
958    /// The review that was affected.
959    pub review: Review,
960
961    /// Changes to the review if the action is `Edited`.
962    pub changes: Option<PullRequestReviewChanges>,
963
964    /// The pull request itself.
965    pub pull_request: PullRequest,
966
967    /// The repository associated with this event.
968    pub repository: Repository,
969
970    /// The user who triggered the event.
971    pub sender: User,
972
973    /// The App installation ID. This is only present for GitHub App events.
974    pub installation: Option<InstallationId>,
975}
976
977impl AppEvent for PullRequestReviewEvent {
978    fn installation(&self) -> Option<u64> {
979        self.installation.map(|i| i.id)
980    }
981}
982
983#[derive(
984    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
985)]
986#[serde(rename_all = "snake_case")]
987pub enum PullRequestReviewCommentAction {
988    Created,
989    Edited,
990    Deleted,
991}
992
993#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
994pub struct PullRequestReviewCommentChanges {
995    /// A change to the body, if any.
996    pub body: Option<ChangeFrom>,
997}
998
999#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1000pub struct PullRequestReviewCommentEvent {
1001    pub action: PullRequestReviewCommentAction,
1002
1003    /// The changes to the comment if the action was `Edited`.
1004    pub changes: Option<PullRequestReviewCommentChanges>,
1005
1006    /// The pull request itself.
1007    pub pull_request: PullRequest,
1008
1009    /// The repository associated with this event.
1010    pub repository: Repository,
1011
1012    /// The comment in question.
1013    pub comment: Comment,
1014
1015    /// The user who triggered the event.
1016    pub sender: User,
1017
1018    /// The App installation ID. This is only present for GitHub App events.
1019    pub installation: Option<InstallationId>,
1020}
1021
1022impl AppEvent for PullRequestReviewCommentEvent {
1023    fn installation(&self) -> Option<u64> {
1024        self.installation.map(|i| i.id)
1025    }
1026}
1027
1028#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1029pub struct Pusher {
1030    pub name: String,
1031    pub email: Option<String>,
1032}
1033
1034#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1035pub struct PushAuthor {
1036    pub name: String,
1037    pub email: Option<String>,
1038    pub username: Option<String>,
1039}
1040
1041#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1042pub struct PushCommit {
1043    pub id: Oid,
1044    pub tree_id: Oid,
1045    pub distinct: bool,
1046    pub message: String,
1047    pub timestamp: DateTime,
1048    pub url: String,
1049    pub author: PushAuthor,
1050    pub committer: PushAuthor,
1051    pub added: Vec<String>,
1052    pub removed: Vec<String>,
1053    pub modified: Vec<String>,
1054}
1055
1056#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1057pub struct PushEvent {
1058    /// The Git ref string that was pushed.
1059    #[serde(rename = "ref")]
1060    pub git_ref: String,
1061
1062    /// The commit hash of the branch before the push.
1063    pub before: Oid,
1064
1065    /// The commit hash of the branch after the push.
1066    pub after: Oid,
1067
1068    /// `true` if this is a new branch.
1069    pub created: bool,
1070
1071    /// `true` if this branch is being deleted.
1072    pub deleted: bool,
1073
1074    /// `true` if this was a force-push.
1075    pub forced: bool,
1076
1077    pub base_ref: Option<String>,
1078
1079    /// The URL to compare the changes with.
1080    pub compare: String,
1081
1082    /// The list of commits that were pushed.
1083    pub commits: Vec<PushCommit>,
1084
1085    /// The new head commit.
1086    pub head_commit: Option<PushCommit>,
1087
1088    /// The repository associated with this event.
1089    pub repository: Repository,
1090
1091    /// The user who pushed the branch. This is the same as the sender, except
1092    /// with less information.
1093    pub pusher: Pusher,
1094
1095    /// The user who triggered the event.
1096    pub sender: User,
1097
1098    /// The App installation ID. This is only present for GitHub App events.
1099    pub installation: Option<InstallationId>,
1100}
1101
1102impl AppEvent for PushEvent {
1103    fn installation(&self) -> Option<u64> {
1104        self.installation.map(|i| i.id)
1105    }
1106}
1107
1108#[derive(
1109    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
1110)]
1111#[serde(rename_all = "snake_case")]
1112pub enum RepositoryAction {
1113    Created,
1114    Deleted,
1115    Archived,
1116    Unarchived,
1117    Publicized,
1118    Privatized,
1119}
1120
1121#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1122pub struct RepositoryEvent {
1123    /// The action that was performed.
1124    pub action: RepositoryAction,
1125
1126    /// The repository associated with this event.
1127    pub repository: Repository,
1128
1129    /// The user who triggered the event.
1130    pub sender: User,
1131
1132    /// The App installation ID. This is only present for GitHub App events.
1133    pub installation: Option<InstallationId>,
1134}
1135
1136impl AppEvent for RepositoryEvent {
1137    fn installation(&self) -> Option<u64> {
1138        self.installation.map(|i| i.id)
1139    }
1140}
1141
1142#[derive(
1143    Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
1144)]
1145#[serde(rename_all = "snake_case")]
1146pub enum WatchAction {
1147    Started,
1148}
1149
1150#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1151pub struct WatchEvent {
1152    /// The action that was performed.
1153    pub action: WatchAction,
1154
1155    /// The repository associated with this event.
1156    pub repository: Repository,
1157
1158    /// The user who triggered the event.
1159    pub sender: User,
1160
1161    /// The App installation ID. This is only present for GitHub App events.
1162    pub installation: Option<InstallationId>,
1163}
1164
1165impl AppEvent for WatchEvent {
1166    fn installation(&self) -> Option<u64> {
1167        self.installation.map(|i| i.id)
1168    }
1169}