From 0a11e2b03a157ac72835abffb283b17d818b0a5a Mon Sep 17 00:00:00 2001 From: AristoChen Date: Fri, 4 Sep 2020 21:59:09 +0800 Subject: [PATCH] Restructure code --- data/render/src/lib.rs | 83 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/data/render/src/lib.rs b/data/render/src/lib.rs index fe52c32ca..7091e9f2c 100644 --- a/data/render/src/lib.rs +++ b/data/render/src/lib.rs @@ -32,49 +32,50 @@ pub async fn check_deprecated(token: std::string::String, entries: &mut Vec = entries.to_vec(); for entry in &mut entries_tmp { - if entry.source.is_some() { - let mut source: &str = entry.source.as_ref().unwrap(); + if entry.source.is_none() { + continue; + } - if source.chars().last().unwrap() == '/' { - source = source.trim_end_matches('/'); - } + let mut source: &str = entry.source.as_ref().unwrap(); + if source.chars().last().unwrap() == '/' { + source = source.trim_end_matches('/'); + } + + let components: Vec<&str> = source.split("/").collect(); + if !(components.contains(&"github.com") && components.len() == 5) { + // valid github source must have 5 elements - anything longer and they are probably a + // reference to a path inside a repo, rather than a repo itself. + continue; + } - let components: Vec<&str> = source.split("/").collect(); - if components.contains(&"github.com") && components.len() == 5 { - // valid github source must have 5 elements - anything longer and they are probably a - // reference to a path inside a repo, rather than a repo itself. - - let owner = components[3]; - let repo = components[4]; - - let commit_list = github - .repo(owner, repo) - .commits() - .list() - .await; - - let commit_list = match commit_list { - Ok(commit_list) => commit_list, - Err(_error) => Vec::new(), - }; - - if commit_list.len() == 0 { - continue; - } - - let date: &str = &commit_list[0].commit.author.date[..]; - let timestamp = NaiveDateTime::parse_from_str(date, "%Y-%m-%dT%H:%M:%SZ")?.timestamp(); - let current_timestamp = Utc::now().timestamp(); - - if current_timestamp - timestamp > 365 * 86400 { - if entry.deprecated.is_none() { - entry.deprecated = Some(true); - } - } else { - if entry.deprecated.is_some() { - entry.deprecated = None; - } - } + let owner = components[3]; + let repo = components[4]; + + let commit_list = github + .repo(owner, repo) + .commits() + .list() + .await; + + let commit_list = match commit_list { + Ok(commit_list) => commit_list, + Err(_error) => Vec::new(), + }; + if commit_list.len() == 0 { + continue; + } + + let date: &str = &commit_list[0].commit.author.date[..]; + let timestamp = NaiveDateTime::parse_from_str(date, "%Y-%m-%dT%H:%M:%SZ")?.timestamp(); + let current_timestamp = Utc::now().timestamp(); + + if current_timestamp - timestamp > 365 * 86400 { + if entry.deprecated.is_none() { + entry.deprecated = Some(true); + } + } else { + if entry.deprecated.is_some() { + entry.deprecated = None; } } }