Skip to content
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

glacier: Append random sequence to branch name to make it unique #1041

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ native-tls = "0.2"
serde_path_to_error = "0.1.2"
octocrab = "0.5"
comrak = "0.8.2"
rand = "0.7"

[dependencies.serde]
version = "1"
Expand Down
20 changes: 13 additions & 7 deletions src/handlers/glacier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{config::GlacierConfig, github::Event, handlers::Context};
use octocrab::models::Object;
use octocrab::params::repos::Reference;
use parser::command::glacier::GlacierCommand;
use rand::Rng as _;

pub(super) async fn handle_command(
ctx: &Context,
Expand Down Expand Up @@ -46,25 +47,30 @@ pub(super) async fn handle_command(
unreachable!()
};

fork.create_ref(
&Reference::Branch(format!("triagebot-ice-{}", number)),
master,
)
.await?;
let pr_branch_name = format!(
"triagebot-ice-{}-{}",
number,
rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(8)
.collect::<String>()
);
fork.create_ref(&Reference::Branch(pr_branch_name.clone()), master)
.await?;
fork.create_file(
format!("ices/{}.rs", number),
format!("Add ICE reproduction for issue rust-lang/rust#{}.", number),
body,
)
.branch(format!("triagebot-ice-{}", number))
.branch(pr_branch_name.clone())
.send()
.await?;

octocrab
.pulls("rust-lang", "glacier")
.create(
format!("ICE - rust-lang/rust#{}", number),
format!("rustbot:triagebot-ice-{}", number),
format!("rustbot:{}", pr_branch_name),
"master",
)
.body(format!(
Expand Down