summaryrefslogtreecommitdiff
path: root/crates/discord-bot/src/config.rs
diff options
context:
space:
mode:
authorseth <[email protected]>2024-10-10 07:26:29 -0400
committerGitHub <[email protected]>2024-10-10 07:26:29 -0400
commitc61b701095a1f6b52777d317275f34687e57ee3e (patch)
treee5b1e80fa8040b593aeebb9daf83bcc9d78c6e81 /crates/discord-bot/src/config.rs
parent4e1fab6ff1d17a0fff50e1a87af8c0bbe8c075f9 (diff)
rise once again my glorious creation (#51)
* git-tracker: update tips after fetch + cleanup * nix: use nix-filter * ci: cleanup * crates: update * git-tracker: don't spam log while transferring * nix: fix static package eval
Diffstat (limited to 'crates/discord-bot/src/config.rs')
-rw-r--r--crates/discord-bot/src/config.rs51
1 files changed, 34 insertions, 17 deletions
diff --git a/crates/discord-bot/src/config.rs b/crates/discord-bot/src/config.rs
index 5076eb9..afc7845 100644
--- a/crates/discord-bot/src/config.rs
+++ b/crates/discord-bot/src/config.rs
@@ -1,25 +1,21 @@
-use crate::consts::NIXPKGS_REMOTE;
+use git_tracker::TrackedRepository;
-use std::env;
+use std::{env, path::PathBuf, sync::Arc};
+
+const DEFAULT_NIXPKGS_URL: &str = "https://github.com/NixOS/nixpkgs";
+
+const DEFAULT_NIXPKGS_REMOTE: &str = "origin";
/// The Discord client's configuration
#[derive(Clone, Debug)]
pub struct Config {
- /// Path to clone a new or use an existing nixpkgs repository
- pub nixpkgs_path: String,
- // A comma separated list of nixpkgs branch to track commits for
- pub nixpkgs_branches: Vec<String>,
+ /// Comma separated list of nixpkgs branch to track commits for
+ nixpkgs_branches: Vec<String>,
+ /// Repository tracker
+ repository: Arc<TrackedRepository>,
}
impl Config {
- /// Take in a comma separated list and split it into a [`Vec<String>`]
- fn split_string_list(branches: &str) -> Vec<String> {
- branches
- .split(',')
- .map(|branch| format!("{NIXPKGS_REMOTE}/{}", branch.trim()))
- .collect()
- }
-
/// Create a new instance of [`Config`] based on variables from the environment
///
/// # Errors
@@ -27,12 +23,33 @@ impl Config {
/// Will return [`Err`] if a variable is not found
pub fn from_env() -> Result<Self, env::VarError> {
let nixpkgs_path = env::var("BOT_NIXPKGS_PATH")?;
- let nixpkgs_branches_raw = env::var("BOT_NIXPKGS_BRANCHES")?;
- let nixpkgs_branches = Self::split_string_list(&nixpkgs_branches_raw);
+
+ let nixpkgs_branches = env::var("BOT_NIXPKGS_BRANCHES")?
+ .split(',')
+ .map(ToString::to_string)
+ .collect();
+
+ let nixpkgs_remote =
+ env::var("BOT_NIXPKGS_REMOTE").unwrap_or(DEFAULT_NIXPKGS_REMOTE.to_string());
+ let nixpkgs_url = env::var("BOT_NIXPKGS_URL").unwrap_or(DEFAULT_NIXPKGS_URL.to_string());
+
+ let repository = TrackedRepository::new(
+ PathBuf::from(nixpkgs_path.clone()),
+ nixpkgs_url,
+ nixpkgs_remote,
+ );
Ok(Self {
- nixpkgs_path,
nixpkgs_branches,
+ repository: Arc::new(repository),
})
}
+
+ pub fn repository(&self) -> &TrackedRepository {
+ &self.repository
+ }
+
+ pub fn nixpkgs_branches(&self) -> &Vec<String> {
+ &self.nixpkgs_branches
+ }
}