1
+ use std:: path:: Path ;
2
+
3
+ use anyhow:: Context ;
1
4
use chrono:: { Datelike , NaiveDate } ;
2
5
3
6
use crate :: {
@@ -11,9 +14,12 @@ use crate::{
11
14
pub fn updates (
12
15
repository : & Repository ,
13
16
milestone : & str ,
17
+ output_directory : & Path ,
14
18
start_date : & Option < NaiveDate > ,
15
19
end_date : & Option < NaiveDate > ,
16
20
) -> anyhow:: Result < ( ) > {
21
+ use std:: fmt:: Write ;
22
+
17
23
let issues = list_issue_titles_in_milestone ( repository, milestone) ?;
18
24
19
25
let filter = Filter {
@@ -24,54 +30,43 @@ pub fn updates(
24
30
end_date,
25
31
} ;
26
32
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( ) ) ) ?;
33
35
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 ( ) ) } ,
44
46
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
+ ) ?;
56
48
57
49
let mut comments = issue. comments ;
58
50
comments. sort_by_key ( |c| c. created_at . clone ( ) ) ;
59
51
comments. retain ( |c| filter. matches ( c) ) ;
60
52
61
- println ! ( ) ;
53
+ writeln ! ( output_text ) ? ;
62
54
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
+ ) ?;
64
60
} else {
65
61
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) ?;
73
63
}
74
64
}
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( ) ) ) ?;
75
70
}
76
71
77
72
Ok ( ( ) )
0 commit comments