-
Notifications
You must be signed in to change notification settings - Fork 74
/
glacier.rs
78 lines (68 loc) · 1.98 KB
/
glacier.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Allows team members to directly create a glacier PR with the code provided.
use crate::{config::GlacierConfig, github::Event, handlers::Context};
use models::repos::Object;
use octocrab::models;
use octocrab::params::repos::Reference;
use parser::command::glacier::GlacierCommand;
use tracing as log;
pub(super) async fn handle_command(
ctx: &Context,
_config: &GlacierConfig,
event: &Event,
cmd: GlacierCommand,
) -> anyhow::Result<()> {
let is_team_member = event
.user()
.is_team_member(&ctx.github)
.await
.unwrap_or(false);
if !is_team_member {
return Ok(());
};
let body = ctx
.github
.raw_gist_from_url(&cmd.source, "playground.rs")
.await?;
let number = event.issue().unwrap().number;
let user = event.user();
let octocrab = &ctx.octocrab;
let fork = octocrab.repos("rustbot", "glacier");
let base = octocrab.repos("rust-lang", "glacier");
let master = base
.get_ref(&Reference::Branch("master".to_string()))
.await?
.object;
let master = if let Object::Commit { sha, .. } = master {
sha
} else {
log::error!("invalid commit sha - master {:?}", master);
unreachable!()
};
fork.create_ref(
&Reference::Branch(format!("triagebot-ice-{}", number)),
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))
.send()
.await?;
octocrab
.pulls("rust-lang", "glacier")
.create(
format!("ICE - rust-lang/rust#{}", number),
format!("rustbot:triagebot-ice-{}", number),
"master",
)
.body(format!(
"Automatically created by @{} in issue rust-lang/rust#{}",
user.login, number
))
.send()
.await?;
Ok(())
}