Skip to content

Commit

Permalink
cleaner logic implementation to get env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvinsh committed Nov 8, 2023
1 parent 2223c79 commit 7eb19c8
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ use crate::{
use anyhow::Result;
use clap::{Args, CommandFactory, Parser};
use clap_complete::Shell;
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use reqwest::{Client, Error};
use tracing::{error, info};

fn create_reqwest_client() -> Result<Client, Error> {
// fetch env variable
let github_token = match std::env::var("GITHUB_TOKEN") {
Ok(token) => token,
Err(_) => String::new(),
};

let mut headers = reqwest::header::HeaderMap::new();
if !github_token.is_empty() {
let auth_header_value =
reqwest::header::HeaderValue::from_str(&format!("Bearer {}", github_token))
.expect("Invalid header value");
headers.insert(reqwest::header::AUTHORIZATION, auth_header_value);
let github_token = std::env::var("GITHUB_TOKEN");

let mut headers = HeaderMap::new();

if let Ok(github_token) = github_token {
headers.insert(
AUTHORIZATION,
HeaderValue::from_str(&format!("Bearer {}", github_token)).unwrap(),
);
}

let client = reqwest::Client::builder()
Expand Down

0 comments on commit 7eb19c8

Please sign in to comment.