Skip to content

Commit

Permalink
Execute check_deprecated() function only if github token is set
Browse files Browse the repository at this point in the history
  • Loading branch information
AristoChen committed Sep 3, 2020
1 parent 2da1f23 commit fcf231d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 9 additions & 1 deletion data/render/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut tools = read_tools(tools)?;
tools.sort();
validate(&tags, &tools)?;
tools = check_deprecated(&mut tools)?;

let token = env::var("GITHUB_TOKEN");
let token = match token {
Ok(token) => token,
Err(_error) => "".to_string(),
};
if token.len() > 0 {
tools = check_deprecated(token, &mut tools)?;
}

let catalog = group(&tags, tools)?;
println!("{}", catalog.render()?);
Expand Down
5 changes: 2 additions & 3 deletions data/render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ extern crate serde_derive;
use std::error::Error;
use hubcaps::{Credentials, Github};
use chrono::{Utc, NaiveDateTime};
use std::env;

mod lints;
pub mod types;
Expand All @@ -25,10 +24,10 @@ pub fn validate(tags: &Tags, entries: &Vec<Entry>) -> Result<(), Box<dyn Error>>
}

#[tokio::main]
pub async fn check_deprecated(entries: &mut Vec<Entry>) -> Result<Vec<Entry>, Box<dyn Error>> {
pub async fn check_deprecated(token: std::string::String, entries: &mut Vec<Entry>) -> Result<Vec<Entry>, Box<dyn Error>> {
let github = Github::new(
String::from("user-agent-name"),
env::var("GITHUB_TOKEN").ok().map(Credentials::Token),
Credentials::Token(token),
)?;

let mut entries_tmp: Vec<Entry> = entries.to_vec();
Expand Down

0 comments on commit fcf231d

Please sign in to comment.