1
0
mirror of https://github.com/rust-unofficial/awesome-rust.git synced 2025-05-13 21:26:41 +02:00

Merge branch 'master' into patch-2

This commit is contained in:
bertllll 2021-08-04 10:29:43 +02:00 committed by GitHub
commit ae88c5ecfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 462 additions and 347 deletions

View File

@ -15,7 +15,7 @@ If you want to add an entry to the `README.md` please consider this:
* if you've not published your crate to `crates.io` remove the `[[CRATE](...)]` part.
* if you have a CI build, please add the build badge. Put the image after the description, separated by a space. Please make sure to add the branch information to the image:
* example for Travis: ` [<img src="https://api.travis-ci.org/XXX/CRATE.svg?branch=master">](https://travis-ci.org/XXX/CRATE)`
* for Github actions please see https://docs.github.com/en/free-pro-team@latest/actions/managing-workflow-runs/adding-a-workflow-status-badge#using-the-branch-parameter
* for Github actions please see https://docs.github.com/en/actions/managing-workflow-runs/adding-a-workflow-status-badge
- please pay attention to the alphabetical ordering.

19
Cargo.lock generated
View File

@ -24,6 +24,15 @@ dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
@ -53,6 +62,7 @@ version = "0.1.0"
dependencies = [
"chrono",
"chrono-humanize",
"diffy",
"env_logger",
"failure",
"futures",
@ -189,6 +199,15 @@ dependencies = [
"syn",
]
[[package]]
name = "diffy"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c1ff48e3f358d3158f88b2c95071f28d136be31d89e5fa843095032a70bff56"
dependencies = [
"ansi_term",
]
[[package]]
name = "dtoa"
version = "0.4.8"

View File

@ -22,4 +22,5 @@ log = "0.4"
regex = "1"
scraper = "0.11"
chrono = { version = "0.4", features = ["serde"] }
chrono-humanize = "0.2"
chrono-humanize = "0.2"
diffy = "0.2"

703
README.md

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ use chrono::{Local, DateTime, Duration};
use std::env;
use tokio::sync::Semaphore;
use tokio::sync::SemaphorePermit;
use diffy::create_patch;
#[derive(Debug, Fail, Serialize, Deserialize)]
enum CheckerError {
@ -27,7 +28,7 @@ enum CheckerError {
},
#[fail(display = "too many requests")]
TooManyRequests,
TooManyRequests,
#[fail(display = "reqwest error: {}", error)]
ReqwestError {
@ -39,9 +40,6 @@ enum CheckerError {
#[fail(display = "travis build image with no branch")]
TravisBuildNoBranch,
#[fail(display = "github actions image with no branch")]
GithubActionNoBranch,
}
fn formatter(err: &CheckerError, url: &String) -> String {
@ -62,9 +60,6 @@ fn formatter(err: &CheckerError, url: &String) -> String {
CheckerError::TravisBuildNoBranch => {
format!("[Travis build image with no branch specified] {}", url)
}
CheckerError::GithubActionNoBranch => {
format!("[Github action image with no branch specified] {}", url)
}
_ => {
format!("{:?}", err)
}
@ -227,14 +222,6 @@ fn get_url_core(url: String) -> BoxFuture<'static, (String, Result<(), CheckerEr
break;
}
}
if let Some(matches) = GITHUB_ACTIONS_REGEX.captures(&url) {
debug!("Github actions match {:?}", matches);
let query = matches.get(1).map(|x| x.as_str()).unwrap_or("");
if !query.starts_with("?") || query.find("branch=").is_none() {
res = Err(CheckerError::GithubActionNoBranch);
break;
}
}
debug!("Finished {}", url);
res = Ok(());
break;
@ -295,13 +282,76 @@ async fn main() -> Result<(), Error> {
let mut to_check: Vec<String> = vec![];
for (event, _range) in parser.into_offset_iter() {
#[derive(Debug)]
struct ListInfo {
location: usize,
data: Vec<String>
}
let mut list_items: Vec<ListInfo> = Vec::new();
let mut in_list_item = false;
let mut list_item: String = String::new();
for (event, range) in parser.into_offset_iter() {
match event {
Event::Start(tag) => {
match tag {
Tag::Link(_link_type, url, _title) | Tag::Image(_link_type, url, _title) => {
to_check.push(url.to_string());
}
Tag::List(_) => {
if in_list_item && list_item.len() > 0 {
list_items.last_mut().unwrap().data.push(list_item.clone());
in_list_item = false;
}
list_items.push(ListInfo {location: range.start, data: Vec::new()});
}
Tag::Item => {
if in_list_item && list_item.len() > 0 {
list_items.last_mut().unwrap().data.push(list_item.clone());
}
in_list_item = true;
list_item = String::new();
}
Tag::Heading(_) => {}
Tag::Paragraph => {}
_ => {
if in_list_item {
in_list_item = false;
}
}
}
}
Event::Text(text) => {
if in_list_item {
list_item.push_str(&text);
}
}
Event::End(tag) => {
match tag {
Tag::Item => {
if list_item.len() > 0 {
list_items.last_mut().unwrap().data.push(list_item.clone());
list_item = String::new();
}
in_list_item = false
}
Tag::List(_) => {
let list_info = list_items.pop().unwrap();
if list_info.data.iter().find(|s| *s == "License").is_some() && list_info.data.iter().find(|s| *s == "Resources").is_some() {
// Ignore wrong ordering in top-level list
continue
}
let mut sorted_recent_list = list_info.data.to_vec();
sorted_recent_list.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()));
let joined_recent = list_info.data.join("\n");
let joined_sorted = sorted_recent_list.join("\n");
let patch = create_patch(&joined_recent, &joined_sorted);
if patch.hunks().len() > 0 {
println!("{}", patch);
return Err(format_err!("Sorting error"));
}
}
_ => {}
}
}