Skip to content

Commit 96d8499

Browse files
committed
Add function for deserializing repository config
1 parent d427d93 commit 96d8499

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/config.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ pub struct RepositoryConfig {
3838
pub merge_queue_enabled: bool,
3939
}
4040

41+
/// Load a repository config from TOML.
42+
pub fn deserialize_config(text: &str) -> Result<RepositoryConfig, toml::de::Error> {
43+
toml::from_str(text)
44+
}
45+
4146
fn default_timeout() -> Duration {
4247
Duration::from_secs(3600)
4348
}
@@ -150,10 +155,9 @@ where
150155

151156
#[cfg(test)]
152157
mod tests {
158+
use crate::config::{RepositoryConfig, default_timeout, deserialize_config};
153159
use std::{collections::BTreeMap, time::Duration};
154160

155-
use crate::config::{RepositoryConfig, default_timeout};
156-
157161
#[test]
158162
fn deserialize_empty() {
159163
let content = "";
@@ -275,6 +279,6 @@ approved = ["foo"]
275279
}
276280

277281
fn load_config(config: &str) -> RepositoryConfig {
278-
toml::from_str(config).unwrap()
282+
deserialize_config(config).expect("Cannot deserialize repository config")
279283
}
280284
}

src/github/api/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tracing::log;
99

1010
use crate::bors::event::PullRequestComment;
1111
use crate::bors::{Comment, WorkflowRun};
12-
use crate::config::{CONFIG_FILE_PATH, RepositoryConfig};
12+
use crate::config::{CONFIG_FILE_PATH, RepositoryConfig, deserialize_config};
1313
use crate::database::WorkflowStatus;
1414
use crate::github::api::operations::{
1515
BranchUpdateError, ForcePush, MergeError, create_check_run, merge_branches,
@@ -83,7 +83,7 @@ impl GithubRepositoryClient {
8383
.ok_or_else(|| anyhow::anyhow!("Configuration file not found"))
8484
.and_then(|content| {
8585
let config: RepositoryConfig =
86-
toml::from_str(&content).map_err(|error| {
86+
deserialize_config(&content).map_err(|error| {
8787
anyhow::anyhow!(
8888
"Could not deserialize repository config: {error:?}"
8989
)

0 commit comments

Comments
 (0)