@@ -6,7 +6,7 @@ use crate::jobs::Job;
6
6
use crate :: zulip:: to_zulip_id;
7
7
use anyhow:: Context as _;
8
8
use async_trait:: async_trait;
9
- use chrono:: Utc ;
9
+ use chrono:: { Datelike , NaiveDate , Utc } ;
10
10
use tracing:: { self as log} ;
11
11
12
12
use super :: Context ;
@@ -17,7 +17,11 @@ const GOALS_STREAM: u64 = 435869; // #project-goals
17
17
const C_TRACKING_ISSUE : & str = "C-tracking-issue" ;
18
18
19
19
const MESSAGE : & str = r#"
20
- Dear $OWNERS, it's been $DAYS days since the last update to your goal *$GOAL*. Please comment on the github tracking issue goals#$GOALNUM with an update at your earliest convenience. Thanks! <3
20
+ Dear $OWNERS, it's been $DAYS days since the last update to your goal *$GOAL*.
21
+
22
+ We will begin drafting the next blog post collecting goal updates $NEXT_UPDATE.
23
+
24
+ Please comment on the github tracking issue goals#$GOALNUM before then. Thanks! <3
21
25
22
26
Here is a suggested template for updates (feel free to drop the items that don't apply):
23
27
@@ -35,7 +39,7 @@ impl Job for ProjectGoalsUpdateJob {
35
39
}
36
40
37
41
async fn run ( & self , ctx : & super :: Context , _metadata : & serde_json:: Value ) -> anyhow:: Result < ( ) > {
38
- ping_project_goals_owners ( & ctx. github , false ) . await
42
+ ping_project_goals_owners_automatically ( & ctx. github ) . await
39
43
}
40
44
}
41
45
@@ -51,7 +55,40 @@ pub async fn check_project_goal_acl(_gh: &GithubClient, gh_id: u64) -> anyhow::R
51
55
Ok ( gh_id == GOAL_OWNER_GH_ID )
52
56
}
53
57
54
- pub async fn ping_project_goals_owners ( gh : & GithubClient , dry_run : bool ) -> anyhow:: Result < ( ) > {
58
+ async fn ping_project_goals_owners_automatically ( gh : & GithubClient ) -> anyhow:: Result < ( ) > {
59
+ // Predicted schedule is to author a blog post on the 3rd week of the month.
60
+ // We start pinging when the month starts until we see an update in this month
61
+ // or the last 7 days of previous month.
62
+ //
63
+ // Therefore, we compute:
64
+ // * Days since start of this month -- threshold will be this number of days + 7.
65
+ // * Date of the 3rd Monday in the month -- this will be the next update (e.g., `on Sep-5`).
66
+ let now = Utc :: now ( ) ;
67
+
68
+ // We want to ping people unless they've written an update since the last week of the previous month.
69
+ let days_threshold = now. day ( ) + 7 ;
70
+
71
+ // Format the 3rd Monday of the month, e.g. "on Sep-5", for inclusion.
72
+ let third_monday =
73
+ NaiveDate :: from_weekday_of_month_opt ( now. year ( ) , now. month ( ) , chrono:: Weekday :: Mon , 3 )
74
+ . unwrap ( )
75
+ . format ( "on %b-%d" )
76
+ . to_string ( ) ;
77
+
78
+ ping_project_goals_owners ( gh, false , days_threshold as i64 , & third_monday) . await
79
+ }
80
+
81
+ /// Sends a ping message to all project goal owners if
82
+ /// they have not posted an update in the last `days_threshold` days.
83
+ ///
84
+ /// `next_update` is a human readable description of when the next update
85
+ /// will be drafted (e.g., `"on Sep 5"`).
86
+ pub async fn ping_project_goals_owners (
87
+ gh : & GithubClient ,
88
+ dry_run : bool ,
89
+ days_threshold : i64 ,
90
+ next_update : & str ,
91
+ ) -> anyhow:: Result < ( ) > {
55
92
let goals_repo = gh. repository ( & RUST_PROJECT_GOALS_REPO ) . await ?;
56
93
57
94
let tracking_issues_query = github:: Query {
@@ -78,7 +115,7 @@ pub async fn ping_project_goals_owners(gh: &GithubClient, dry_run: bool) -> anyh
78
115
days_since_last_comment,
79
116
comments,
80
117
) ;
81
- if days_since_last_comment < 21 && comments > 1 {
118
+ if days_since_last_comment < days_threshold && comments > 1 {
82
119
continue ;
83
120
}
84
121
@@ -99,7 +136,8 @@ pub async fn ping_project_goals_owners(gh: &GithubClient, dry_run: bool) -> anyh
99
136
} ,
100
137
)
101
138
. replace ( "$GOALNUM" , & issue. number . to_string ( ) )
102
- . replace ( "$GOAL" , & issue. title ) ;
139
+ . replace ( "$GOAL" , & issue. title )
140
+ . replace ( "$NEXT_UPDATE" , next_update) ;
103
141
104
142
let zulip_req = crate :: zulip:: MessageApiRequest {
105
143
recipient : crate :: zulip:: Recipient :: Stream {
@@ -115,7 +153,9 @@ pub async fn ping_project_goals_owners(gh: &GithubClient, dry_run: bool) -> anyh
115
153
if !dry_run {
116
154
zulip_req. send ( & gh. raw ( ) ) . await ?;
117
155
} else {
118
- log:: debug!( "skipping zulip send because dry run" ) ;
156
+ eprintln ! ( ) ;
157
+ eprintln ! ( "-- Dry Run ------------------------------------" ) ;
158
+ eprintln ! ( "Would send to {zulip_topic_name}: {}" , zulip_req. content) ;
119
159
}
120
160
}
121
161
0 commit comments