1
1
use crate :: db:: schedule_job;
2
2
use crate :: github;
3
3
use crate :: jobs:: Job ;
4
- use crate :: zulip:: BOT_EMAIL ;
5
- use crate :: zulip:: { to_zulip_id, MembersApiResponse } ;
6
- use anyhow:: { format_err, Context as _} ;
4
+ use anyhow:: Context as _;
7
5
use async_trait:: async_trait;
8
6
use chrono:: { Datelike , Duration , NaiveTime , TimeZone , Utc } ;
9
7
use serde:: { Deserialize , Serialize } ;
10
8
11
9
const TYPES_REPO : & ' static str = "rust-lang/types-team" ;
10
+ // T-types/meetings
11
+ const TYPES_MEETINGS_STREAM : u64 = 326132 ;
12
12
13
13
pub struct TypesPlanningMeetingThreadOpenJob ;
14
14
@@ -22,14 +22,18 @@ impl Job for TypesPlanningMeetingThreadOpenJob {
22
22
// On the last week of the month, we open a thread on zulip for the next Monday
23
23
let today = chrono:: Utc :: now ( ) . date ( ) . naive_utc ( ) ;
24
24
let first_monday = today + chrono:: Duration :: days ( 7 ) ;
25
+ // We actually schedule for every Monday, so first check if this is the last Monday of the month
26
+ if first_monday. month ( ) == today. month ( ) {
27
+ return Ok ( ( ) ) ;
28
+ }
25
29
let meeting_date_string = first_monday. format ( "%Y-%m-%d" ) . to_string ( ) ;
26
30
let message = format ! ( "\
27
31
Hello @*T-types/meetings*. Monthly planning meeting in one week.\n \
28
32
This is a reminder to update the current [roadmap tracking issues](https://github.com/rust-lang/types-team/issues?q=is%3Aissue+is%3Aopen+label%3Aroadmap-tracking-issue).\n \
29
33
Extra reminders will be sent later this week.") ;
30
34
let zulip_req = crate :: zulip:: MessageApiRequest {
31
35
recipient : crate :: zulip:: Recipient :: Stream {
32
- id : 326132 ,
36
+ id : TYPES_MEETINGS_STREAM ,
33
37
topic : & format ! ( "{meeting_date_string} planning meeting" ) ,
34
38
} ,
35
39
content : & message,
@@ -99,20 +103,9 @@ pub async fn request_updates(
99
103
100
104
let mut issues_needs_updates = vec ! [ ] ;
101
105
for issue in issues {
102
- // Github doesn't have a nice way to get the *last* comment; we would have to paginate all comments to get it.
103
- // For now, just bail out if there are more than 100 comments (if this ever becomes a problem, we will have to fix).
104
- let comments = issue. get_first100_comments ( gh) . await ?;
105
- if comments. len ( ) >= 100 {
106
- anyhow:: bail!(
107
- "Encountered types tracking issue with 100 or more comments; needs implementation."
108
- ) ;
109
- }
110
-
111
- // If there are any comments in the past 7 days, we consider this "updated". We *could* be more clever, but
106
+ // If the issue has been updated in the past 7 days, we consider this "updated". We *could* be more clever, but
112
107
// this is fine under the assumption that tracking issues should only contain updates.
113
- let older_than_7_days = comments
114
- . last ( )
115
- . map_or ( true , |c| c. updated_at < ( Utc :: now ( ) - Duration :: days ( 7 ) ) ) ;
108
+ let older_than_7_days = issue. updated_at < ( Utc :: now ( ) - Duration :: days ( 7 ) ) ;
116
109
if !older_than_7_days {
117
110
continue ;
118
111
}
@@ -166,7 +159,7 @@ pub async fn request_updates(
166
159
let meeting_date_string = metadata. date_string ;
167
160
let zulip_req = crate :: zulip:: MessageApiRequest {
168
161
recipient : crate :: zulip:: Recipient :: Stream {
169
- id : 326132 ,
162
+ id : TYPES_MEETINGS_STREAM ,
170
163
topic : & format ! ( "{meeting_date_string} planning meeting" ) ,
171
164
} ,
172
165
content : & message,
@@ -175,34 +168,3 @@ pub async fn request_updates(
175
168
176
169
Ok ( ( ) )
177
170
}
178
-
179
- #[ allow( unused) ] // Needed for commented out bit above
180
- async fn zulip_id_and_email (
181
- ctx : & super :: Context ,
182
- github_id : i64 ,
183
- ) -> anyhow:: Result < Option < ( u64 , String ) > > {
184
- let bot_api_token = std:: env:: var ( "ZULIP_API_TOKEN" ) . expect ( "ZULIP_API_TOKEN" ) ;
185
-
186
- let members = ctx
187
- . github
188
- . raw ( )
189
- . get ( "https://rust-lang.zulipchat.com/api/v1/users" )
190
- . basic_auth ( BOT_EMAIL , Some ( & bot_api_token) )
191
- . send ( )
192
- . await
193
- . map_err ( |e| format_err ! ( "Failed to get list of zulip users: {e:?}." ) ) ?;
194
- let members = members
195
- . json :: < MembersApiResponse > ( )
196
- . await
197
- . map_err ( |e| format_err ! ( "Failed to get list of zulip users: {e:?}." ) ) ?;
198
-
199
- let zulip_id = match to_zulip_id ( & ctx. github , github_id) . await {
200
- Ok ( Some ( id) ) => id as u64 ,
201
- Ok ( None ) => return Ok ( None ) ,
202
- Err ( e) => anyhow:: bail!( "Could not find Zulip ID for GitHub id {github_id}: {e:?}" ) ,
203
- } ;
204
-
205
- let user = members. members . iter ( ) . find ( |m| m. user_id == zulip_id) ;
206
-
207
- Ok ( user. map ( |m| ( m. user_id , m. email . clone ( ) ) ) )
208
- }
0 commit comments