Skip to content

Commit

Permalink
split
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Mar 25, 2024
1 parent 4f0cb00 commit 706126a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use nix_rs::{

use crate::{
config,
github::{self, PullRequest, PullRequestRef},
github::pull_request::{PullRequest, PullRequestRef},
nix::system_list::{SystemFlakeUrl, SystemsList},
};

Expand All @@ -27,7 +27,7 @@ pub enum FlakeRef {
impl FromStr for FlakeRef {
type Err = String;
fn from_str(s: &str) -> std::result::Result<FlakeRef, String> {
let flake_ref = match github::PullRequestRef::from_web_url(s) {
let flake_ref = match PullRequestRef::from_web_url(s) {
Some(pr) => FlakeRef::GithubPR(pr),
None => FlakeRef::Flake(FlakeUrl(s.to_string())),
};
Expand Down
37 changes: 37 additions & 0 deletions src/github/matrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// Enough types to get branch info from Pull Request URL
use itertools::iproduct;
use nix_rs::flake::system::System;
use serde::{Deserialize, Serialize};

use crate::config::Config;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GitHubMatrixRow {
pub system: System,
pub subflake: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GitHubMatrix {
pub include: Vec<GitHubMatrixRow>,
}

impl GitHubMatrix {
pub fn new(systems: Vec<System>, subflakes: Vec<String>) -> Self {
let include = iproduct!(systems, subflakes)
.map(|(system, subflake)| GitHubMatrixRow { system, subflake })
.collect();
GitHubMatrix { include }
}
}

pub(crate) async fn dump_github_actions_matrix(
cfg: &Config,
systems: Vec<System>,
) -> anyhow::Result<()> {
// TODO: Should take into account systems whitelist
// Ref: https://github.com/srid/nixci/blob/efc77c8794e5972617874edd96afa8dd4f1a75b2/src/config.rs#L104-L105
let matrix = GitHubMatrix::new(systems, cfg.subflakes.0.keys().cloned().collect());
println!("{}", serde_json::to_string(&matrix)?);
Ok(())
}
2 changes: 2 additions & 0 deletions src/github/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod matrix;
pub mod pull_request;
38 changes: 2 additions & 36 deletions src/github.rs → src/github/pull_request.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/// Enough types to get branch info from Pull Request URL
use anyhow::{bail, Context};
use itertools::iproduct;
use nix_rs::flake::{system::System, url::FlakeUrl};
use nix_rs::flake::url::FlakeUrl;
use reqwest::header::USER_AGENT;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use try_guard::guard;
use url::{Host, Url};

use crate::config::Config;

/// A reference to a Github Pull Request
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PullRequestRef {
Expand Down Expand Up @@ -106,34 +103,3 @@ where
bail!("cannot make request: {}", resp.status())
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GitHubMatrixRow {
pub system: System,
pub subflake: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GitHubMatrix {
pub include: Vec<GitHubMatrixRow>,
}

impl GitHubMatrix {
pub fn new(systems: Vec<System>, subflakes: Vec<String>) -> Self {
let include = iproduct!(systems, subflakes)
.map(|(system, subflake)| GitHubMatrixRow { system, subflake })
.collect();
GitHubMatrix { include }
}
}

pub(crate) async fn dump_github_actions_matrix(
cfg: &Config,
systems: Vec<System>,
) -> anyhow::Result<()> {
// TODO: Should take into account systems whitelist
// Ref: https://github.com/srid/nixci/blob/efc77c8794e5972617874edd96afa8dd4f1a75b2/src/config.rs#L104-L105
let matrix = GitHubMatrix::new(systems, cfg.subflakes.0.keys().cloned().collect());
println!("{}", serde_json::to_string(&matrix)?);
Ok(())
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn nixci(args: CliArgs) -> anyhow::Result<Vec<DrvOut>> {
match args.command {
cli::Command::Build(build_cfg) => nixci_build(args.verbose, &build_cfg, &url, &cfg).await,
cli::Command::DumpGithubActionsMatrix { systems, .. } => {
github::dump_github_actions_matrix(&cfg, systems).await?;
github::matrix::dump_github_actions_matrix(&cfg, systems).await?;
// TODO: Return something meaningful, or break the function.
Ok(vec![])
}
Expand Down

0 comments on commit 706126a

Please sign in to comment.