@@ -13,7 +13,7 @@ use rust_project_goals::{
13
13
gh:: {
14
14
issue_id:: { IssueId , Repository } ,
15
15
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
17
17
} ,
18
18
labels:: GhLabel ,
19
19
} ,
@@ -209,6 +209,11 @@ enum GithubAction<'doc> {
209
209
body : String ,
210
210
} ,
211
211
212
+ UpdateIssueBody {
213
+ number : u64 ,
214
+ body : String ,
215
+ } ,
216
+
212
217
// We intentionally do not sync the issue *text*, because it may have been edited.
213
218
SyncAssignees {
214
219
number : u64 ,
@@ -290,8 +295,14 @@ fn initialize_issues<'doc>(
290
295
//
291
296
let existing_issue = if let Some ( tracking_issue) = desired_issue. tracking_issue {
292
297
// a. We first check if there is a declared tracking issue in the markdown file.
293
- // If so, then we just load its information from the repository by number.
294
- Some ( fetch_issue ( repository, tracking_issue. number ) ?)
298
+ // If so, check if we've already loaded its data.
299
+ if let Some ( issue) = milestone_issues. iter ( ) . find ( |issue| issue. number == tracking_issue. number ) {
300
+ // If so, reuse it to avoid latency.
301
+ Some ( issue. clone ( ) )
302
+ } else {
303
+ // If not, load its information from the repository by number.
304
+ Some ( fetch_issue ( repository, tracking_issue. number ) ?)
305
+ }
295
306
} else {
296
307
// b. If the markdown does not have a declared tracking issue, then we can search through
297
308
// the issues in the milestone for one with the correct title.
@@ -348,6 +359,14 @@ fn initialize_issues<'doc>(
348
359
} ) ;
349
360
}
350
361
362
+ let link_text = goal_document_link ( timeframe, & desired_issue. goal_document ) ;
363
+ if !existing_issue. body . contains ( & link_text) {
364
+ actions. insert ( GithubAction :: UpdateIssueBody {
365
+ number : existing_issue. number ,
366
+ body : desired_issue. body ,
367
+ } ) ;
368
+ }
369
+
351
370
let issue_id = IssueId :: new ( repository. clone ( ) , existing_issue. number ) ;
352
371
if desired_issue. tracking_issue != Some ( & issue_id) {
353
372
actions. insert ( GithubAction :: LinkToTrackingIssue {
@@ -394,6 +413,11 @@ fn issue<'doc>(timeframe: &str, document: &'doc GoalDocument) -> anyhow::Result<
394
413
} )
395
414
}
396
415
416
+ fn goal_document_link ( timeframe : & str , document : & GoalDocument ) -> String {
417
+ let goal_file = document. link_path . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
418
+ format ! ( "[{timeframe}/{goal_file}](https://rust-lang.github.io/rust-project-goals/{timeframe}/{goal_file}.html)" )
419
+ }
420
+
397
421
fn issue_text ( timeframe : & str , document : & GoalDocument ) -> anyhow:: Result < String > {
398
422
let mut tasks = vec ! [ ] ;
399
423
for goal_plan in & document. goal_plans {
@@ -406,15 +430,13 @@ fn issue_text(timeframe: &str, document: &GoalDocument) -> anyhow::Result<String
406
430
. map ( |team| team. name_and_link ( ) )
407
431
. collect :: < Vec < _ > > ( ) ;
408
432
409
- let goal_file = document. link_path . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
410
-
411
433
Ok ( format ! (
412
434
r##"
413
435
| Metadata | |
414
436
| -------- | --- |
415
437
| Point of contact | {poc} |
416
438
| Team(s) | {teams} |
417
- | Goal document | [{timeframe}/{goal_file}](https://rust-lang.github.io/rust-project-goals/{timeframe}/{goal_file}.html) |
439
+ | Goal document | {goaldocument} |
418
440
419
441
## Summary
420
442
@@ -430,6 +452,7 @@ fn issue_text(timeframe: &str, document: &GoalDocument) -> anyhow::Result<String
430
452
teams = teams. join( ", " ) ,
431
453
summary = document. summary,
432
454
tasks = tasks. join( "\n " ) ,
455
+ goaldocument = goal_document_link( timeframe, document) ,
433
456
) )
434
457
}
435
458
@@ -495,6 +518,9 @@ impl Display for GithubAction<'_> {
495
518
GithubAction :: Comment { number, body } => {
496
519
write ! ( f, "post comment on issue #{}: \" {}\" " , number, body)
497
520
}
521
+ GithubAction :: UpdateIssueBody { number, body : _ } => {
522
+ write ! ( f, "update the body on issue #{} for new milestone" , number)
523
+ }
498
524
GithubAction :: SyncAssignees {
499
525
number,
500
526
remove_owners,
@@ -565,6 +591,11 @@ impl GithubAction<'_> {
565
591
Ok ( ( ) )
566
592
}
567
593
594
+ GithubAction :: UpdateIssueBody { number, body } => {
595
+ update_issue_body ( repository, number, & body) ?;
596
+ Ok ( ( ) )
597
+ }
598
+
568
599
GithubAction :: SyncAssignees {
569
600
number,
570
601
remove_owners,
0 commit comments