Skip to content

Commit 765bec4

Browse files
committed
move label creation to a method
1 parent b88b5bc commit 765bec4

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

mdbook-goals/src/gh/labels.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,27 @@ impl GhLabel {
2323

2424
Ok(labels)
2525
}
26+
27+
pub fn create(&self, repository: &str) -> anyhow::Result<()> {
28+
let output = Command::new("gh")
29+
.arg("-R")
30+
.arg(repository)
31+
.arg("label")
32+
.arg("create")
33+
.arg(&self.name)
34+
.arg("--color")
35+
.arg(&self.color)
36+
.arg("--force")
37+
.output()?;
38+
39+
if !output.status.success() {
40+
Err(anyhow::anyhow!(
41+
"failed to create label `{}`: {}",
42+
self.name,
43+
String::from_utf8_lossy(&output.stderr)
44+
))
45+
} else {
46+
Ok(())
47+
}
48+
}
2649
}

mdbook-goals/src/rfc.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -449,29 +449,9 @@ impl Display for GithubAction<'_> {
449449
impl GithubAction<'_> {
450450
pub fn execute(self, repository: &str, timeframe: &str) -> anyhow::Result<()> {
451451
match self {
452-
GithubAction::CreateLabel {
453-
label: GhLabel { name, color },
454-
} => {
455-
let output = Command::new("gh")
456-
.arg("-R")
457-
.arg(repository)
458-
.arg("label")
459-
.arg("create")
460-
.arg(&name)
461-
.arg("--color")
462-
.arg(&color)
463-
.arg("--force")
464-
.output()?;
465-
466-
if !output.status.success() {
467-
Err(anyhow::anyhow!(
468-
"failed to create label `{}`: {}",
469-
name,
470-
String::from_utf8_lossy(&output.stderr)
471-
))
472-
} else {
473-
Ok(())
474-
}
452+
GithubAction::CreateLabel { label } => {
453+
label.create(repository)?;
454+
Ok(())
475455
}
476456

477457
GithubAction::CreateIssue {

0 commit comments

Comments
 (0)