Skip to main content

octocrab/
params.rs

1//! # Common GitHub Parameter Types
2
3/// The status of a issue or pull request.
4#[derive(Debug, Clone, Copy, serde::Serialize)]
5#[serde(rename_all = "lowercase")]
6#[non_exhaustive]
7pub enum AlertState {
8    Dismissed,
9    Open,
10}
11
12/// The status of a issue or pull request.
13#[derive(Debug, Clone, Copy, serde::Serialize)]
14#[serde(rename_all = "lowercase")]
15#[non_exhaustive]
16pub enum State {
17    All,
18    Open,
19    Closed,
20}
21
22/// What to sort results by. Can be either `created`, `updated`, `popularity`
23/// (comment count) or `long-running` (age, filtering by pulls updated in the
24/// last month).
25#[derive(Debug, Clone, Copy, serde::Serialize)]
26#[serde(rename_all = "snake_case")]
27#[non_exhaustive]
28pub enum Direction {
29    #[serde(rename = "asc")]
30    Ascending,
31    #[serde(rename = "desc")]
32    Descending,
33}
34
35/// The reason for locking an issue.
36#[derive(Debug, Clone, Copy, serde::Serialize)]
37#[non_exhaustive]
38pub enum LockReason {
39    #[serde(rename = "off-topic")]
40    OffTopic,
41    #[serde(rename = "too heated")]
42    TooHeated,
43    #[serde(rename = "resolved")]
44    Resolved,
45    #[serde(rename = "spam")]
46    Spam,
47}
48
49pub mod actions {
50    //! Parameter types for the actions API.
51
52    /// The archive format for artifacts.
53    #[derive(Debug, Clone, Copy, serde::Serialize)]
54    #[serde(rename_all = "snake_case")]
55    #[non_exhaustive]
56    pub enum ArchiveFormat {
57        Zip,
58    }
59
60    impl std::fmt::Display for ArchiveFormat {
61        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
62            let text = match self {
63                Self::Zip => "zip",
64            };
65
66            f.write_str(text)
67        }
68    }
69
70    /// Configures the access that repositories have to the organization secret.
71    #[derive(Debug, Clone, Copy, serde::Serialize)]
72    #[serde(rename_all = "snake_case")]
73    #[non_exhaustive]
74    pub enum Visibility {
75        All,
76        Private,
77        Selected,
78    }
79}
80
81pub mod apps {
82    //! Parameter types for the apps API.
83
84    use crate::models::RepositoryId;
85
86    /// <https://docs.github.com/en/rest/reference/apps#create-an-installation-access-token-for-an-app>
87    #[derive(Debug, Clone, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize, Default)]
88    #[serde(rename_all = "snake_case")]
89    #[non_exhaustive]
90    pub struct CreateInstallationAccessToken {
91        pub repositories: Vec<String>,
92        pub repository_ids: Vec<RepositoryId>,
93    }
94}
95
96pub mod checks {
97    //! Parameter types for the checks API.
98
99    #[derive(Debug, Clone, Copy, serde::Serialize)]
100    #[serde(rename_all = "snake_case")]
101    pub enum CheckRunStatus {
102        Queued,
103        InProgress,
104        Completed,
105    }
106
107    #[derive(Debug, Clone, Copy, serde::Serialize)]
108    #[serde(rename_all = "snake_case")]
109    pub enum CheckRunConclusion {
110        Success,
111        Failure,
112        Neutral,
113        Cancelled,
114        TimedOut,
115        Skipped,
116        Stale,
117        ActionRequired,
118    }
119
120    #[derive(serde::Serialize)]
121    pub struct CheckRunOutput {
122        pub title: String,
123        pub summary: String,
124        #[serde(skip_serializing_if = "Option::is_none")]
125        pub text: Option<String>,
126        #[serde(skip_serializing_if = "Vec::is_empty")]
127        pub annotations: Vec<CheckRunOutputAnnotation>,
128        #[serde(skip_serializing_if = "Vec::is_empty")]
129        pub images: Vec<CheckRunOutputImage>,
130    }
131
132    #[derive(serde::Serialize)]
133    pub struct CheckRunOutputAnnotation {
134        pub path: String,
135        pub start_line: u32,
136        pub end_line: u32,
137        #[serde(skip_serializing_if = "Option::is_none")]
138        pub start_column: Option<u32>,
139        #[serde(skip_serializing_if = "Option::is_none")]
140        pub end_column: Option<u32>,
141        pub annotation_level: CheckRunOutputAnnotationLevel,
142        pub message: String,
143        #[serde(skip_serializing_if = "Option::is_none")]
144        pub title: Option<String>,
145        #[serde(skip_serializing_if = "Option::is_none")]
146        pub raw_details: Option<String>,
147    }
148
149    #[derive(Debug, Clone, Copy, serde::Serialize)]
150    #[serde(rename_all = "snake_case")]
151    pub enum CheckRunOutputAnnotationLevel {
152        Notice,
153        Warning,
154        Failure,
155    }
156
157    #[derive(serde::Serialize)]
158    pub struct CheckRunOutputImage {
159        pub image_url: String,
160        pub alt: String,
161        #[serde(skip_serializing_if = "Option::is_none")]
162        pub caption: Option<String>,
163    }
164
165    #[derive(serde::Serialize, serde::Deserialize, Debug)]
166    pub struct CheckRunAnnotation {
167        pub path: String,
168        pub start_line: u32,
169        pub end_line: u32,
170        #[serde(skip_serializing_if = "Option::is_none")]
171        pub start_column: Option<u32>,
172        #[serde(skip_serializing_if = "Option::is_none")]
173        pub end_column: Option<u32>,
174        #[serde(skip_serializing_if = "Option::is_none")]
175        pub annotation_level: Option<String>,
176        #[serde(skip_serializing_if = "Option::is_none")]
177        pub title: Option<String>,
178        #[serde(skip_serializing_if = "Option::is_none")]
179        pub message: Option<String>,
180        #[serde(skip_serializing_if = "Option::is_none")]
181        pub raw_details: Option<String>,
182        pub blob_href: String,
183    }
184}
185
186pub mod code_scannings {
187    //! Parameter types for the code scanning API.
188
189    /// What to sort the results by. Can be either `created`, `updated`,
190    /// or `comments`.
191    #[derive(Debug, Clone, Copy, serde::Serialize)]
192    #[serde(rename_all = "snake_case")]
193    #[non_exhaustive]
194    pub enum Sort {
195        Created,
196        Updated,
197    }
198
199    /// The reference for the code scanning alert.
200    /// This can be a branch, tag, or commit.
201    #[derive(Debug, Clone, serde::Serialize)]
202    #[serde(rename_all = "snake_case")]
203    #[non_exhaustive]
204    pub enum Reference {
205        Branch(String),
206        Tag(String),
207        Commit(String),
208    }
209
210    /// The severity of the alert.
211    #[derive(Debug, Clone, Copy, serde::Serialize)]
212    #[serde(rename_all = "snake_case")]
213    #[non_exhaustive]
214    pub enum Severity {
215        Info,
216        Low,
217        Medium,
218        High,
219        Critical,
220    }
221
222    /// A generic filter type that allows you to filter either by exact match,
223    /// any match, or no matches.
224    #[derive(Debug, Clone, Copy)]
225    #[non_exhaustive]
226    pub enum Filter<T> {
227        Matches(T),
228        Any,
229        None,
230    }
231
232    impl<T: serde::Serialize> serde::Serialize for crate::params::code_scannings::Filter<T> {
233        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
234        where
235            S: serde::Serializer,
236        {
237            match self {
238                Self::Matches(val) => val.serialize(serializer),
239                Self::Any => serializer.serialize_str("*"),
240                Self::None => serializer.serialize_str("none"),
241            }
242        }
243    }
244
245    impl<T: serde::Serialize> From<T> for crate::params::code_scannings::Filter<T> {
246        fn from(value: T) -> Self {
247            Self::Matches(value)
248        }
249    }
250
251    #[cfg(test)]
252    mod tests {
253
254        #[test]
255        fn serialize() {
256            assert_eq!(
257                "1234",
258                serde_json::to_string(&crate::params::code_scannings::Filter::Matches(1234))
259                    .unwrap()
260            );
261            assert_eq!(
262                r#""*""#,
263                serde_json::to_string(&crate::params::code_scannings::Filter::<()>::Any).unwrap()
264            );
265            assert_eq!(
266                r#""none""#,
267                serde_json::to_string(&crate::params::code_scannings::Filter::<()>::None).unwrap()
268            );
269        }
270    }
271}
272
273pub mod issues {
274    //! Parameter types for the issues API.
275
276    /// What to sort the results by. Can be either `created`, `updated`,
277    /// or `comments`.
278    #[derive(Debug, Clone, Copy, serde::Serialize)]
279    #[serde(rename_all = "snake_case")]
280    #[non_exhaustive]
281    pub enum Sort {
282        Created,
283        Updated,
284        Comments,
285    }
286
287    /// A generic filter type that allows you to filter either by exact match,
288    /// any match, or no matches.
289    #[derive(Debug, Clone, Copy)]
290    #[non_exhaustive]
291    pub enum Filter<T> {
292        Matches(T),
293        Any,
294        None,
295    }
296
297    impl<T: serde::Serialize> serde::Serialize for Filter<T> {
298        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
299        where
300            S: serde::Serializer,
301        {
302            match self {
303                Self::Matches(val) => val.serialize(serializer),
304                Self::Any => serializer.serialize_str("*"),
305                Self::None => serializer.serialize_str("none"),
306            }
307        }
308    }
309
310    impl<T: serde::Serialize> From<T> for Filter<T> {
311        fn from(value: T) -> Self {
312            Self::Matches(value)
313        }
314    }
315
316    #[cfg(test)]
317    mod tests {
318        use super::*;
319
320        #[test]
321        fn serialize() {
322            assert_eq!(
323                "1234",
324                serde_json::to_string(&Filter::Matches(1234)).unwrap()
325            );
326            assert_eq!(
327                r#""milestone""#,
328                serde_json::to_string(&Filter::Matches("milestone")).unwrap()
329            );
330            assert_eq!(r#""*""#, serde_json::to_string(&Filter::<()>::Any).unwrap());
331            assert_eq!(
332                r#""none""#,
333                serde_json::to_string(&Filter::<()>::None).unwrap()
334            );
335        }
336    }
337}
338
339pub mod markdown {
340    /// The rendering mode.
341    #[derive(Debug, Clone, Copy, serde::Serialize)]
342    #[serde(rename_all = "lowercase")]
343    #[non_exhaustive]
344    pub enum Mode {
345        /// Render a document in plain Markdown, just like README.md files
346        /// are rendered.
347        Markdown,
348        /// Render a document in [GitHub Flavored Markdown][gfm], which creates
349        /// links for user mentions as well as references to SHA-1 hashes,
350        /// issues, and pull requests.
351        ///
352        /// [gfm]: https://github.github.com/gfm/
353        Gfm,
354    }
355}
356
357pub mod orgs {
358    //! Parameter types for the organization API.
359
360    /// What to sort results by. Can be either `created`, `updated`, `popularity`
361    /// (comment count) or `long-running` (age, filtering by pulls updated in the
362    /// last month).
363    #[derive(Debug, Clone, Copy, serde::Serialize)]
364    #[serde(rename_all = "snake_case")]
365    #[non_exhaustive]
366    pub enum Role {
367        Member,
368        Admin,
369    }
370}
371
372pub mod pulls {
373    //! Parameter types for the pull request API.
374
375    /// What to sort results by. Can be either `created`, `updated`, `popularity`
376    /// (comment count) or `long-running` (age, filtering by pulls updated in the
377    /// last month).
378    #[derive(Debug, Clone, Copy, serde::Serialize)]
379    #[serde(rename_all = "snake_case")]
380    #[non_exhaustive]
381    pub enum Sort {
382        Created,
383        Updated,
384        Popularity,
385        LongRunning,
386    }
387
388    /// Custom media types are used in the API to let consumers choose the
389    ///
390    /// format of the data they wish to receive. This is done by adding one or
391    /// more of the following types to the Accept header when you make a
392    /// request. Media types are specific to resources, allowing them to change
393    /// independently and support formats that other resources don't.
394    #[derive(Debug, Clone, Copy, serde::Serialize)]
395    #[serde(rename_all = "lowercase")]
396    #[non_exhaustive]
397    pub enum MediaType {
398        Raw,
399        Text,
400        Html,
401        Full,
402    }
403
404    impl std::fmt::Display for MediaType {
405        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
406            let text = match self {
407                Self::Raw => "raw",
408                Self::Text => "text",
409                Self::Html => "html",
410                Self::Full => "full",
411            };
412
413            f.write_str(text)
414        }
415    }
416
417    #[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
418    #[serde(rename_all = "snake_case")]
419    #[non_exhaustive]
420    pub enum MergeMethod {
421        Merge,
422        Squash,
423        Rebase,
424    }
425
426    #[derive(Debug, Clone, Copy, serde::Serialize)]
427    #[serde(rename_all = "lowercase")]
428    #[non_exhaustive]
429    pub enum State {
430        Open,
431        Closed,
432    }
433
434    pub mod comments {
435        /// What to sort results by. Can be either `created` or `updated`.
436        #[derive(Debug, Clone, Copy, serde::Serialize)]
437        #[serde(rename_all = "snake_case")]
438        #[non_exhaustive]
439        pub enum Sort {
440            Created,
441            Updated,
442        }
443    }
444}
445
446pub mod repos {
447    /// The type of repository to search for.
448    #[derive(Debug, Clone, Copy, serde::Serialize)]
449    #[serde(rename_all = "snake_case")]
450    #[non_exhaustive]
451    pub enum Type {
452        /// All repositories, usually the default.
453        All,
454        /// All forked rpositories.
455        Forks,
456        /// Only available if your organization is associated with an enterprise
457        /// account using GitHub Enterprise Cloud or GitHub Enterprise
458        /// Server 2.20+.
459        Internal,
460        /// All member repositories
461        Member,
462        ///  All private repositores
463        Private,
464        /// All public repositories
465        Public,
466        /// All source repostories (a repository that is not a fork).
467        Sources,
468    }
469
470    #[derive(Debug, Clone, Copy, serde::Serialize)]
471    #[serde(rename_all = "snake_case")]
472    #[non_exhaustive]
473    pub enum Sort {
474        Created,
475        Updated,
476        Pushed,
477        FullName,
478    }
479
480    /// A Git reference, either a branch, tag, or rev.
481    #[derive(Debug, Clone)]
482    pub enum Reference {
483        Branch(String),
484        Tag(String),
485    }
486
487    impl Reference {
488        pub fn ref_url(&self) -> String {
489            match self {
490                Self::Branch(branch) => format!("heads/{branch}"),
491                Self::Tag(tag) => format!("tags/{tag}"),
492            }
493        }
494
495        pub fn full_ref_url(&self) -> String {
496            format!("refs/{}", self.ref_url())
497        }
498    }
499
500    impl std::fmt::Display for Reference {
501        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
502            f.write_str(&self.full_ref_url())
503        }
504    }
505
506    /// A Git reference of unknown type.
507    ///
508    /// In some cases clients may have a string identifying a commit, but not
509    /// know whether it's a branch or a tag or commit hash.
510    /// Many Github APIs accept such strings. These APIs also accept `heads/` or `tags/`.
511    #[derive(Debug, Clone)]
512    pub struct Commitish(pub String);
513
514    impl From<Reference> for Commitish {
515        fn from(r: Reference) -> Commitish {
516            // Convert to `heads/` or `tags/` to avoid
517            // ambiguity since we know the type of the ref.
518            Commitish(r.ref_url())
519        }
520    }
521
522    impl From<String> for Commitish {
523        fn from(s: String) -> Commitish {
524            Commitish(s)
525        }
526    }
527
528    impl std::fmt::Display for Commitish {
529        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
530            f.write_str(&self.0)
531        }
532    }
533
534    pub mod forks {
535        /// The available methods to sort repository forks by.
536        #[derive(Debug, Clone, Copy, serde::Serialize)]
537        #[serde(rename_all = "snake_case")]
538        #[non_exhaustive]
539        pub enum Sort {
540            Newest,
541            Oldest,
542            Stargazers,
543        }
544    }
545
546    pub mod release_assets {
547
548        #[derive(Debug, Clone, Copy, serde::Serialize)]
549        #[serde(rename_all = "lowercase")]
550        #[non_exhaustive]
551        pub enum State {
552            Open,
553            Uploaded,
554            Starter,
555        }
556    }
557}
558
559pub mod teams {
560    #[derive(Debug, Clone, Copy, serde::Serialize)]
561    #[serde(rename_all = "snake_case")]
562    #[non_exhaustive]
563    pub enum Privacy {
564        Secret,
565        Closed,
566    }
567
568    #[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
569    #[serde(rename_all = "snake_case")]
570    #[non_exhaustive]
571    pub enum Permission {
572        Pull,
573        Push,
574        Admin,
575        Maintain,
576        Triage,
577    }
578}
579
580pub mod workflows {
581    #[derive(Debug, Clone, Copy, serde::Serialize)]
582    #[serde(rename_all = "snake_case")]
583    #[non_exhaustive]
584    pub enum Filter {
585        Latest,
586        All,
587    }
588}
589
590pub mod users {
591    //! Parameter types for the users API.
592
593    pub mod repos {
594        /// What ownership type to filter a user repository list by.
595        ///
596        /// See <https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-a-user>
597        #[derive(Debug, Clone, Copy, serde::Serialize)]
598        #[serde(rename_all = "snake_case")]
599        #[non_exhaustive]
600        pub enum Type {
601            All,
602            Owner,
603            Member,
604        }
605    }
606
607    pub mod emails {
608        use serde::{Deserialize, Serialize};
609
610        ///Denotes whether an email is publicly visible.
611        #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Copy)]
612        #[serde(rename_all = "snake_case")]
613        #[non_exhaustive]
614        pub enum EmailVisibilityState {
615            Public,
616            Private,
617        }
618    }
619}