Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,26 @@ impl ClientConfig {
}
}

// impl From<GlimConfig> for ClientConfig {
// fn from(config: GlimConfig) -> Self {
// Self::new(config.gitlab_url, config.gitlab_token).with_search_filter(config.search_filter)
// }
// }
//
impl From<GlimConfig> for ClientConfig {
fn from(config: GlimConfig) -> Self {
Self::new(config.gitlab_url, config.gitlab_token).with_search_filter(config.search_filter)
let token = if let Some(token_file) = &config.gitlab_token_file {
std::fs::read_to_string(token_file)
.map(|s| s.trim().to_string())
.unwrap_or_else(|e| {
tracing::warn!("Failed to read token file {:?}: {}", token_file, e);
config.gitlab_token.to_string()
})
} else {
config.gitlab_token.to_string()
};

Self::new(config.gitlab_url, token).with_search_filter(config.search_filter)
}
}

Expand Down Expand Up @@ -354,6 +371,7 @@ mod tests {
let glim_config = GlimConfig {
gitlab_url: "https://gitlab.example.com".into(),
gitlab_token: "test-token".into(),
gitlab_token_file: None,
search_filter: Some("test".into()),
log_level: Some("Off".into()),
animations: true,
Expand Down
3 changes: 3 additions & 0 deletions src/glim_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub struct GlimConfig {
pub gitlab_url: CompactString,
/// The Personal Access Token to authenticate with GitLab
pub gitlab_token: CompactString,
#[serde(default)]
pub gitlab_token_file: Option<PathBuf>,
/// Filter applied to the projects list
pub search_filter: Option<CompactString>,
/// Logging level: Off, Error, Warn, Info, Debug, Trace
Expand All @@ -56,6 +58,7 @@ impl Default for GlimConfig {
Self {
gitlab_url: "https://".into(),
gitlab_token: "".into(),
gitlab_token_file: None,
search_filter: None,
log_level: Some("Error".into()),
animations: true,
Expand Down
14 changes: 10 additions & 4 deletions src/ui/popup/config_popup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::vec;
use std::{path::PathBuf, vec};

use compact_str::{CompactString, ToCompactString};
use ratatui::{
Expand Down Expand Up @@ -164,9 +164,14 @@ impl ConfigPopupState {
.unwrap_or(&"")
.trim()
.to_compact_string();
let search_filter_value = values.get(2).unwrap_or(&"").trim();
let log_level_value = values.get(3).unwrap_or(&"Off").trim();
let animations_value = values.get(4).unwrap_or(&"true").trim();
let gitlab_token_file = values
.get(2)
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.map(|s| PathBuf::from(s));
let search_filter_value = values.get(3).unwrap_or(&"").trim();
let log_level_value = values.get(4).unwrap_or(&"Off").trim();
let animations_value = values.get(5).unwrap_or(&"true").trim();

let search_filter = if search_filter_value.is_empty() {
None
Expand All @@ -185,6 +190,7 @@ impl ConfigPopupState {
GlimConfig {
gitlab_url,
gitlab_token,
gitlab_token_file,
search_filter,
log_level,
animations,
Expand Down