Skip to content

Commit b9d17bc

Browse files
committed
Review comments and fix cron expression
1 parent 6fb7a7d commit b9d17bc

File tree

2 files changed

+14
-51
lines changed

2 files changed

+14
-51
lines changed

src/handlers/types_planning_updates.rs

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use crate::db::schedule_job;
22
use crate::github;
33
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 _;
75
use async_trait::async_trait;
86
use chrono::{Datelike, Duration, NaiveTime, TimeZone, Utc};
97
use serde::{Deserialize, Serialize};
108

119
const TYPES_REPO: &'static str = "rust-lang/types-team";
10+
// T-types/meetings
11+
const TYPES_MEETINGS_STREAM: u64 = 326132;
1212

1313
pub struct TypesPlanningMeetingThreadOpenJob;
1414

@@ -22,14 +22,18 @@ impl Job for TypesPlanningMeetingThreadOpenJob {
2222
// On the last week of the month, we open a thread on zulip for the next Monday
2323
let today = chrono::Utc::now().date().naive_utc();
2424
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+
}
2529
let meeting_date_string = first_monday.format("%Y-%m-%d").to_string();
2630
let message = format!("\
2731
Hello @*T-types/meetings*. Monthly planning meeting in one week.\n\
2832
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\
2933
Extra reminders will be sent later this week.");
3034
let zulip_req = crate::zulip::MessageApiRequest {
3135
recipient: crate::zulip::Recipient::Stream {
32-
id: 326132,
36+
id: TYPES_MEETINGS_STREAM,
3337
topic: &format!("{meeting_date_string} planning meeting"),
3438
},
3539
content: &message,
@@ -99,20 +103,9 @@ pub async fn request_updates(
99103

100104
let mut issues_needs_updates = vec![];
101105
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
112107
// 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));
116109
if !older_than_7_days {
117110
continue;
118111
}
@@ -166,7 +159,7 @@ pub async fn request_updates(
166159
let meeting_date_string = metadata.date_string;
167160
let zulip_req = crate::zulip::MessageApiRequest {
168161
recipient: crate::zulip::Recipient::Stream {
169-
id: 326132,
162+
id: TYPES_MEETINGS_STREAM,
170163
topic: &format!("{meeting_date_string} planning meeting"),
171164
},
172165
content: &message,
@@ -175,34 +168,3 @@ pub async fn request_updates(
175168

176169
Ok(())
177170
}
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-
}

src/jobs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ pub fn default_jobs() -> Vec<JobSchedule> {
9292
},
9393
JobSchedule {
9494
name: TypesPlanningMeetingThreadOpenJob.name(),
95-
// Last Monday of every month
96-
schedule: Schedule::from_str("0 0 12 ? * 2L *").unwrap(),
95+
// We want last Monday of every month, but cron unfortunately doesn't support that
96+
// Instead, every Monday and we can check
97+
schedule: Schedule::from_str("0 0 12 ? * * *").unwrap(),
9798
metadata: serde_json::Value::Null,
9899
},
99100
]

0 commit comments

Comments
 (0)