Skip to content

Commit 22ac0f7

Browse files
committed
extra function to create issues
1 parent 765bec4 commit 22ac0f7

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

mdbook-goals/src/gh/issues.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::{
55

66
use serde::{Deserialize, Serialize};
77

8+
use crate::util::comma;
9+
810
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
911
pub struct ExistingGithubIssue {
1012
pub number: u64,
@@ -86,6 +88,42 @@ pub fn list_issue_titles_in_milestone(
8688
.collect())
8789
}
8890

91+
pub fn create_issue(
92+
repository: &str,
93+
body: &str,
94+
title: &str,
95+
labels: &[String],
96+
assignees: &BTreeSet<String>,
97+
milestone: &str,
98+
) -> anyhow::Result<()> {
99+
let output = Command::new("gh")
100+
.arg("-R")
101+
.arg(&repository)
102+
.arg("issue")
103+
.arg("create")
104+
.arg("-b")
105+
.arg(&body)
106+
.arg("-t")
107+
.arg(&title)
108+
.arg("-l")
109+
.arg(labels.join(","))
110+
.arg("-a")
111+
.arg(comma(&assignees))
112+
.arg("-m")
113+
.arg(&milestone)
114+
.output()?;
115+
116+
if !output.status.success() {
117+
Err(anyhow::anyhow!(
118+
"failed to create issue `{}`: {}",
119+
title,
120+
String::from_utf8_lossy(&output.stderr)
121+
))
122+
} else {
123+
Ok(())
124+
}
125+
}
126+
89127
const LOCK_TEXT: &str = "This issue is intended for status updates only.\n\nFor general questions or comments, please contact the owner(s) directly.";
90128

91129
impl ExistingGithubIssue {

mdbook-goals/src/rfc.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ use regex::Regex;
1212
use crate::{
1313
gh::{
1414
issue_id::IssueId,
15-
issues::{list_issue_titles_in_milestone, lock_issue},
15+
issues::{create_issue, list_issue_titles_in_milestone, lock_issue},
1616
labels::GhLabel,
1717
},
1818
goal::{self, GoalDocument, ParsedOwners, PlanItem, Status},
1919
team::{get_person_data, TeamName},
20+
util::comma,
2021
};
2122

2223
fn validate_path(path: &Path) -> anyhow::Result<String> {
@@ -465,34 +466,11 @@ impl GithubAction<'_> {
465466
goal_document: _,
466467
},
467468
} => {
468-
let output = Command::new("gh")
469-
.arg("-R")
470-
.arg(&repository)
471-
.arg("issue")
472-
.arg("create")
473-
.arg("-b")
474-
.arg(&body)
475-
.arg("-t")
476-
.arg(&title)
477-
.arg("-l")
478-
.arg(labels.join(","))
479-
.arg("-a")
480-
.arg(comma(&assignees))
481-
.arg("-m")
482-
.arg(&timeframe)
483-
.output()?;
484-
485-
if !output.status.success() {
486-
Err(anyhow::anyhow!(
487-
"failed to create issue `{}`: {}",
488-
title,
489-
String::from_utf8_lossy(&output.stderr)
490-
))
491-
} else {
492-
Ok(())
493-
}
469+
create_issue(repository, &body, &title, &labels, &assignees, timeframe)?;
494470

495471
// Note: the issue is not locked, but we will reloop around later.
472+
473+
Ok(())
496474
}
497475
GithubAction::SyncAssignees {
498476
number,
@@ -536,8 +514,3 @@ impl GithubAction<'_> {
536514
}
537515
}
538516
}
539-
540-
/// Returns a comma-separated list of the strings in `s` (no spaces).
541-
fn comma(s: &BTreeSet<String>) -> String {
542-
s.iter().map(|s| &s[..]).collect::<Vec<_>>().join(",")
543-
}

mdbook-goals/src/util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
collections::BTreeSet,
23
fmt::{Display, Write},
34
path::{Path, PathBuf},
45
};
@@ -122,3 +123,8 @@ pub fn markdown_files(directory_path: &Path) -> anyhow::Result<Vec<(PathBuf, Pat
122123
}
123124
Ok(files)
124125
}
126+
127+
/// Returns a comma-separated list of the strings in `s` (no spaces).
128+
pub fn comma(s: &BTreeSet<String>) -> String {
129+
s.iter().map(|s| &s[..]).collect::<Vec<_>>().join(",")
130+
}

0 commit comments

Comments
 (0)