Skip to content

Commit

Permalink
Automatically check whether a github entry is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
AristoChen committed Sep 3, 2020
1 parent 072ee4a commit 2da1f23
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
5 changes: 4 additions & 1 deletion data/render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ edition = "2018"
serde = "1.0.111"
serde_derive = "1.0.111"
serde_yaml = "0.8.12"
askama = "0.9.0"
askama = "0.9.0"
hubcaps = "0.6"
tokio = { version = "0.2", features = ["macros"] }
chrono = "0.4.15"
3 changes: 2 additions & 1 deletion data/render/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use askama::Template;
use render::types::{Entry, Tags};
use render::{group, validate};
use render::{group, validate, check_deprecated};
use std::env;
use std::error::Error;

Expand Down Expand Up @@ -28,6 +28,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut tools = read_tools(tools)?;
tools.sort();
validate(&tags, &tools)?;
tools = check_deprecated(&mut tools)?;

let catalog = group(&tags, tools)?;
println!("{}", catalog.render()?);
Expand Down
61 changes: 61 additions & 0 deletions data/render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
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 @@ -21,6 +24,64 @@ pub fn validate(tags: &Tags, entries: &Vec<Entry>) -> Result<(), Box<dyn Error>>
Ok(())
}

#[tokio::main]
pub async fn check_deprecated(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),
)?;

let mut entries_tmp: Vec<Entry> = entries.to_vec();
for entry in &mut entries_tmp {
if entry.source.is_some() {
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.

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;
}
}
}
}
}
Ok(entries_tmp.to_vec())
}

pub fn group(tags: &Tags, entries: Vec<Entry>) -> Result<Catalog, Box<dyn Error>> {
let mut linters = BTreeMap::new();

Expand Down
2 changes: 1 addition & 1 deletion data/render/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you also want to support this project, head over to our [Github sponsors page

- :copyright: stands for proprietary software. All other tools are Open Source.
- :information_source: indicates that the community does not recommend to use this tool for new projects anymore. The icon links to the discussion issue.
- :warning: means that this tool was not updated for more than 6 months, or the repo was archived.
- :warning: means that this tool was not updated for more than 1 year, or the repo was archived.

Pull requests are very welcome!
Also check out the sister project, [awesome-dynamic-analysis](https://github.com/mre/awesome-dynamic-analysis).
Expand Down

0 comments on commit 2da1f23

Please sign in to comment.