1#![allow(missing_docs)]
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct RepositoryRef {
7 pub owner: String,
8 pub repo: String,
9}
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct FileChange {
13 pub path: String,
14 pub content: String,
15 #[serde(default = "default_encoding")]
16 pub encoding: FileEncoding,
17 #[serde(default)]
18 pub operation: FileOperation,
19}
20
21fn default_encoding() -> FileEncoding {
22 FileEncoding::Utf8
23}
24
25#[derive(Debug, Clone, Default, Serialize, Deserialize)]
26#[serde(rename_all = "kebab-case")]
27pub enum FileEncoding {
28 #[default]
29 Utf8,
30 Base64,
31}
32
33#[derive(Debug, Clone, Default, Serialize, Deserialize)]
34#[serde(rename_all = "lowercase")]
35pub enum FileOperation {
36 Add,
37 #[default]
38 Modify,
39 Delete,
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
43#[serde(rename_all = "lowercase")]
44pub enum IssueState {
45 Open,
46 Closed,
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
50#[serde(rename_all = "snake_case")]
51pub enum IssueStateReason {
52 Completed,
53 NotPlanned,
54 Reopened,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct GitHubLabel {
59 pub id: u64,
60 pub name: String,
61 pub color: String,
62 pub description: Option<String>,
63 #[serde(default)]
64 pub default: bool,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct GitHubMilestone {
69 pub number: u32,
70 pub title: String,
71 pub description: Option<String>,
72 pub state: MilestoneState,
73 pub due_on: Option<String>,
74 pub created_at: String,
75 pub updated_at: String,
76 pub closed_at: Option<String>,
77 #[serde(default)]
78 pub open_issues: u32,
79 #[serde(default)]
80 pub closed_issues: u32,
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
84#[serde(rename_all = "lowercase")]
85pub enum MilestoneState {
86 Open,
87 Closed,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
91pub struct GitHubUser {
92 pub id: u64,
93 pub login: String,
94 pub name: Option<String>,
95 pub avatar_url: String,
96 pub html_url: String,
97 #[serde(rename = "type")]
98 pub user_type: UserType,
99}
100
101#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
102pub enum UserType {
103 User,
104 Organization,
105 Bot,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct GitHubIssue {
110 pub number: u64,
111 pub title: String,
112 pub body: Option<String>,
113 pub state: IssueState,
114 pub state_reason: Option<IssueStateReason>,
115 pub user: GitHubUser,
116 #[serde(default)]
117 pub assignees: Vec<GitHubUser>,
118 #[serde(default)]
119 pub labels: Vec<GitHubLabel>,
120 pub milestone: Option<GitHubMilestone>,
121 pub created_at: String,
122 pub updated_at: String,
123 pub closed_at: Option<String>,
124 pub html_url: String,
125 #[serde(default)]
126 pub comments: u32,
127 #[serde(default)]
128 pub is_pull_request: bool,
129}
130
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct CreateIssueParams {
133 pub owner: String,
134 pub repo: String,
135 pub title: String,
136 pub body: Option<String>,
137 #[serde(default)]
138 pub assignees: Vec<String>,
139 #[serde(default)]
140 pub labels: Vec<String>,
141 pub milestone: Option<u32>,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize)]
145pub struct UpdateIssueParams {
146 pub owner: String,
147 pub repo: String,
148 pub issue_number: u64,
149 pub title: Option<String>,
150 pub body: Option<String>,
151 pub state: Option<IssueState>,
152 pub state_reason: Option<IssueStateReason>,
153 pub assignees: Option<Vec<String>>,
154 pub labels: Option<Vec<String>>,
155 pub milestone: Option<u32>,
156}
157
158#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct ListIssuesParams {
160 pub owner: String,
161 pub repo: String,
162 #[serde(default = "default_issue_state_filter")]
163 pub state: IssueStateFilter,
164 pub labels: Option<String>,
165 #[serde(default)]
166 pub sort: IssueSort,
167 #[serde(default)]
168 pub direction: SortDirection,
169 pub assignee: Option<String>,
170 pub creator: Option<String>,
171 #[serde(default = "default_per_page")]
172 pub per_page: u8,
173 #[serde(default = "default_page")]
174 pub page: u32,
175}
176
177fn default_issue_state_filter() -> IssueStateFilter {
178 IssueStateFilter::Open
179}
180
181fn default_per_page() -> u8 {
182 30
183}
184
185fn default_page() -> u32 {
186 1
187}
188
189#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
190#[serde(rename_all = "lowercase")]
191pub enum IssueStateFilter {
192 #[default]
193 Open,
194 Closed,
195 All,
196}
197
198#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
199#[serde(rename_all = "lowercase")]
200pub enum IssueSort {
201 #[default]
202 Created,
203 Updated,
204 Comments,
205}
206
207#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
208#[serde(rename_all = "lowercase")]
209pub enum SortDirection {
210 Asc,
211 #[default]
212 Desc,
213}
214
215#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
216#[serde(rename_all = "lowercase")]
217pub enum PullRequestState {
218 Open,
219 Closed,
220}
221
222#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
223#[serde(rename_all = "lowercase")]
224pub enum PullRequestStateFilter {
225 #[default]
226 Open,
227 Closed,
228 All,
229}
230
231#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
232#[serde(rename_all = "kebab-case")]
233pub enum PullRequestSort {
234 #[default]
235 Created,
236 Updated,
237 Popularity,
238 LongRunning,
239}
240
241#[derive(Debug, Clone, Serialize, Deserialize)]
242pub struct ListPullRequestsParams {
243 pub owner: String,
244 pub repo: String,
245 #[serde(default)]
246 pub state: PullRequestStateFilter,
247 pub head: Option<String>,
248 pub base: Option<String>,
249 #[serde(default)]
250 pub sort: PullRequestSort,
251 #[serde(default)]
252 pub direction: SortDirection,
253 #[serde(default = "default_per_page")]
254 pub per_page: u8,
255 #[serde(default = "default_page")]
256 pub page: u32,
257}
258
259#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
260#[serde(rename_all = "lowercase")]
261pub enum MergeableState {
262 Mergeable,
263 Conflicting,
264 #[default]
265 Unknown,
266}
267
268#[derive(Debug, Clone, Serialize, Deserialize)]
269pub struct GitHubBranchRef {
270 #[serde(rename = "ref")]
271 pub branch_ref: String,
272 pub label: String,
273 pub sha: String,
274 pub repo: Option<RepositoryRef>,
275}
276
277#[derive(Debug, Clone, Serialize, Deserialize)]
278pub struct GitHubPullRequest {
279 pub number: u64,
280 pub title: String,
281 pub body: Option<String>,
282 pub state: PullRequestState,
283 #[serde(default)]
284 pub draft: bool,
285 #[serde(default)]
286 pub merged: bool,
287 pub mergeable: Option<bool>,
288 #[serde(default)]
289 pub mergeable_state: MergeableState,
290 pub user: GitHubUser,
291 pub head: GitHubBranchRef,
292 pub base: GitHubBranchRef,
293 #[serde(default)]
294 pub assignees: Vec<GitHubUser>,
295 #[serde(default)]
296 pub requested_reviewers: Vec<GitHubUser>,
297 #[serde(default)]
298 pub labels: Vec<GitHubLabel>,
299 pub milestone: Option<GitHubMilestone>,
300 pub created_at: String,
301 pub updated_at: String,
302 pub closed_at: Option<String>,
303 pub merged_at: Option<String>,
304 pub html_url: String,
305 #[serde(default)]
306 pub commits: u32,
307 #[serde(default)]
308 pub additions: u32,
309 #[serde(default)]
310 pub deletions: u32,
311 #[serde(default)]
312 pub changed_files: u32,
313}
314
315#[derive(Debug, Clone, Serialize, Deserialize)]
316pub struct CreatePullRequestParams {
317 pub owner: String,
318 pub repo: String,
319 pub title: String,
320 pub body: Option<String>,
321 pub head: String,
322 pub base: String,
323 #[serde(default)]
324 pub draft: bool,
325 #[serde(default = "default_true")]
326 pub maintainer_can_modify: bool,
327}
328
329fn default_true() -> bool {
330 true
331}
332
333#[derive(Debug, Clone, Serialize, Deserialize)]
334pub struct MergePullRequestParams {
335 pub owner: String,
336 pub repo: String,
337 pub pull_number: u64,
338 pub commit_title: Option<String>,
339 pub commit_message: Option<String>,
340 #[serde(default)]
341 pub merge_method: MergeMethod,
342 pub sha: Option<String>,
343}
344
345#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
346#[serde(rename_all = "lowercase")]
347pub enum MergeMethod {
348 #[default]
349 Merge,
350 Squash,
351 Rebase,
352}
353
354#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
355#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
356pub enum ReviewState {
357 Approved,
358 ChangesRequested,
359 Commented,
360 Dismissed,
361 Pending,
362}
363
364#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
365#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
366pub enum ReviewEvent {
367 Approve,
368 RequestChanges,
369 Comment,
370}
371
372#[derive(Debug, Clone, Serialize, Deserialize)]
373pub struct GitHubReview {
374 pub id: u64,
375 pub user: GitHubUser,
376 pub body: Option<String>,
377 pub state: ReviewState,
378 pub commit_id: String,
379 pub html_url: String,
380 pub submitted_at: Option<String>,
381}
382
383#[derive(Debug, Clone, Serialize, Deserialize)]
384pub struct CreateReviewParams {
385 pub owner: String,
386 pub repo: String,
387 pub pull_number: u64,
388 pub body: Option<String>,
389 pub event: ReviewEvent,
390 pub commit_id: Option<String>,
391 #[serde(default)]
392 pub comments: Vec<ReviewCommentInput>,
393}
394
395#[derive(Debug, Clone, Serialize, Deserialize)]
396pub struct ReviewCommentInput {
397 pub path: String,
398 pub line: u32,
399 pub body: String,
400 #[serde(default)]
401 pub side: DiffSide,
402 pub start_line: Option<u32>,
403 pub start_side: Option<DiffSide>,
404}
405
406#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
407#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
408pub enum DiffSide {
409 Left,
410 #[default]
411 Right,
412}
413
414#[derive(Debug, Clone, Serialize, Deserialize)]
415pub struct GitHubComment {
416 pub id: u64,
417 pub body: String,
418 pub user: GitHubUser,
419 pub created_at: String,
420 pub updated_at: String,
421 pub html_url: String,
422}
423
424#[derive(Debug, Clone, Serialize, Deserialize)]
425pub struct CreateCommentParams {
426 pub owner: String,
427 pub repo: String,
428 pub issue_number: u64,
429 pub body: String,
430}
431
432#[derive(Debug, Clone, Serialize, Deserialize)]
433pub struct GitHubBranch {
434 pub name: String,
435 pub sha: String,
436 #[serde(default)]
437 pub protected: bool,
438}
439
440#[derive(Debug, Clone, Serialize, Deserialize)]
441pub struct CreateBranchParams {
442 pub owner: String,
443 pub repo: String,
444 pub branch_name: String,
445 pub from_ref: String,
446}
447
448#[derive(Debug, Clone, Serialize, Deserialize)]
449pub struct GitHubCommitAuthor {
450 pub name: String,
451 pub email: String,
452 pub date: String,
453}
454
455#[derive(Debug, Clone, Serialize, Deserialize)]
456pub struct GitHubCommit {
457 pub sha: String,
458 pub message: String,
459 pub author: GitHubCommitAuthor,
460 pub committer: GitHubCommitAuthor,
461 pub timestamp: String,
462 pub html_url: String,
463 #[serde(default)]
464 pub parents: Vec<String>,
465}
466
467#[derive(Debug, Clone, Serialize, Deserialize)]
468pub struct CreateCommitParams {
469 pub owner: String,
470 pub repo: String,
471 pub message: String,
472 pub files: Vec<FileChange>,
473 pub branch: String,
474 pub parent_sha: Option<String>,
475 pub author_name: Option<String>,
476 pub author_email: Option<String>,
477}
478
479#[derive(Debug, Clone, Serialize, Deserialize)]
480pub struct GitHubFileContent {
481 pub name: String,
482 pub path: String,
483 pub content: String,
484 pub sha: String,
485 pub size: u64,
486 #[serde(rename = "type")]
487 pub file_type: FileType,
488 pub encoding: String,
489 pub html_url: String,
490 pub download_url: Option<String>,
491}
492
493#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
494#[serde(rename_all = "lowercase")]
495pub enum FileType {
496 File,
497 Dir,
498 Symlink,
499 Submodule,
500}
501
502#[derive(Debug, Clone, Serialize, Deserialize)]
503pub struct GitHubDirectoryEntry {
504 pub name: String,
505 pub path: String,
506 pub sha: String,
507 pub size: u64,
508 #[serde(rename = "type")]
509 pub entry_type: FileType,
510 pub html_url: String,
511 pub download_url: Option<String>,
512}
513
514#[derive(Debug, Clone, Serialize, Deserialize)]
515pub struct GitHubRepository {
516 pub id: u64,
517 pub name: String,
518 pub full_name: String,
519 pub owner: GitHubUser,
520 pub description: Option<String>,
521 pub private: bool,
522 pub fork: bool,
523 pub default_branch: String,
524 pub language: Option<String>,
525 pub stargazers_count: u32,
526 pub forks_count: u32,
527 pub open_issues_count: u32,
528 pub watchers_count: u32,
529 pub html_url: String,
530 pub clone_url: String,
531 pub ssh_url: String,
532 pub created_at: String,
533 pub updated_at: String,
534 pub pushed_at: String,
535 #[serde(default)]
536 pub topics: Vec<String>,
537 pub license: Option<GitHubLicense>,
538}
539
540#[derive(Debug, Clone, Serialize, Deserialize)]
541pub struct GitHubLicense {
542 pub key: String,
543 pub name: String,
544 pub spdx_id: Option<String>,
545 pub url: Option<String>,
546}
547
548#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
549#[serde(rename_all = "snake_case")]
550pub enum GitHubEventType {
551 Push,
552 PullRequest,
553 PullRequestReview,
554 PullRequestReviewComment,
555 Issues,
556 IssueComment,
557 Create,
558 Delete,
559 Fork,
560 Star,
561 Watch,
562 Release,
563 WorkflowRun,
564 CheckRun,
565 CheckSuite,
566 Status,
567}