-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Alokit-Innovations/tr/settings
Implement settings for auto assign and comment
- Loading branch information
Showing
6 changed files
with
120 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ mod config; | |
pub mod webhook; | ||
pub mod user; | ||
pub mod hunk; | ||
pub mod review; | ||
pub mod review; | ||
pub mod repo_config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use sled::IVec; | ||
|
||
use crate::db::config::get_db; | ||
use crate::utils::repo_config::RepoConfig; | ||
|
||
pub fn save_repo_config_to_db(repo_config: &RepoConfig, | ||
repo_name: &str, repo_owner: &str, repo_provider: &str) { | ||
let db = get_db(); | ||
let config_key = format!("{}/{}/{}/config", repo_provider, repo_owner, repo_name); | ||
println!("config_key = {}", &config_key); | ||
|
||
// Serialize repo struct to JSON | ||
let parse_res = serde_json::to_vec(repo_config); | ||
if parse_res.is_err() { | ||
let e = parse_res.expect_err("Empty error in parse_res in save_repo_config_to_db"); | ||
eprintln!("Unable to serialize repo in save_repo_config_to_db: {:?}, error: {:?}", &repo_config, e); | ||
return; | ||
} | ||
let config_json = parse_res.expect("Uncaught error in parse_res save_repo_config_to_db"); | ||
// Insert JSON into sled DB | ||
let insert_res = db.insert(IVec::from(config_key.as_bytes()), config_json); | ||
if insert_res.is_err() { | ||
let e = insert_res.expect_err("No error in insert_res save_repo_config_to_db"); | ||
eprintln!("Failed to upsert repo config into sled DB: {:?}", e); | ||
return; | ||
} | ||
println!("Repo Config succesfully upserted: {:?}", repo_config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct RepoConfig { | ||
comment: bool, | ||
auto_assign: bool | ||
} | ||
|
||
impl RepoConfig { | ||
// Getters | ||
pub fn comment(&self) -> bool { | ||
self.comment | ||
} | ||
|
||
pub fn auto_assign(&self) -> bool { | ||
self.auto_assign | ||
} | ||
|
||
// Function to create a default RepoConfig | ||
pub fn default() -> Self { | ||
RepoConfig { | ||
comment: true, | ||
auto_assign: true | ||
} | ||
} | ||
} |