dev_scope/models/v1alpha/
report_location.rs

1use crate::models::core::ModelMetadata;
2use crate::models::v1alpha::V1AlphaApiVersion;
3use crate::models::{HelpMetadata, InternalScopeModel, ScopeModel};
4use derive_builder::Builder;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8/// How to load the report to GitHub Issue
9#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
10#[serde(rename_all = "camelCase")]
11#[schemars(deny_unknown_fields)]
12pub struct ReportDestinationGithubIssueSpec {
13    /// `owner` of the repository for the issue
14    pub owner: String,
15
16    /// `repo` the name of the repo for the issue
17    pub repo: String,
18
19    #[serde(default)]
20    /// A list of tags to be added to the issue
21    pub tags: Vec<String>,
22}
23
24/// How to upload a report to RustyPaste
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
26#[serde(rename_all = "camelCase")]
27#[schemars(deny_unknown_fields)]
28pub struct ReportDestinationRustyPasteSpec {
29    /// URL of RustyPaste
30    pub url: String,
31}
32
33#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
34#[serde(rename_all = "camelCase")]
35#[schemars(deny_unknown_fields)]
36pub enum ReportDestinationSpec {
37    RustyPaste(ReportDestinationRustyPasteSpec),
38    GithubIssue(ReportDestinationGithubIssueSpec),
39}
40
41/// Define where to upload the report to
42#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
43#[serde(rename_all = "camelCase")]
44#[schemars(deny_unknown_fields)]
45pub struct ReportLocationSpec {
46    #[serde(with = "serde_yaml::with::singleton_map")]
47    #[schemars(with = "ReportDestinationSpec")]
48    /// Destination the report should be uploaded to
49    pub destination: ReportDestinationSpec,
50}
51
52#[derive(Serialize, Deserialize, Debug, strum::Display, Clone, PartialEq, JsonSchema)]
53pub enum ReportLocationKind {
54    #[strum(serialize = "ScopeReportLocation")]
55    ScopeReportLocation,
56}
57
58/// A `ScopeReportLocation` tells where to upload a report to.
59#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Builder, JsonSchema)]
60#[builder(setter(into))]
61#[serde(rename_all = "camelCase")]
62#[schemars(deny_unknown_fields)]
63pub struct V1AlphaReportLocation {
64    /// API version of the resource
65    pub api_version: V1AlphaApiVersion,
66    /// The type of resource.
67    pub kind: ReportLocationKind,
68    /// Standard set of options including name, description for the resource.
69    /// Together `kind` and `metadata.name` are required to be unique. If there are duplicate, the
70    /// resources "closest" to the execution dir will take precedence.
71    pub metadata: ModelMetadata,
72    /// Options for the resource.
73    pub spec: ReportLocationSpec,
74}
75
76impl HelpMetadata for V1AlphaReportLocation {
77    fn metadata(&self) -> &ModelMetadata {
78        &self.metadata
79    }
80
81    fn full_name(&self) -> String {
82        format!("{}/{}", self.kind(), self.name())
83    }
84}
85
86impl ScopeModel<ReportLocationSpec> for V1AlphaReportLocation {
87    fn api_version(&self) -> String {
88        V1AlphaReportLocation::int_api_version()
89    }
90
91    fn kind(&self) -> String {
92        V1AlphaReportLocation::int_kind()
93    }
94
95    fn spec(&self) -> &ReportLocationSpec {
96        &self.spec
97    }
98}
99
100impl InternalScopeModel<ReportLocationSpec, V1AlphaReportLocation> for V1AlphaReportLocation {
101    fn int_api_version() -> String {
102        V1AlphaApiVersion::ScopeV1Alpha.to_string()
103    }
104
105    fn int_kind() -> String {
106        ReportLocationKind::ScopeReportLocation.to_string()
107    }
108    #[cfg(test)]
109    fn examples() -> Vec<String> {
110        vec![
111            "v1alpha/ReportLocation.github.yaml".to_string(),
112            "v1alpha/ReportLocation.rustyPaste.yaml".to_string(),
113        ]
114    }
115}