-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgithub.rs
72 lines (64 loc) · 1.58 KB
/
github.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
#![allow(dead_code)]
use std::{borrow::Cow, process::Command};
use cargo_metadata::Package;
use crate::{
command::release::Options,
utils::{will, Program},
Context,
};
struct Support {
gh: Program,
}
impl Default for Support {
fn default() -> Self {
Self::new()
}
}
impl Support {
fn new() -> Self {
Support {
gh: Program::named("gh"),
}
}
}
pub fn create_release(
publishee: &Package,
new_version: &semver::Version,
notes: &str,
Options { dry_run, .. }: Options,
ctx: &Context,
) -> anyhow::Result<()> {
let tag_name = crate::utils::tag_name(publishee, new_version, &ctx.repo);
let mut cmd = Command::new("gh");
cmd.args(["release", "create"])
.arg(&tag_name)
.arg("--title")
.arg(format!(
"{}v{}",
match crate::utils::tag_prefix(publishee, &ctx.repo) {
Some(prefix) => Cow::Owned(format!("{prefix} ")),
None => "".into(),
},
new_version
))
.arg("--notes");
log::trace!(
"{} run {:?} \"{}…\" [note truncated]",
will(dry_run),
cmd,
notes
.chars()
.take(22)
.collect::<String>()
.replace('\n', "\\n")
.replace("\r\n", "\\r\\n")
);
cmd.arg(notes);
if !dry_run && !cmd.status()?.success() {
log::warn!(
"'gh' tool execution failed - considering this non-critical, and you may try to create the release with: {:?}",
cmd
);
}
Ok(())
}