gitlab/api/
packages.rs

1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7//! Packages API types.
8//!
9//! These types are used for querying packages from projects or groups.
10
11use std::borrow::Cow;
12
13use super::ParamValue;
14
15/// Package Status
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17#[non_exhaustive]
18pub enum PackageStatus {
19    /// The default filter.
20    Default,
21    /// Return hidden packages.
22    Hidden,
23    /// Return in-progress packages.
24    Processing,
25    /// Return packages with errors.
26    Error,
27    /// Return packages which are pending destruction.
28    PendingDestruction,
29    /// Return packages which are deprecated.
30    Deprecated,
31}
32
33impl PackageStatus {
34    /// The scope as a query parameter.
35    pub(crate) fn as_str(self) -> &'static str {
36        match self {
37            PackageStatus::Default => "default",
38            PackageStatus::Hidden => "hidden",
39            PackageStatus::Processing => "processing",
40            PackageStatus::Error => "error",
41            PackageStatus::PendingDestruction => "pending_destruction",
42            PackageStatus::Deprecated => "deprecated",
43        }
44    }
45}
46
47impl ParamValue<'static> for PackageStatus {
48    fn as_value(&self) -> Cow<'static, str> {
49        self.as_str().into()
50    }
51}
52
53/// Package types
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55#[non_exhaustive]
56pub enum PackageType {
57    /// Return `conan` (C and C++) packages.
58    Conan,
59    /// Return `maven` (Java) packages.
60    Maven,
61    /// Return `npm` (NodeJS) packages.
62    Npm,
63    /// Return `pypi` (Python) packages.
64    Pypi,
65    /// Return `composer` (PHP) packages.
66    Composer,
67    /// Return `nuget` (C#) packages.
68    Nuget,
69    /// Return `helm` (Kubernetes) packages.
70    Helm,
71    /// Return `terraform` (Terraform) packages.
72    TerraformModule,
73    /// Return `golang` (Go) packages.
74    GoLang,
75}
76
77impl PackageType {
78    /// The scope as a query parameter.
79    pub(crate) fn as_str(self) -> &'static str {
80        match self {
81            PackageType::Conan => "conan",
82            PackageType::Maven => "maven",
83            PackageType::Npm => "npm",
84            PackageType::Pypi => "pypi",
85            PackageType::Composer => "composer",
86            PackageType::Nuget => "nuget",
87            PackageType::Helm => "helm",
88            PackageType::TerraformModule => "terraform_module",
89            PackageType::GoLang => "golang",
90        }
91    }
92}
93
94impl ParamValue<'static> for PackageType {
95    fn as_value(&self) -> Cow<'static, str> {
96        self.as_str().into()
97    }
98}
99
100#[cfg(test)]
101mod tests {
102    use super::{PackageStatus, PackageType};
103
104    #[test]
105    fn package_type_as_str() {
106        let items = &[
107            (PackageType::Conan, "conan"),
108            (PackageType::Maven, "maven"),
109            (PackageType::Npm, "npm"),
110            (PackageType::Pypi, "pypi"),
111            (PackageType::Composer, "composer"),
112            (PackageType::Nuget, "nuget"),
113            (PackageType::Helm, "helm"),
114            (PackageType::TerraformModule, "terraform_module"),
115            (PackageType::GoLang, "golang"),
116        ];
117
118        for (i, s) in items {
119            assert_eq!(i.as_str(), *s);
120        }
121    }
122
123    #[test]
124    fn package_status_as_str() {
125        let items = &[
126            (PackageStatus::Default, "default"),
127            (PackageStatus::Hidden, "hidden"),
128            (PackageStatus::Processing, "processing"),
129            (PackageStatus::Error, "error"),
130            (PackageStatus::PendingDestruction, "pending_destruction"),
131            (PackageStatus::Deprecated, "deprecated"),
132        ];
133
134        for (i, s) in items {
135            assert_eq!(i.as_str(), *s);
136        }
137    }
138}