feat: read token from environment

This commit is contained in:
Patrick 2024-07-14 20:45:22 +02:00
parent 46ab80a7ac
commit bacb6b4b9a
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F

View file

@ -53,9 +53,13 @@ struct Config {
static CONFIG: Lazy<Config> = Lazy::new(Config::from_args);
static GITHUB_TOKEN: Lazy<OsString> = Lazy::new(|| {
use std::env;
use std::io::{stdin, BufRead, BufReader};
use std::os::unix::prelude::*;
match env::var_os("PR_TRACKER_GITHUB_TOKEN") {
Some(token) => token,
None => {
let mut bytes = Vec::with_capacity(41);
if let Err(e) = BufReader::new(stdin()).read_until(b'\n', &mut bytes) {
eprintln!("pr-tracker: read: {}", e);
@ -65,6 +69,8 @@ static GITHUB_TOKEN: Lazy<OsString> = Lazy::new(|| {
bytes.pop();
}
OsString::from_vec(bytes)
}
}
});
#[derive(Debug, Default, Template)]