Skip to content

Add glacier command to track ICEs #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 22, 2020
Merged

Add glacier command to track ICEs #526

merged 10 commits into from
May 22, 2020

Conversation

Elinvynia
Copy link
Contributor

This is building on the work done in #234, huge props to @hellow554 for the initial effort!

I have no idea how to run the bot, but the tests I added pass.

match toks.next_token()? {
Some(Token::Quote(s)) => {
let source = s.to_owned();
let playground_url = Regex::new("https://play.rust-lang.org/.*").unwrap();
Copy link

@hellow554 hellow554 May 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using starts_with? I don't like using a regex for this case, because you pull in the crate just for this piece and you could circumvent it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good suggestion! It didn't cross my mind, heh.

@Elinvynia
Copy link
Contributor Author

Status update: Currently waiting on XAMPPRocky/octocrab#12 to be merged to allow me to do this cleanly.

@LeSeulArtichaut
Copy link
Contributor

@Elinvynia XAMPPRocky/octocrab#12 has been merged

Copy link
Contributor

@LeSeulArtichaut LeSeulArtichaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising overall :)

let number = event.issue().unwrap().number;
let user = event.user();

let octocrab = octocrab::instance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As asked by @Mark-Simulacrum, we should not use the static instance here. Let's store it in Context alongside the GithubClient


let octocrab = octocrab::instance();

let fork = octocrab.repos("rust-lang", "glacier");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we @Mark-Simulacrum will create a fork for the bot, so to not pollute the main rust-lang/glacier repository? In that case you just need to set the owner to "rustbot" instead of "rust-lang"

};

fork.create_ref(&Reference::Branch(format!("triagebot-ice-{}", number)), master).await?;
fork.create_file(format!("ices/{}.rs", number), format!("This PR was created by {} on issue {}.", user.login, number), body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is actually the commit message. You probably want to change that, to something like "Add ICE reproduction for issue #{}"?


fork.create_ref(&Reference::Branch(format!("triagebot-ice-{}", number)), master).await?;
fork.create_file(format!("ices/{}.rs", number), format!("This PR was created by {} on issue {}.", user.login, number), body)
.branch("triagebot-ice")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the branch you created earlier.

Suggested change
.branch("triagebot-ice")
.branch(format!("triagebot-ice-{}", number))


octocrab.pulls("rust-lang", "glacier")
.create(format!("ICE - {}", number), format!("triagebot-ice-{}", number), "master")
.body("This is a fake new catastrophic avalanche of ICE!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the body (description) of the PR. Let's change it to something like "Automatically created by @{} in issue #{}"

.await?;

octocrab.pulls("rust-lang", "glacier")
.create(format!("ICE - {}", number), format!("triagebot-ice-{}", number), "master")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we actually create a fork for rustbot, you'll need to set this to "rustbot:triagebot-ice-{}"

};

let url = cmd.source;
let response = reqwest::get(&format!("{}{}", url.replace("github", "githubusercontent"), "/playground.rs")).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the reqwest::Client inside of the GithubClient using GithubClient::raw

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::NoLink => write!(f, "no link provided"),
Self::InvalidLink => write!(f, "invalid link"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's note here that it should be a link to a gist.

impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::NoLink => write!(f, "no link provided"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should note the requirement for quotes around the link.


match event {
Event::IssueComment(_) => (),
_ => {return Ok(None);}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to run on newly opened issues too, not just comments?

Command::Glacier(Ok(command)) => Ok(Some(command)),
Command::Glacier(Err(err)) => {
return Err(format!(
"Parsing assign command in [comment]({}) failed: {}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: glacier, not assign command.

let master = if let Object::Commit { sha, ..} = master {
sha
} else {
panic!()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the actual value of master here so that we can debug if it does occur.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I think this should be unreachable!() instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless, we should note what we actually encountered.

panic!()
};

fork.create_ref(&Reference::Branch(format!("triagebot-ice-{}", number)), master).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this fail if the branch already exists? Sometimes we have multiple distinct examples for a single ICE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honesly I am not sure what happens here, how should we proceed? Append a random string and hope for no conflict?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to leave as is for now.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see octocrab moved to a crates.io dependency before merging, and I've also asked @XAMPPRocky over zulip to see if we can use a subset of tokio's feature flags rather than full.

Other than that, this looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants