• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FlorianNAdam / nirion / #6

12 Jul 2026 11:10PM UTC coverage: 75.524%. Remained the same
#6

push

web-flow
chore: migrate YAML parsing to serde_yaml_ng (#11)

2 of 3 new or added lines in 2 files covered. (66.67%)

1009 of 1336 relevant lines covered (75.52%)

9.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/nirion-lib/src/patch.rs
1
use std::{collections::BTreeMap, fs, process::Stdio};
2

3
use anyhow::{Context, Result};
4
use serde::Deserialize;
5
use tokio::process::Command;
6

7
use crate::projects::{Projects, TargetSelector};
8

9
#[derive(Clone, Debug, PartialEq, Eq)]
10
pub enum PatchTarget {
11
    EnvFile,
12
    Compose,
13
}
14

15
pub async fn patch_target(
×
16
    target: &TargetSelector,
17
    projects: &Projects,
18
    patch_target: &PatchTarget,
19
) -> Result<()> {
20
    match target {
×
21
        TargetSelector::All => {
22
            anyhow::bail!("Only individual projects can be patched");
×
23
        }
24

25
        TargetSelector::Project(proj) => {
×
26
            if patch_target == &PatchTarget::EnvFile {
×
27
                anyhow::bail!(
×
28
                    "Only individual service env files can be patched"
×
29
                );
30
            }
31

32
            let project = &projects[&proj.name];
×
33
            patch(&project.docker_compose).await?;
×
34
        }
35

36
        TargetSelector::Service(img) => {
×
37
            let project = &projects[&img.project];
×
38

39
            match patch_target {
×
40
                PatchTarget::Compose => {
41
                    patch(&project.docker_compose).await?;
×
42
                }
43

44
                PatchTarget::EnvFile => {
45
                    let compose =
×
46
                        load_compose_env_files(&project.docker_compose)?;
×
47

48
                    let service = compose.services.get(&img.service).with_context(|| {
×
49
                        format!(
×
50
                            "Service `{}` not found in compose file for project `{}`",
×
51
                            img.service, img.project
52
                        )
53
                    })?;
54

55
                    let env_file =
×
56
                        service
×
57
                            .env_file
×
58
                            .first()
59
                            .with_context(|| {
×
60
                                format!(
×
61
                                    "No env_file found for `{}.{}`",
×
62
                                    img.project, img.service
63
                                )
64
                            })?;
65

66
                    patch(env_file).await?;
×
67
                }
68
            }
69
        }
70
    }
71

72
    Ok(())
×
73
}
74

75
fn load_compose_env_files(path: &str) -> anyhow::Result<ComposeFile> {
×
76
    let data = fs::read_to_string(path)
×
77
        .with_context(|| format!("Failed reading {}", path))?;
×
78

NEW
79
    serde_yaml_ng::from_str::<ComposeFile>(&data)
×
80
        .with_context(|| format!("Compose file parse error in {}", path))
×
81
}
82

83
#[derive(Debug, Deserialize)]
84
struct ComposeFile {
85
    services: BTreeMap<String, Service>,
86
}
87

88
#[derive(Debug, Deserialize)]
89
struct Service {
90
    #[serde(default)]
91
    env_file: Vec<String>,
92
}
93

94
pub async fn patch(file: &str) -> Result<()> {
×
95
    let status = Command::new("sudo")
×
96
        .arg("mirage-patch")
97
        .arg(file)
×
98
        .stdin(Stdio::inherit())
×
99
        .stdout(Stdio::inherit())
×
100
        .stderr(Stdio::inherit())
×
101
        .status()
102
        .await
×
103
        .context("failed to spawn mirage-patch")?;
104

105
    if !status.success() {
×
106
        anyhow::bail!("mirage-patch exited with status: {}", status);
×
107
    }
108

109
    Ok(())
×
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc