From bc2e1870f5901ad1e7cc99cfb6f0f9c33a65d2b0 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Wed, 22 Feb 2023 18:10:14 +0530 Subject: [PATCH] feat: convert publiccodeyml::Repository to db::AddRepository --- federate/publiccodeyml/src/schema.rs | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/federate/publiccodeyml/src/schema.rs b/federate/publiccodeyml/src/schema.rs index 1a584ac..bfd5214 100644 --- a/federate/publiccodeyml/src/schema.rs +++ b/federate/publiccodeyml/src/schema.rs @@ -132,3 +132,38 @@ impl From<&db_core::AddRepository<'_>> for Repository { } } } + +impl Repository { + pub fn to_add_repository(&self, import: bool) -> AddRepository { + let tags = self + .intended_audience + .scope + .as_ref() + .map(|s| s.iter().map(|t| t.as_str()).collect()); + let description = self + .description + .get("en") + .as_ref() + .unwrap() + .short_description + .as_ref() + .map(|s| s.as_str()); + let website = self + .description + .get("en") + .unwrap() + .documentation + .as_ref() + .map(|s| s.as_str()); + AddRepository { + html_link: self.url.as_str(), + tags, + url: self.url.clone(), + name: &self.name, + owner: &self.legal.repo_owner, + description, + website, + import, + } + } +}