Skip to content

Commit 365e094

Browse files
committed
move code for locking issues into gh::issues
1 parent 8526604 commit 365e094

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

mdbook-goals/src/gh/issues.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,54 @@ pub fn list_issue_titles_in_milestone(
8585
})
8686
.collect())
8787
}
88+
89+
const LOCK_TEXT: &str = "This issue is intended for status updates only.\n\nFor general questions or comments, please contact the owner(s) directly.";
90+
91+
impl ExistingGithubIssue {
92+
/// We use the presence of a "lock comment" as a signal that we successfully locked the issue.
93+
/// The github CLI doesn't let you query that directly.
94+
pub fn was_locked(&self) -> bool {
95+
self.comments.iter().any(|c| c.body.trim() == LOCK_TEXT)
96+
}
97+
}
98+
99+
pub fn lock_issue(repository: &str, number: u64) -> anyhow::Result<()> {
100+
let output = Command::new("gh")
101+
.arg("-R")
102+
.arg(repository)
103+
.arg("issue")
104+
.arg("lock")
105+
.arg(number.to_string())
106+
.output()?;
107+
108+
if !output.status.success() {
109+
if !output.stderr.starts_with(b"already locked") {
110+
return Err(anyhow::anyhow!(
111+
"failed to lock issue `{}`: {}",
112+
number,
113+
String::from_utf8_lossy(&output.stderr)
114+
));
115+
}
116+
}
117+
118+
// Leave a comment explaining what is going on.
119+
let output = Command::new("gh")
120+
.arg("-R")
121+
.arg(repository)
122+
.arg("issue")
123+
.arg("comment")
124+
.arg(number.to_string())
125+
.arg("-b")
126+
.arg(LOCK_TEXT)
127+
.output()?;
128+
129+
if !output.status.success() {
130+
return Err(anyhow::anyhow!(
131+
"failed to leave lock comment `{}`: {}",
132+
number,
133+
String::from_utf8_lossy(&output.stderr)
134+
));
135+
}
136+
137+
Ok(())
138+
}

mdbook-goals/src/rfc.rs

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ use regex::Regex;
1212
use crate::{
1313
gh::{
1414
issue_id::IssueId,
15-
issues::{list_issue_titles_in_milestone, ExistingGithubIssue},
15+
issues::{list_issue_titles_in_milestone, lock_issue},
1616
labels::{list_labels, GhLabel},
1717
},
1818
goal::{self, GoalDocument, ParsedOwners, PlanItem, Status},
1919
team::{get_person_data, TeamName},
2020
};
2121

22-
const LOCK_TEXT: &str = "This issue is intended for status updates only.\n\nFor general questions or comments, please contact the owner(s) directly.";
23-
2422
fn validate_path(path: &Path) -> anyhow::Result<String> {
2523
if !path.is_dir() {
2624
return Err(anyhow::anyhow!(
@@ -559,56 +557,7 @@ impl GithubAction<'_> {
559557
}
560558
}
561559

562-
fn lock_issue(repository: &str, number: u64) -> anyhow::Result<()> {
563-
let output = Command::new("gh")
564-
.arg("-R")
565-
.arg(repository)
566-
.arg("issue")
567-
.arg("lock")
568-
.arg(number.to_string())
569-
.output()?;
570-
571-
if !output.status.success() {
572-
if !output.stderr.starts_with(b"already locked") {
573-
return Err(anyhow::anyhow!(
574-
"failed to lock issue `{}`: {}",
575-
number,
576-
String::from_utf8_lossy(&output.stderr)
577-
));
578-
}
579-
}
580-
581-
// Leave a comment explaining what is going on.
582-
let output = Command::new("gh")
583-
.arg("-R")
584-
.arg(repository)
585-
.arg("issue")
586-
.arg("comment")
587-
.arg(number.to_string())
588-
.arg("-b")
589-
.arg(LOCK_TEXT)
590-
.output()?;
591-
592-
if !output.status.success() {
593-
return Err(anyhow::anyhow!(
594-
"failed to leave lock comment `{}`: {}",
595-
number,
596-
String::from_utf8_lossy(&output.stderr)
597-
));
598-
}
599-
600-
Ok(())
601-
}
602-
603560
/// Returns a comma-separated list of the strings in `s` (no spaces).
604561
fn comma(s: &BTreeSet<String>) -> String {
605562
s.iter().map(|s| &s[..]).collect::<Vec<_>>().join(",")
606563
}
607-
608-
impl ExistingGithubIssue {
609-
/// We use the presence of a "lock comment" as a signal that we successfully locked the issue.
610-
/// The github CLI doesn't let you query that directly.
611-
fn was_locked(&self) -> bool {
612-
self.comments.iter().any(|c| c.body.trim() == LOCK_TEXT)
613-
}
614-
}

0 commit comments

Comments
 (0)