github_types/app.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
21use serde::Deserialize;
22
23use crate::{DateTime, EventType, User};
24
25pub trait AppEvent {
26 /// Returns the installation ID for the event.
27 fn installation(&self) -> Option<u64> {
28 None
29 }
30}
31
32#[derive(
33 Deserialize, Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash,
34)]
35#[serde(rename_all = "snake_case")]
36pub enum Permission {
37 Read,
38 Write,
39}
40
41/// Permissions given to the app installation.
42#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
43pub struct InstallationPermissions {
44 pub issues: Permission,
45 pub contents: Permission,
46 pub pull_requests: Permission,
47 pub metadata: Permission,
48}
49
50/// Information about an app installation.
51#[derive(Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
52pub struct Installation {
53 pub id: u64,
54 pub account: User,
55 pub repository_selection: String,
56 pub access_tokens_url: String,
57 pub repositories_url: String,
58 pub html_url: String,
59 pub app_id: u64,
60 pub target_id: u64,
61 pub target_type: String,
62 pub permissions: InstallationPermissions,
63 pub events: Vec<EventType>,
64 pub created_at: DateTime,
65 pub updated_at: DateTime,
66 pub single_file_name: Option<String>,
67}