Skip to content

Commit d269c31

Browse files
committed
create helper for sync'ing assignees
1 parent 22ac0f7 commit d269c31

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

mdbook-goals/src/gh/issues.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,40 @@ pub fn create_issue(
124124
}
125125
}
126126

127+
pub fn sync_assignees(
128+
repository: &str,
129+
number: u64,
130+
remove_owners: &BTreeSet<String>,
131+
add_owners: &BTreeSet<String>,
132+
) -> anyhow::Result<()> {
133+
let mut command = Command::new("gh");
134+
command
135+
.arg("-R")
136+
.arg(&repository)
137+
.arg("issue")
138+
.arg("edit")
139+
.arg(number.to_string());
140+
141+
if !remove_owners.is_empty() {
142+
command.arg("--remove-assignee").arg(comma(&remove_owners));
143+
}
144+
145+
if !add_owners.is_empty() {
146+
command.arg("--add-assignee").arg(comma(&add_owners));
147+
}
148+
149+
let output = command.output()?;
150+
if !output.status.success() {
151+
Err(anyhow::anyhow!(
152+
"failed to sync issue `{}`: {}",
153+
number,
154+
String::from_utf8_lossy(&output.stderr)
155+
))
156+
} else {
157+
Ok(())
158+
}
159+
}
160+
127161
const LOCK_TEXT: &str = "This issue is intended for status updates only.\n\nFor general questions or comments, please contact the owner(s) directly.";
128162

129163
impl ExistingGithubIssue {

mdbook-goals/src/rfc.rs

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

2322
fn validate_path(path: &Path) -> anyhow::Result<String> {
@@ -477,32 +476,8 @@ impl GithubAction<'_> {
477476
remove_owners,
478477
add_owners,
479478
} => {
480-
let mut command = Command::new("gh");
481-
command
482-
.arg("-R")
483-
.arg(&repository)
484-
.arg("issue")
485-
.arg("edit")
486-
.arg(number.to_string());
487-
488-
if !remove_owners.is_empty() {
489-
command.arg("--remove-assignee").arg(comma(&remove_owners));
490-
}
491-
492-
if !add_owners.is_empty() {
493-
command.arg("--add-assignee").arg(comma(&add_owners));
494-
}
495-
496-
let output = command.output()?;
497-
if !output.status.success() {
498-
Err(anyhow::anyhow!(
499-
"failed to sync issue `{}`: {}",
500-
number,
501-
String::from_utf8_lossy(&output.stderr)
502-
))
503-
} else {
504-
Ok(())
505-
}
479+
sync_assignees(repository, number, &remove_owners, &add_owners)?;
480+
Ok(())
506481
}
507482

508483
GithubAction::LockIssue { number } => lock_issue(repository, number),

0 commit comments

Comments
 (0)