1use crate::helpers::ToJsonString;
2use reqwest::Error as ReqwestError;
3use serde::{Deserialize, Serialize};
4use serde_json::error::Error as JsonError;
5use serde_json::Value;
6use std::collections::HashMap;
7
8#[macro_export]
9macro_rules! impl_to_json_string {
10 ($type_name:ty) => {
11 impl ToJsonString for $type_name {
12 fn to_json_string(&self) -> Result<String, JsonError> {
13 serde_json::to_string(self)
14 }
15 }
16 };
17}
18
19pub type Response<T> = Result<GitHubApiResult<T>, GitHubApiError>;
22
23#[derive(Debug)]
24pub struct GitHubApiResult<T> {
25 pub result: T,
26 pub raw_result: String,
27 pub limits: Option<LimitRemainingReset>,
28 pub owner: Option<String>,
29 pub repository: Option<String>,
30 pub next_page: Option<u64>,
31}
32
33#[derive(Debug)]
34pub enum GitHubApiError {
35 NotImplemented,
36 JsonError((JsonError, String)),
37 GitHubError((String, String)),
38 ReqwestError(ReqwestError),
39}
40
41#[derive(Debug, Serialize, Deserialize)]
46pub enum OpenClosed {
47 #[serde(rename(deserialize = "open"))]
48 Open,
49 #[serde(rename(deserialize = "closed"))]
50 Closed,
51}
52
53#[derive(Debug)]
54pub enum Pagination {
55 First(u64),
56 Previous(u64),
57 Next(u64),
58 Last(u64),
59 Undefined(String, u64),
60}
61
62#[derive(Debug, Serialize, Deserialize)]
67pub struct RateLimitResponse {
68 pub resources: RateLimitResources,
69
70 pub rate: Option<LimitRemainingReset>,
73}
74impl_to_json_string!(RateLimitResponse);
75
76#[derive(Debug, Serialize, Deserialize)]
77pub struct RateLimitResources {
78 pub core: LimitRemainingReset,
79 pub search: LimitRemainingReset,
80 pub graphql: LimitRemainingReset,
81 pub integration_manifest: LimitRemainingReset,
82}
83impl_to_json_string!(RateLimitResources);
84
85#[derive(Debug, Serialize, Deserialize)]
86pub struct LimitRemainingReset {
87 pub limit: u64,
88 pub remaining: u64,
89 pub reset: u64,
90}
91impl_to_json_string!(LimitRemainingReset);
92
93#[derive(Debug, Serialize, Deserialize)]
98pub struct TagsResponse {
99 pub name: String,
100 pub zipball_url: String,
101 pub tarball_url: String,
102 pub commit: TagsCommit,
103 pub node_id: String,
104
105 #[serde(flatten)]
106 pub uncaptured: HashMap<String, Value>,
107}
108impl_to_json_string!(TagsResponse);
109
110#[derive(Debug, Serialize, Deserialize)]
111pub struct TagsCommit {
112 pub sha: String,
113 pub url: String,
114
115 #[serde(flatten)]
116 pub uncaptured: HashMap<String, Value>,
117}
118impl_to_json_string!(TagsCommit);
119
120#[derive(Debug, Serialize, Deserialize)]
125pub struct ReleasesResponse {
126 pub url: String,
127 pub assets_url: String,
128 pub upload_url: String,
129 pub html_url: String,
130 pub id: u64,
131 pub node_id: String,
132 pub tag_name: String,
133 pub target_commitish: String,
134 pub name: String,
135 pub draft: bool,
136 pub author: GenericPerson,
137 pub prerelease: bool,
138 pub created_at: String,
139 pub published_at: String,
140 pub assets: Vec<ReleasesAsset>,
141 pub tarball_url: String,
142 pub zipball_url: String,
143 pub body: String,
144
145 #[serde(flatten)]
146 pub uncaptured: HashMap<String, Value>,
147}
148impl_to_json_string!(ReleasesResponse);
149
150#[derive(Debug, Serialize, Deserialize)]
151pub struct ReleasesAsset {
152 pub url: String,
153 pub id: u64,
154 pub node_id: String,
155 pub name: String,
156 pub label: Option<String>,
157 pub uploader: GenericPerson,
158 pub content_type: String,
159 pub state: String,
160 pub size: u64,
161 pub download_count: u64,
162 pub created_at: String,
163 pub updated_at: String,
164 pub browser_download_url: String,
165
166 #[serde(flatten)]
167 pub uncaptured: HashMap<String, Value>,
168}
169impl_to_json_string!(ReleasesAsset);
170
171#[derive(Debug, Serialize, Deserialize)]
172pub struct GenericPerson {
173 pub login: String,
174 pub id: u64,
175 pub node_id: String,
176 pub avatar_url: String,
177 pub gravatar_id: String,
178 pub url: String,
179 pub html_url: String,
180 pub followers_url: String,
181 pub following_url: String,
182 pub gists_url: String,
183 pub starred_url: String,
184 pub subscriptions_url: String,
185 pub organizations_url: String,
186 pub repos_url: String,
187 pub events_url: String,
188 pub received_events_url: String,
189 pub r#type: String,
190 pub site_admin: bool,
191
192 #[serde(flatten)]
193 pub uncaptured: HashMap<String, Value>,
194}
195impl_to_json_string!(GenericPerson);
196
197#[derive(Debug, Serialize, Deserialize)]
202pub struct LicenseResponse {
203 pub name: String,
204 pub path: String,
205 pub sha: String,
206 pub size: u64,
207 pub url: String,
208 pub html_url: String,
209 pub git_url: String,
210 pub download_url: String,
211 pub r#type: String,
212 pub content: String,
213 pub encoding: String,
214 #[serde(rename(deserialize = "_links"))]
215 pub links: LicenseLinks,
216 pub license: LicenseLicense,
217
218 #[serde(flatten)]
219 pub uncaptured: HashMap<String, Value>,
220}
221impl_to_json_string!(LicenseResponse);
222
223#[derive(Debug, Serialize, Deserialize)]
224pub struct LicenseLinks {
225 #[serde(rename(deserialize = "self"))]
226 pub self_link: String,
227 pub git: String,
228 pub html: String,
229
230 #[serde(flatten)]
231 pub uncaptured: HashMap<String, Value>,
232}
233impl_to_json_string!(LicenseLinks);
234
235#[derive(Debug, Serialize, Deserialize)]
236pub struct LicenseLicense {
237 pub key: String,
238 pub name: String,
239 pub spdx_id: String,
240 pub url: String,
241 pub node_id: String,
242
243 #[serde(flatten)]
244 pub uncaptured: HashMap<String, Value>,
245}
246impl_to_json_string!(LicenseLicense);
247
248