1+ use std:: path:: Path ;
2+
3+ use anyhow:: Context ;
14use chrono:: { Datelike , NaiveDate } ;
25
36use crate :: {
@@ -11,9 +14,12 @@ use crate::{
1114pub fn updates (
1215 repository : & Repository ,
1316 milestone : & str ,
17+ output_directory : & Path ,
1418 start_date : & Option < NaiveDate > ,
1519 end_date : & Option < NaiveDate > ,
1620) -> anyhow:: Result < ( ) > {
21+ use std:: fmt:: Write ;
22+
1723 let issues = list_issue_titles_in_milestone ( repository, milestone) ?;
1824
1925 let filter = Filter {
@@ -24,54 +30,43 @@ pub fn updates(
2430 end_date,
2531 } ;
2632
27- for ( title, issue) in issues {
28- let total_updates = issue
29- . comments
30- . iter ( )
31- . filter ( |c| !c. is_automated_comment ( ) )
32- . count ( ) ;
33+ std:: fs:: create_dir_all ( output_directory)
34+ . with_context ( || format ! ( "creating directory `{}`" , output_directory. display( ) ) ) ?;
3335
34- println ! (
35- "# {title} (#{number})" ,
36- title = title ,
37- number = issue . number
38- ) ;
39- println ! ( "" ) ;
40- println ! ( "| Metadata | |" ) ;
41- println ! ( "| --- | --- |" ) ;
42- println ! (
43- "| Assigned to | {assignees} |" ,
36+ for ( title , issue ) in issues {
37+ let mut output_text = String :: new ( ) ;
38+ writeln ! (
39+ output_text ,
40+ "What follows is a series of updates related to a project goal entitled {title}. \
41+ The goal is assigned to {people} ({assignees}). \
42+ Please create a short 1-2 paragraph summary of these updates suitable for inclusion in a blog post.
43+ Write the update in the third person. \
44+ UPDATES START HERE:" ,
45+ people = if issue . assignees . len ( ) == 1 { "1 person" . to_string ( ) } else { format! ( "{} people" , issue . assignees . len ( ) ) } ,
4446 assignees = comma( & issue. assignees) ,
45- ) ;
46- println ! ( "| State | {state} |" , state = issue. state) ;
47- println ! ( "| Total updates | {total_updates} |" ) ;
48- println ! (
49- "| Date of most recent update | {date} |" ,
50- date = issue
51- . comments
52- . last( )
53- . map( |c| c. created_at_date( ) . to_string( ) )
54- . unwrap_or( "none" . to_string( ) )
55- ) ;
47+ ) ?;
5648
5749 let mut comments = issue. comments ;
5850 comments. sort_by_key ( |c| c. created_at . clone ( ) ) ;
5951 comments. retain ( |c| filter. matches ( c) ) ;
6052
61- println ! ( ) ;
53+ writeln ! ( output_text ) ? ;
6254 if comments. len ( ) == 0 {
63- println ! ( "No updates since {date}." , date = filter. start_date) ;
55+ writeln ! (
56+ output_text,
57+ "No updates since {date}." ,
58+ date = filter. start_date
59+ ) ?;
6460 } else {
6561 for comment in comments {
66- println ! (
67- "## Update by {author} from {created} ([link]({url}))" ,
68- author = comment. author,
69- created = comment. created_at_date( ) ,
70- url = comment. url,
71- ) ;
72- println ! ( "\n {body}\n " , body = comment. body) ;
62+ writeln ! ( output_text, "\n {body}\n " , body = comment. body) ?;
7363 }
7464 }
65+ let output_file = output_directory
66+ . join ( issue. number . to_string ( ) )
67+ . with_extension ( "md" ) ;
68+ std:: fs:: write ( & output_file, output_text)
69+ . with_context ( || format ! ( "writing to `{}`" , output_file. display( ) ) ) ?;
7570 }
7671
7772 Ok ( ( ) )
0 commit comments