Skip to content

Commit 727ed43

Browse files
authored
Include more structured data in batch members (#70)
1 parent df3d47f commit 727ed43

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/course.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ pub enum AssignmentOptionality {
347347
Stretch,
348348
}
349349

350+
#[derive(Serialize)]
350351
pub struct BatchMembers {
351352
pub name: String,
352353
pub trainees: BTreeMap<GithubLogin, Trainee>,

src/endpoints.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
ops::AddAssign,
44
};
55

6-
use ::octocrab::models::{Author, teams::RequestedTeam};
6+
use ::octocrab::models::teams::RequestedTeam;
77
use anyhow::Context;
88
use axum::{
99
Json,
@@ -19,6 +19,7 @@ use tower_sessions::Session;
1919

2020
use crate::{
2121
Error, ServerState,
22+
course::{BatchMembers, get_batch_members},
2223
github_accounts::get_trainees,
2324
newtypes::GithubLogin,
2425
octocrab::{all_pages, octocrab, octocrab_for_maybe_token},
@@ -104,30 +105,27 @@ pub async fn trainee_batches(
104105
}))
105106
}
106107

107-
#[derive(Serialize)]
108-
pub struct Batch {
109-
trainees: Vec<String>,
110-
}
111-
112108
pub async fn trainee_batch(
113109
session: Session,
110+
headers: HeaderMap,
114111
State(server_state): State<ServerState>,
115112
OriginalUri(original_uri): OriginalUri,
116113
Path((_course, batch)): Path<(String, String)>,
117-
) -> Result<Json<Batch>, Error> {
118-
let octocrab = octocrab(&session, &server_state, original_uri).await?;
119-
let trainees = all_pages("team members", &octocrab, async || {
120-
octocrab
121-
.teams(server_state.config.github_org)
122-
.members(batch)
123-
.send()
124-
.await
125-
})
126-
.await?
127-
.into_iter()
128-
.map(|Author { login, .. }| login)
129-
.collect();
130-
Ok(Json(Batch { trainees }))
114+
) -> Result<Json<BatchMembers>, Error> {
115+
let octocrab = octocrab(&session, &server_state, original_uri.clone()).await?;
116+
let sheets_client =
117+
sheets_client(&session, server_state.clone(), headers, original_uri).await?;
118+
119+
let batch_members = get_batch_members(
120+
&octocrab,
121+
sheets_client,
122+
&server_state.config.github_email_mapping_sheet_id,
123+
&server_state.config.github_org,
124+
&batch,
125+
)
126+
.await?;
127+
128+
Ok(Json(batch_members))
131129
}
132130

133131
pub async fn teams(

0 commit comments

Comments
 (0)