From bacb6b4b9a0b348c73a194361f083731c58e3241 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 14 Jul 2024 20:45:22 +0200 Subject: [PATCH] feat: read token from environment --- src/main.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2ebcfee..d015742 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,18 +53,24 @@ struct Config { static CONFIG: Lazy = Lazy::new(Config::from_args); static GITHUB_TOKEN: Lazy = Lazy::new(|| { + use std::env; use std::io::{stdin, BufRead, BufReader}; use std::os::unix::prelude::*; - 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); - exit(74) + 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); + exit(74) + } + if bytes.last() == Some(&b'\n') { + bytes.pop(); + } + OsString::from_vec(bytes) + } } - if bytes.last() == Some(&b'\n') { - bytes.pop(); - } - OsString::from_vec(bytes) }); #[derive(Debug, Default, Template)]