Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb2964d
commit d253f4d
Showing
6 changed files
with
59 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GH_GPT_GITHUB_TOKEN="..." | ||
GH_GPT_OPENAI_API_KEY="..." |
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 |
---|---|---|
|
@@ -15,5 +15,6 @@ Cargo.lock | |
|
||
|
||
# Added by cargo | ||
|
||
/target | ||
|
||
.env |
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 |
---|---|---|
@@ -1,14 +1,27 @@ | ||
//! General configuration | ||
|
||
/// Configuration for the application. | ||
#[derive(Debug, Default)] | ||
pub struct Config { | ||
pub api_keys: ApiKeys, | ||
} | ||
use color_eyre::eyre::Result; | ||
use config::Config; | ||
use serde_derive::Deserialize; | ||
|
||
/// Configuration for the API keys. | ||
#[derive(Debug, Default)] | ||
pub struct ApiKeys { | ||
/// Configuration for the application. | ||
#[derive(Debug, Default, Deserialize)] | ||
pub struct GhGptConfig { | ||
pub github_token: String, | ||
pub openai_api_key: String, | ||
} | ||
|
||
impl GhGptConfig { | ||
/// Create a new configuration from environment variables. | ||
pub fn new() -> Result<Self> { | ||
CONFIG.clone().try_deserialize().map_err(|e| e.into()) | ||
} | ||
} | ||
|
||
lazy_static::lazy_static! { | ||
#[derive(Debug)] | ||
pub static ref CONFIG: Config = Config::builder() | ||
.add_source(config::Environment::with_prefix("gh_gpt")) | ||
.build() | ||
.unwrap(); | ||
} |
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
//! Module related to Github labels. | ||
|
||
use color_eyre::eyre::Result; | ||
use log::debug; | ||
|
||
use crate::config::Config; | ||
use crate::config::GhGptConfig; | ||
|
||
/// Labelize a Github issue. | ||
/// # Arguments | ||
/// * `cfg` - The application configuration. | ||
/// * `gh_issue_number` - The Github issue number. | ||
pub fn labelize(_cfg: &Config, gh_issue_number: u64) { | ||
pub fn labelize(_cfg: &GhGptConfig, gh_issue_number: u64) -> Result<()> { | ||
debug!("labelize: {}", gh_issue_number); | ||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -1,32 +1,39 @@ | ||
#[macro_use] | ||
extern crate log; | ||
use clap::Parser; | ||
use color_eyre::eyre::Result; | ||
use dotenv::dotenv; | ||
use gh_gpt::cli::commands::{Cli, Commands}; | ||
use gh_gpt::config::Config; | ||
use gh_gpt::config::GhGptConfig; | ||
use gh_gpt::labels::labelize; | ||
|
||
fn main() { | ||
fn main() -> Result<()> { | ||
// Initialize the logger. | ||
env_logger::init(); | ||
|
||
// Initialize the error handler. | ||
color_eyre::install()?; | ||
|
||
// Load the environment variables from the .env file. | ||
dotenv()?; | ||
|
||
// Say hello. | ||
info!("hello from gh-gpt 🤖 !"); | ||
|
||
// Parse the command line arguments. | ||
let cli = Cli::parse(); | ||
|
||
// Retrieve the application configuration. | ||
let cfg = config(); | ||
let cfg = GhGptConfig::new()?; | ||
|
||
if let Some(command) = cli.command { | ||
match command { | ||
Commands::Labelize { gh_issue_number } => { | ||
labelize(&cfg, gh_issue_number); | ||
} | ||
// Execute the command. | ||
match cli.command { | ||
Some(command) => match command { | ||
Commands::Labelize { gh_issue_number } => labelize(&cfg, gh_issue_number), | ||
}, | ||
None => { | ||
info!("nothing to do there, bye 👋"); | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
/// Parse and return the application configuration. | ||
fn config() -> Config { | ||
// TODO: Parse the configuration from the environment variables. | ||
Config::default() | ||
} |