Skip to content

Commit 70cc40b

Browse files
committed
Sort meetings by scheduled date
1 parent 213da2a commit 70cc40b

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

github-graphql/src/lib.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
pub mod queries {
88
use super::schema;
99

10+
pub type Date = chrono::NaiveDate;
1011
pub type DateTime = chrono::DateTime<chrono::Utc>;
1112

13+
cynic::impl_scalar!(Date, schema::Date);
1214
cynic::impl_scalar!(DateTime, schema::DateTime);
1315

1416
#[derive(cynic::QueryVariables, Debug, Clone)]
@@ -272,8 +274,8 @@ mod schema {
272274
}
273275

274276
#[cynic::schema_for_derives(file = "src/github.graphql", module = "schema")]
275-
pub mod project_items_by_status {
276-
use super::queries::{PageInfo, Uri};
277+
pub mod project_items {
278+
use super::queries::{Date, PageInfo, Uri};
277279
use super::schema;
278280

279281
#[derive(cynic::QueryVariables, Debug, Clone)]
@@ -312,13 +314,25 @@ pub mod project_items_by_status {
312314
#[derive(cynic::QueryFragment, Debug)]
313315
pub struct ProjectV2Item {
314316
pub content: Option<ProjectV2ItemContent>,
317+
318+
// Currently we hard code the field names we care about here.
319+
#[cynic(rename = "fieldValueByName")]
315320
#[arguments(name = "Status")]
316-
pub field_value_by_name: Option<ProjectV2ItemFieldValue>,
321+
pub status: Option<ProjectV2ItemFieldValue>,
322+
#[cynic(rename = "fieldValueByName")]
323+
#[arguments(name = "Date")]
324+
pub date: Option<ProjectV2ItemFieldValue>,
317325
}
318326

319327
impl ProjectV2Item {
320-
pub fn status(&self) -> &Option<ProjectV2ItemFieldValue> {
321-
&self.field_value_by_name
328+
pub fn status(&self) -> Option<&str> {
329+
let Some(ref status) = self.status else { return None };
330+
status.as_str()
331+
}
332+
333+
pub fn date(&self) -> Option<Date> {
334+
let Some(ref date) = self.date else { return None };
335+
date.as_date()
322336
}
323337
}
324338

@@ -333,6 +347,7 @@ pub mod project_items_by_status {
333347
#[derive(cynic::InlineFragments, Debug)]
334348
pub enum ProjectV2ItemFieldValue {
335349
ProjectV2ItemFieldSingleSelectValue(ProjectV2ItemFieldSingleSelectValue),
350+
ProjectV2ItemFieldDateValue(ProjectV2ItemFieldDateValue),
336351

337352
#[cynic(fallback)]
338353
Other,
@@ -345,6 +360,13 @@ pub mod project_items_by_status {
345360
_ => return None,
346361
})
347362
}
363+
364+
pub fn as_date(&self) -> Option<Date> {
365+
match self {
366+
Self::ProjectV2ItemFieldDateValue(val) => val.date,
367+
_ => None,
368+
}
369+
}
348370
}
349371

350372
#[derive(cynic::QueryFragment, Debug)]
@@ -358,4 +380,9 @@ pub mod project_items_by_status {
358380
pub struct ProjectV2ItemFieldSingleSelectValue {
359381
pub name: Option<String>,
360382
}
383+
384+
#[derive(cynic::QueryFragment, Debug)]
385+
pub struct ProjectV2ItemFieldDateValue {
386+
pub date: Option<Date>,
387+
}
361388
}

src/github.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,23 +2116,23 @@ impl IssuesQuery for LeastRecentlyReviewedPullRequests {
21162116
async fn project_items_by_status(
21172117
client: &GithubClient,
21182118
status_filter: impl Fn(Option<&str>) -> bool,
2119-
) -> anyhow::Result<Vec<github_graphql::project_items_by_status::ProjectV2ItemContent>> {
2119+
) -> anyhow::Result<Vec<github_graphql::project_items::ProjectV2Item>> {
21202120
use cynic::QueryBuilder;
2121-
use github_graphql::project_items_by_status;
2121+
use github_graphql::project_items;
21222122

21232123
const DESIGN_MEETING_PROJECT: i32 = 31;
2124-
let mut args = project_items_by_status::Arguments {
2124+
let mut args = project_items::Arguments {
21252125
project_number: DESIGN_MEETING_PROJECT,
21262126
after: None,
21272127
};
21282128

21292129
let mut all_items = vec![];
21302130
loop {
2131-
let query = project_items_by_status::Query::build(args.clone());
2131+
let query = project_items::Query::build(args.clone());
21322132
let req = client.post(Repository::GITHUB_GRAPHQL_API_URL);
21332133
let req = req.json(&query);
21342134

2135-
let data: cynic::GraphQlResponse<project_items_by_status::Query> = client.json(req).await?;
2135+
let data: cynic::GraphQlResponse<project_items::Query> = client.json(req).await?;
21362136
if let Some(errors) = data.errors {
21372137
anyhow::bail!("There were graphql errors. {:?}", errors);
21382138
}
@@ -2149,14 +2149,7 @@ async fn project_items_by_status(
21492149
.ok_or_else(|| anyhow!("Malformed response."))?
21502150
.into_iter()
21512151
.flatten()
2152-
.filter(|item| {
2153-
status_filter(
2154-
item.field_value_by_name
2155-
.as_ref()
2156-
.and_then(|status| status.as_str()),
2157-
)
2158-
})
2159-
.flat_map(|item| item.content);
2152+
.filter(|item| status_filter(item.status()));
21602153
all_items.extend(filtered);
21612154

21622155
let page_info = items.page_info;
@@ -2166,6 +2159,7 @@ async fn project_items_by_status(
21662159
args.after = page_info.end_cursor;
21672160
}
21682161

2162+
all_items.sort_by_key(|item| item.date());
21692163
Ok(all_items)
21702164
}
21712165

@@ -2199,15 +2193,15 @@ impl IssuesQuery for DesignMeetings {
21992193
_include_fcp_details: bool,
22002194
client: &'a GithubClient,
22012195
) -> anyhow::Result<Vec<crate::actions::IssueDecorator>> {
2202-
use github_graphql::project_items_by_status::ProjectV2ItemContent;
2196+
use github_graphql::project_items::ProjectV2ItemContent;
22032197

22042198
let items =
22052199
project_items_by_status(client, |status| status == self.with_status.query_str())
22062200
.await?;
22072201
Ok(items
22082202
.into_iter()
2209-
.flat_map(|item| match item {
2210-
ProjectV2ItemContent::Issue(issue) => Some(crate::actions::IssueDecorator {
2203+
.flat_map(|item| match item.content {
2204+
Some(ProjectV2ItemContent::Issue(issue)) => Some(crate::actions::IssueDecorator {
22112205
assignees: String::new(),
22122206
number: issue.number.try_into().unwrap(),
22132207
fcp_details: None,

0 commit comments

Comments
 (0)