Allow plain strings for nixpkgs maintainer fields (#393)

* Allow plain strings for nixpkgs maintainer fields

* apply fmt to changed files
This commit is contained in:
Yannik Sander 2021-12-18 14:45:08 +01:00 committed by GitHub
parent 29651d086b
commit a4d8421312
Failed to generate hash of commit
2 changed files with 49 additions and 10 deletions

View file

@ -5,7 +5,9 @@ use std::path::PathBuf;
use crate::data::import::NixOption;
use log::error;
use pandoc::{InputFormat, InputKind, OutputFormat, OutputKind, PandocOption, PandocOutput, PandocError};
use pandoc::{
InputFormat, InputKind, OutputFormat, OutputKind, PandocError, PandocOption, PandocOutput,
};
use serde::{Deserialize, Serialize};
use super::{
@ -216,10 +218,13 @@ impl From<import::NixpkgsEntry> for Derivation {
.map(|l: &License| l.fullName.to_owned())
.collect();
let package_maintainers = package
let package_maintainers: Vec<Maintainer> = package
.meta
.maintainers
.map_or(Default::default(), Flatten::flatten);
.map_or(Default::default(), Flatten::flatten)
.into_iter()
.map(Into::into)
.collect();
let package_maintainers_set = package_maintainers
.iter()
@ -316,7 +321,10 @@ impl From<import::NixOption> for Derivation {
PandocOption::LuaFilter(man_filter),
]);
let result = pandoc.execute().expect(&format!("Pandoc could not parse documentation of '{}'", name));
let result = pandoc.execute().expect(&format!(
"Pandoc could not parse documentation of '{}'",
name
));
match result {
PandocOutput::ToBuffer(description) => Some(description),
@ -342,7 +350,33 @@ impl From<import::NixOption> for Derivation {
}
}
type Maintainer = import::Maintainer;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Maintainer {
name: Option<String>,
github: Option<String>,
email: Option<String>,
}
impl From<import::Maintainer> for Maintainer {
fn from(import: import::Maintainer) -> Self {
match import {
import::Maintainer::Full {
name,
github,
email,
} => Maintainer {
name,
github,
email,
},
import::Maintainer::Simple(name) => Maintainer {
name: Some(name),
github: None,
email: None,
},
}
}
}
impl From<super::Flake> for Maintainer {
fn from(flake: super::Flake) -> Self {

View file

@ -98,10 +98,14 @@ pub struct Meta {
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Maintainer {
pub name: Option<String>,
pub github: Option<String>,
pub email: Option<String>,
#[serde(untagged)]
pub enum Maintainer {
Full {
name: Option<String>,
github: Option<String>,
email: Option<String>,
},
Simple(String),
}
arg_enum! {
@ -267,7 +271,8 @@ mod tests {
"github": "AndersonTorres",
"githubId": 5954806,
"name": "Anderson Torres"
}
},
"Fred Flintstone"
],
"name": "0verkill-unstable-2011-01-13",
"outputsToInstall": [