Skip to content

Commit 42032de

Browse files
committed
add 'start_date' and 'end_date' as configuration props in 'report.toml'
1 parent b08f495 commit 42032de

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

src/metrics/list_repos.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use async_trait::async_trait;
2-
use chrono::Duration;
32
use stable_eyre::eyre;
43
use tokio::sync::mpsc::Sender;
4+
use toml::value::Datetime;
55

66
use super::{util, Graphql, Producer};
77

@@ -10,21 +10,24 @@ pub struct ListReposForOrg {
1010
graphql: Graphql,
1111
org_name: String,
1212
repo_names: Vec<String>,
13-
number_of_days: i64,
13+
start_date: Datetime,
14+
end_date: Datetime,
1415
}
1516

1617
impl ListReposForOrg {
1718
pub fn new(
1819
graphql: Graphql,
1920
org_name: String,
2021
repo_names: Vec<String>,
21-
number_of_days: i64,
22+
start_date: Datetime,
23+
end_date: Datetime,
2224
) -> Self {
2325
ListReposForOrg {
2426
graphql,
2527
org_name,
2628
repo_names,
27-
number_of_days,
29+
start_date,
30+
end_date,
2831
}
2932
}
3033
}
@@ -41,7 +44,8 @@ impl Producer for ListReposForOrg {
4144
&mut self.graphql,
4245
&self.org_name,
4346
&repo,
44-
Duration::days(self.number_of_days),
47+
&self.start_date,
48+
&self.end_date,
4549
)
4650
.await?;
4751
tx.send(vec![repo.to_owned(), count_prs.to_string()])

src/metrics/repo_participants.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
use std::collections::{HashMap, HashSet};
22

33
use async_trait::async_trait;
4-
use chrono::{Duration, Utc};
54
use fehler::throws;
65
use graphql_client::GraphQLQuery;
76
use stable_eyre::eyre;
87
use stable_eyre::eyre::Error;
98
use tokio::sync::mpsc::Sender;
9+
use toml::value::Datetime;
1010

1111
use super::{Graphql, Producer};
1212

1313
pub struct RepoParticipants {
1414
graphql: Graphql,
1515
org_name: String,
1616
repo_names: Vec<String>,
17-
number_of_days: i64,
17+
start_date: Datetime,
18+
end_date: Datetime,
1819
}
1920

2021
impl RepoParticipants {
2122
pub fn new(
2223
graphql: Graphql,
2324
org_name: String,
2425
repo_names: Vec<String>,
25-
number_of_days: i64,
26+
start_date: Datetime,
27+
end_date: Datetime,
2628
) -> Self {
2729
Self {
2830
graphql,
2931
org_name,
3032
repo_names,
31-
number_of_days,
33+
start_date,
34+
end_date,
3235
}
3336
}
3437
}
@@ -53,7 +56,8 @@ impl Producer for RepoParticipants {
5356
&mut self.graphql,
5457
&self.org_name,
5558
repo_name,
56-
Duration::days(self.number_of_days),
59+
&self.start_date,
60+
&self.end_date,
5761
)
5862
.await?;
5963

@@ -113,16 +117,9 @@ async fn pr_participants(
113117
graphql: &mut Graphql,
114118
org_name: &str,
115119
repo_name: &str,
116-
time_period: Duration,
120+
start_date: &Datetime,
121+
end_date: &Datetime,
117122
) -> Vec<(String, ParticipantCounts)> {
118-
// get date string to match GitHub's PR query format for `created` field
119-
// i.e., "2021-05-18UTC" turns into "2021-05-18"
120-
let date_str = chrono::NaiveDate::parse_from_str(
121-
&format!("{}", (Utc::now() - time_period).date())[..],
122-
"%FUTC",
123-
)
124-
.unwrap();
125-
126123
// Tracks, for each github login, how many PRs they participated in on this repository.
127124
let mut counts: HashMap<String, ParticipantCounts> = HashMap::new();
128125

@@ -133,10 +130,11 @@ async fn pr_participants(
133130
.query(PrsAndParticipants)
134131
.execute(pap::Variables {
135132
query_string: format!(
136-
r#"repo:{org_name}/{repo_name} is:pr created:>{date_str}"#,
133+
r#"repo:{org_name}/{repo_name} is:pr created:{start_date}..{end_date}"#,
137134
org_name = org_name,
138135
repo_name = repo_name,
139-
date_str = date_str,
136+
start_date = start_date,
137+
end_date = end_date,
140138
),
141139
after_cursor,
142140
})

src/metrics/util.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use super::Graphql;
2-
use chrono::{Duration, Utc};
31
use fehler::throws;
42
use graphql_client::GraphQLQuery;
53
use stable_eyre::eyre::Error;
4+
use toml::value::Datetime;
5+
6+
use super::Graphql;
67

78
#[derive(GraphQLQuery)]
89
#[graphql(
@@ -74,19 +75,12 @@ pub(super) async fn count_pull_requests(
7475
graphql: &mut Graphql,
7576
org_name: &str,
7677
repo_name: &str,
77-
time_period: Duration,
78+
start_date: &Datetime,
79+
end_date: &Datetime,
7880
) -> usize {
79-
// get date string to match GitHub's PR query format for `created` field
80-
// i.e., "2021-05-18UTC" turns into "2021-05-18"
81-
let date_str = chrono::NaiveDate::parse_from_str(
82-
&format!("{}", (Utc::now() - time_period).date())[..],
83-
"%FUTC",
84-
)
85-
.unwrap();
86-
8781
let query_string = format!(
88-
r#"repo:{}/{} is:pr created:>{}"#,
89-
org_name, repo_name, date_str,
82+
r#"repo:{}/{} is:pr created:{}..{}"#,
83+
org_name, repo_name, start_date, end_date
9084
);
9185

9286
let response = graphql

src/report.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{fs::File, path::PathBuf};
55
use fehler::throws;
66
use serde::Deserialize;
77
use stable_eyre::eyre::{self, Error, WrapErr};
8+
use toml::value::Datetime;
89

910
use crate::metrics::Consumer;
1011
use crate::metrics::{self, Graphql};
@@ -44,7 +45,8 @@ struct GithubConfig {
4445

4546
#[derive(Deserialize, Debug)]
4647
struct DataSourceConfig {
47-
number_of_days: i64,
48+
start_date: Datetime,
49+
end_date: Datetime,
4850
}
4951

5052
#[derive(Deserialize, Debug)]

src/report/repo_info.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl Report {
3636
graphql,
3737
config.github.org.clone(),
3838
config.github.repos.clone(),
39-
config.data_source.number_of_days,
39+
config.data_source.start_date.clone(),
40+
config.data_source.end_date.clone(),
4041
),
4142
)
4243
.await

src/report/repo_participant.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ impl Report {
4646
graphql,
4747
config.github.org.clone(),
4848
config.github.repos.clone(),
49-
config.data_source.number_of_days,
49+
config.data_source.start_date.clone(),
50+
config.data_source.end_date.clone(),
5051
),
5152
)
5253
.await

0 commit comments

Comments
 (0)