Skip to content

Commit dbda01e

Browse files
authored
Merge pull request #1623 from apiraino/feat/add-all-compiler-wg-meetings
WG-prioritization: retrieve all T-compiler WG meetings
2 parents 116550a + 6b8f9c9 commit dbda01e

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

src/actions.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use chrono::{DateTime, Utc};
1+
use chrono::{DateTime, Duration, Utc};
22
use std::collections::HashMap;
33
use std::sync::Arc;
44

@@ -7,7 +7,10 @@ use reqwest::Client;
77
use serde::{Deserialize, Serialize};
88
use tera::{Context, Tera};
99

10-
use crate::github::{self, GithubClient, Repository};
10+
use crate::{
11+
github::{self, GithubClient, Repository},
12+
http_client::{CompilerMeeting, HttpClient},
13+
};
1114

1215
#[async_trait]
1316
pub trait Action {
@@ -86,6 +89,15 @@ impl<'a> Action for Step<'a> {
8689
async fn call(&self) -> anyhow::Result<String> {
8790
let gh = GithubClient::new_with_default_token(Client::new());
8891

92+
// retrieve all Rust compiler meetings
93+
// from today for 7 days
94+
let today: chrono::DateTime<chrono::Local> = chrono::Local::now();
95+
let tcompiler_meetings: Vec<CompilerMeeting> =
96+
CompilerMeeting::get_meetings(today, today + Duration::days(7))
97+
.await
98+
.map_err(|e| format!("Meetings couldn't be retrieved: {:?}", e))
99+
.unwrap_or_default();
100+
89101
let mut context = Context::new();
90102
let mut results = HashMap::new();
91103

@@ -143,6 +155,9 @@ impl<'a> Action for Step<'a> {
143155
let date = chrono::Utc::today().format("%Y-%m-%d").to_string();
144156
context.insert("CURRENT_DATE", &date);
145157

158+
// populate T-compiler meetings
159+
context.insert("meetings_tcompiler", &tcompiler_meetings);
160+
146161
Ok(TEMPLATES
147162
.render(&format!("{}.tt", self.name), &context)
148163
.unwrap())

src/http_client/mod.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use anyhow::Result;
2+
use async_trait::async_trait;
3+
use reqwest::Url;
4+
5+
#[derive(serde::Deserialize, serde::Serialize, Debug)]
6+
pub struct CompilerMeetings {
7+
items: Vec<CompilerMeeting>,
8+
}
9+
10+
#[derive(serde::Deserialize, serde::Serialize, Debug)]
11+
pub struct Start {
12+
#[serde(rename(deserialize = "dateTime"))]
13+
date_time: String,
14+
}
15+
16+
#[derive(serde::Deserialize, serde::Serialize, Debug)]
17+
pub struct CompilerMeeting {
18+
summary: String,
19+
#[serde(rename(deserialize = "htmlLink"))]
20+
html_link: String,
21+
#[serde(rename(deserialize = "originalStartTime"))]
22+
original_start: Option<Start>,
23+
start: Option<Start>,
24+
}
25+
26+
#[async_trait]
27+
pub trait HttpClient {
28+
async fn get_meetings(
29+
start_date: chrono::DateTime<chrono::Local>,
30+
end_date: chrono::DateTime<chrono::Local>,
31+
) -> Result<Vec<CompilerMeeting>>
32+
where
33+
Self: Sized;
34+
}
35+
36+
#[async_trait]
37+
impl HttpClient for CompilerMeeting {
38+
/// Retrieve all meetings from the Rust Compiler Team Calendar in a date range
39+
/// If a Google API auth token is not provided just return
40+
// Google calendar API documentation:
41+
// https://developers.google.com/calendar/api/v3/reference/events/list
42+
// The API token needs only one permission: https://www.googleapis.com/auth/calendar.events.readonly
43+
async fn get_meetings(
44+
start_date: chrono::DateTime<chrono::Local>,
45+
end_date: chrono::DateTime<chrono::Local>,
46+
) -> Result<Vec<CompilerMeeting>> {
47+
let api_key = match std::env::var("GOOGLE_API_KEY") {
48+
Ok(v) => v,
49+
Err(_) => {
50+
return Ok(vec![]);
51+
}
52+
};
53+
let google_calendar_id = "6u5rrtce6lrtv07pfi3damgjus%40group.calendar.google.com";
54+
let time_min = format!("{}T00:00:00+00:00", start_date.format("%F").to_string());
55+
let time_max = format!("{}T23:59:59+00:00", end_date.format("%F").to_string());
56+
let url = Url::parse_with_params(
57+
&format!(
58+
"https://www.googleapis.com/calendar/v3/calendars/{}/events",
59+
google_calendar_id
60+
),
61+
&[
62+
// see google docs for the meaning of these values
63+
("key", api_key),
64+
("timeMin", time_min),
65+
("timeMax", time_max),
66+
("singleEvents", "true".to_string()),
67+
],
68+
)?;
69+
let calendar = reqwest::get(url).await?.json::<CompilerMeetings>().await?;
70+
Ok(calendar.items)
71+
}
72+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod config;
1818
pub mod db;
1919
pub mod github;
2020
pub mod handlers;
21+
pub mod http_client;
2122
pub mod interactions;
2223
pub mod notification_listing;
2324
pub mod payload;

templates/_meetings.tt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% macro render(meetings, empty="No other meetings scheduled.") %}
2+
{%- for mtg in meetings %}
3+
- [{{ mtg.summary }}]({{ mtg.html_link }}) at <time:{{ mtg.start.date_time }}>{% else %}
4+
- {{empty}}{% endfor -%}
5+
{% endmacro %}

templates/prioritization_agenda.tt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% import "_issues.tt" as issues %}
2+
{% import "_meetings.tt" as meetings %}
23

34
---
45
tags: weekly, rustc
@@ -10,6 +11,9 @@ tags: weekly, rustc
1011

1112
## Announcements
1213

14+
### Other WG meetings ([calendar link](https://calendar.google.com/calendar/embed?src=6u5rrtce6lrtv07pfi3damgjus%40group.calendar.google.com))
15+
{{-meetings::render(meetings=meetings_tcompiler, empty="No meetings scheduled for next week")}}
16+
1317
- New MCPs (take a look, see if you like them!)
1418
{{-issues::render(issues=mcp_new_not_seconded, indent=" ", empty="No new proposals this time.")}}
1519
- Old MCPs (not seconded, take a look)

0 commit comments

Comments
 (0)