Skip to content

Commit 8132a52

Browse files
author
Niko Matsakis
committed
update issue body
1 parent 8cb9df6 commit 8132a52

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

crates/rust-project-goals-cli/src/rfc.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rust_project_goals::{
1313
gh::{
1414
issue_id::{IssueId, Repository},
1515
issues::{
16-
change_milestone, create_comment, create_issue, fetch_issue, list_issues_in_milestone, lock_issue, sync_assignees, FLAGSHIP_LABEL, LOCK_TEXT
16+
change_milestone, create_comment, create_issue, fetch_issue, list_issues_in_milestone, lock_issue, sync_assignees, update_issue_body, FLAGSHIP_LABEL, LOCK_TEXT
1717
},
1818
labels::GhLabel,
1919
},
@@ -209,6 +209,11 @@ enum GithubAction<'doc> {
209209
body: String,
210210
},
211211

212+
UpdateIssueBody {
213+
number: u64,
214+
body: String,
215+
},
216+
212217
// We intentionally do not sync the issue *text*, because it may have been edited.
213218
SyncAssignees {
214219
number: u64,
@@ -348,6 +353,14 @@ fn initialize_issues<'doc>(
348353
});
349354
}
350355

356+
let link_text = goal_document_link(timeframe, &desired_issue.goal_document);
357+
if !existing_issue.body.contains(&link_text) {
358+
actions.insert(GithubAction::UpdateIssueBody {
359+
number: existing_issue.number,
360+
body: existing_issue.body,
361+
});
362+
}
363+
351364
let issue_id = IssueId::new(repository.clone(), existing_issue.number);
352365
if desired_issue.tracking_issue != Some(&issue_id) {
353366
actions.insert(GithubAction::LinkToTrackingIssue {
@@ -394,6 +407,11 @@ fn issue<'doc>(timeframe: &str, document: &'doc GoalDocument) -> anyhow::Result<
394407
})
395408
}
396409

410+
fn goal_document_link(timeframe: &str, document: &GoalDocument) -> String {
411+
let goal_file = document.link_path.file_stem().unwrap().to_str().unwrap();
412+
format!("[{timeframe}/{goal_file}](https://rust-lang.github.io/rust-project-goals/{timeframe}/{goal_file}.html)")
413+
}
414+
397415
fn issue_text(timeframe: &str, document: &GoalDocument) -> anyhow::Result<String> {
398416
let mut tasks = vec![];
399417
for goal_plan in &document.goal_plans {
@@ -406,15 +424,13 @@ fn issue_text(timeframe: &str, document: &GoalDocument) -> anyhow::Result<String
406424
.map(|team| team.name_and_link())
407425
.collect::<Vec<_>>();
408426

409-
let goal_file = document.link_path.file_stem().unwrap().to_str().unwrap();
410-
411427
Ok(format!(
412428
r##"
413429
| Metadata | |
414430
| -------- | --- |
415431
| Point of contact | {poc} |
416432
| Team(s) | {teams} |
417-
| Goal document | [{timeframe}/{goal_file}](https://rust-lang.github.io/rust-project-goals/{timeframe}/{goal_file}.html) |
433+
| Goal document | {goaldocument} |
418434
419435
## Summary
420436
@@ -430,6 +446,7 @@ fn issue_text(timeframe: &str, document: &GoalDocument) -> anyhow::Result<String
430446
teams = teams.join(", "),
431447
summary = document.summary,
432448
tasks = tasks.join("\n"),
449+
goaldocument = goal_document_link(timeframe, document),
433450
))
434451
}
435452

@@ -495,6 +512,9 @@ impl Display for GithubAction<'_> {
495512
GithubAction::Comment { number, body } => {
496513
write!(f, "post comment on issue #{}: \"{}\"", number, body)
497514
}
515+
GithubAction::UpdateIssueBody { number, body: _ } => {
516+
write!(f, "update the body on issue #{} for new milestone", number)
517+
}
498518
GithubAction::SyncAssignees {
499519
number,
500520
remove_owners,
@@ -565,6 +585,11 @@ impl GithubAction<'_> {
565585
Ok(())
566586
}
567587

588+
GithubAction::UpdateIssueBody { number, body } => {
589+
update_issue_body(repository, number, &body)?;
590+
Ok(())
591+
}
592+
568593
GithubAction::SyncAssignees {
569594
number,
570595
remove_owners,

crates/rust-project-goals/src/gh/issues.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,28 @@ pub fn create_comment(repository: &Repository, number: u64, body: &str) -> anyho
246246
}
247247
}
248248

249+
pub fn update_issue_body(repository: &Repository, number: u64, body: &str) -> anyhow::Result<()> {
250+
let output = Command::new("gh")
251+
.arg("-R")
252+
.arg(&repository.to_string())
253+
.arg("issue")
254+
.arg("edit")
255+
.arg(number.to_string())
256+
.arg("-b")
257+
.arg(body)
258+
.output()?;
259+
260+
if !output.status.success() {
261+
Err(anyhow::anyhow!(
262+
"failed to adjust issue body on issue `{}`: {}",
263+
number,
264+
String::from_utf8_lossy(&output.stderr)
265+
))
266+
} else {
267+
Ok(())
268+
}
269+
}
270+
249271
pub fn sync_assignees(
250272
repository: &Repository,
251273
number: u64,

0 commit comments

Comments
 (0)