This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08dfe89
commit b93852d
Showing
5 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ tempfile = "3.1.0" | |
[workspace] | ||
members = [ | ||
"autofix", | ||
"grabber", | ||
"labeler" | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "glacier-grabber" | ||
version = "0.1.0" | ||
authors = ["Langston Barrett <[email protected]>"] | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
glacier = "0.1.0" | ||
once_cell = { workspace = true } | ||
regex = "1" | ||
reqwest = { workspace = true } | ||
serde = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use once_cell::sync::Lazy; | ||
use reqwest::blocking::Client; | ||
use serde::{Deserialize, Serialize}; | ||
use std::env::{var, VarError}; | ||
|
||
static CLIENT: Lazy<Client> = Lazy::new(|| { | ||
Client::builder() | ||
.user_agent("rust-lang/glacier") | ||
.build() | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) struct Config { | ||
token: String, | ||
} | ||
|
||
impl Config { | ||
pub(crate) fn from_env(on_glacier: bool) -> Result<Self, VarError> { | ||
Ok(Self { | ||
token: if on_glacier { | ||
var("GITHUB_TOKEN")? | ||
} else { | ||
var("GRAB_TOKEN")? | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
pub(crate) fn get_labeled_issues( | ||
config: &Config, | ||
repo: &str, | ||
label_name: String, | ||
) -> Result<Vec<Issue>, reqwest::Error> { | ||
let url = format!("https://api.github.com/repos/{repo}/issues?labels={label_name}&state=open"); | ||
|
||
let issues: Vec<Issue> = CLIENT | ||
.get(url) | ||
.bearer_auth(&config.token) | ||
.send()? | ||
.error_for_status()? | ||
.json()?; | ||
|
||
// TODO: Pagination, see labeler | ||
|
||
Ok(issues) | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
pub(crate) struct Labels { | ||
pub(crate) labels: Vec<String>, | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub(crate) struct Issue { | ||
pub(crate) number: usize, | ||
pub(crate) body: String, | ||
} | ||
|
||
#[derive(Deserialize, Debug, PartialEq, Eq)] | ||
#[serde(rename_all = "lowercase")] | ||
pub(crate) enum IssueState { | ||
Open, | ||
Closed, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use glacier::rayon::iter::ParallelIterator; | ||
|
||
mod github; | ||
|
||
fn main() { | ||
let config = github::Config::from_env(false).unwrap(); | ||
|
||
let mut tested_issue_list = glacier::discover("./ices") | ||
.unwrap() | ||
.into_iter() | ||
.map(|ice| ice.id()) | ||
.collect::<Vec<_>>(); | ||
tested_issue_list.sort_unstable(); | ||
tested_issue_list.dedup(); | ||
|
||
let mut untesteds = | ||
crate::github::get_labeled_issues(&config, "rust-lang/rust", "I-ICE".to_string()).unwrap(); | ||
untesteds.retain(|i| !tested_issue_list.contains(&i.number)); | ||
for untested in untesteds { | ||
let mut reproduction = Vec::new(); | ||
let mut in_code_section = false; | ||
let mut in_code = false; | ||
let mut has_main = false; | ||
for line in untested.body.lines() { | ||
if in_code { | ||
if line.starts_with("```") { | ||
in_code = false; | ||
continue; | ||
} | ||
if line.starts_with("fn main") { | ||
has_main = true; | ||
} | ||
reproduction.push(line); | ||
} | ||
if line.starts_with("### Code") { | ||
in_code_section = true; | ||
} else if line.starts_with('#') && in_code_section { | ||
in_code_section = false; | ||
} | ||
if line.starts_with("```") && in_code_section { | ||
in_code = true; | ||
} | ||
} | ||
if reproduction.is_empty() { | ||
continue; | ||
} | ||
if !has_main { | ||
reproduction.push(""); | ||
reproduction.push("fn main() {}"); | ||
} | ||
std::fs::write( | ||
format!("./ices/{}.rs", untested.number), | ||
reproduction.join("\n"), | ||
) | ||
.unwrap(); | ||
} | ||
|
||
let failed = glacier::test_all() | ||
.unwrap() | ||
.filter(|res| { | ||
if let Ok(test) = res { | ||
test.outcome() != glacier::Outcome::ICEd | ||
} else { | ||
true | ||
} | ||
}) | ||
.collect::<Result<Vec<glacier::TestResult>, _>>() | ||
.unwrap(); | ||
|
||
for result in &failed { | ||
std::fs::remove_file(result.path()).unwrap(); | ||
} | ||
} |