dev_scope/shared/models/internal/
upload_location.rs

1use crate::models::prelude::{ModelMetadata, V1AlphaReportLocation};
2use crate::models::HelpMetadata;
3
4#[derive(Debug, PartialEq, Clone)]
5pub enum ReportUploadLocationDestination {
6    RustyPaste {
7        url: String,
8    },
9    GithubIssue {
10        owner: String,
11        repo: String,
12        tags: Vec<String>,
13    },
14}
15#[derive(Debug, PartialEq, Clone)]
16pub struct ReportUploadLocation {
17    pub metadata: ModelMetadata,
18    pub full_name: String,
19    pub destination: ReportUploadLocationDestination,
20}
21
22impl HelpMetadata for ReportUploadLocation {
23    fn metadata(&self) -> &ModelMetadata {
24        &self.metadata
25    }
26
27    fn full_name(&self) -> String {
28        self.full_name.to_string()
29    }
30}
31
32impl TryFrom<V1AlphaReportLocation> for ReportUploadLocation {
33    type Error = anyhow::Error;
34
35    fn try_from(value: V1AlphaReportLocation) -> Result<Self, Self::Error> {
36        let destination = match value.spec.destination {
37            crate::models::prelude::ReportDestinationSpec::RustyPaste(ref def) => {
38                ReportUploadLocationDestination::RustyPaste {
39                    url: def.url.to_string(),
40                }
41            }
42            crate::models::prelude::ReportDestinationSpec::GithubIssue(ref github_issue) => {
43                ReportUploadLocationDestination::GithubIssue {
44                    owner: github_issue.owner.to_string(),
45                    repo: github_issue.repo.to_string(),
46                    tags: github_issue.tags.clone(),
47                }
48            }
49        };
50        Ok(ReportUploadLocation {
51            full_name: value.full_name(),
52            metadata: value.metadata,
53            destination,
54        })
55    }
56}