Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/bin/match-pr-to-assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use chrono::NaiveDate;
use indexmap::IndexMap;
use trainee_tracker::{
config::{CourseSchedule, CourseScheduleWithRegisterSheetId},
course::match_prs_to_assignments,
course::{Assignment, Submission, SubmissionState, match_prs_to_assignments},
newtypes::Region,
octocrab::octocrab_for_token,
prs::get_prs,
setup_logging,
};

#[tokio::main]
Expand All @@ -19,6 +20,8 @@ async fn main() {
exit(1);
};

setup_logging();

let octocrab = octocrab_for_token(github_token.to_owned()).expect("Failed to get octocrab");

let Ok(
Expand Down Expand Up @@ -58,7 +61,7 @@ async fn main() {
.map(|region| (Region(region.to_string()), fixed_date))
.collect()
})
.take(3)
.take(5)
.collect(),
);
let course_schedule = CourseSchedule {
Expand Down Expand Up @@ -106,10 +109,23 @@ async fn main() {
.iter()
.zip(sprint_with_submissions.submissions.iter())
{
println!("{:?} - {:?}", assignment, submission);
if let Assignment::ExpectedPullRequest { title, .. } = assignment {
let text = match submission {
SubmissionState::Some(Submission::PullRequest { pull_request, .. }) => {
format!("{} ({})", pull_request.title, pull_request.url)
}
SubmissionState::MissingButExpected(..) => "MissingButExpected".to_owned(),
SubmissionState::MissingButNotExpected(..) => {
"MissingButNotExpected".to_owned()
}
SubmissionState::MissingStretch(..) => "MissingStretch".to_owned(),
SubmissionState::Some(..) => "Wrong submission type".to_owned(),
};
println!("{} - {}", title, text);
}
}
}
for unknown in matched.unknown_prs {
println!("Unknown PR: {:?}", unknown);
println!("Unknown PR: {:#?}", unknown);
}
}
13 changes: 2 additions & 11 deletions src/bin/trainee-tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use axum::routing::{get, post};
use dotenv::dotenv;
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer};
use tracing::info;
use tracing_subscriber::prelude::*;
use trainee_tracker::{Config, ServerState};
use trainee_tracker::{Config, ServerState, setup_logging};

use std::net::SocketAddr;

Expand All @@ -17,15 +16,7 @@ async fn main() {
);
}

let stderr_log_level = tracing_subscriber::filter::LevelFilter::INFO;
let stderr_layer = tracing_subscriber::fmt::layer()
.pretty()
.with_writer(std::io::stderr);

tracing_subscriber::registry()
.with(stderr_layer.with_filter(stderr_log_level))
.try_init()
.expect("Failed to configure logging");
setup_logging();

if let Err(err) = dotenv() {
if !err.not_found() {
Expand Down
11 changes: 9 additions & 2 deletions src/course.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use octocrab::{
};
use regex::Regex;
use serde::Serialize;
use tracing::debug;
use url::Url;

impl CourseScheduleWithRegisterSheetId {
Expand Down Expand Up @@ -945,11 +946,12 @@ fn match_pr_to_assignment(
continue;
}
}
let mut pr_title_words = title_word_set(&pr.title);
let mut pr_title_words = title_word_set(pr.title.split("|").last().unwrap_or_default());
if let Some(claimed_sprint_index) = claimed_sprint_index {
let claimed_sprint_number = claimed_sprint_index + 1;
pr_title_words.insert(format!("sprint{}", claimed_sprint_number));
}
debug!(pr=pr.title, title_words=?pr_title_words, "Considering PR");

for (assignment_index, assignment) in sprint.assignments.iter().enumerate() {
match assignment {
Expand All @@ -969,13 +971,18 @@ fn match_pr_to_assignment(
}
}
let match_count = assignment_title_words.intersection(&pr_title_words).count();
debug!(
?assignment_title_words,
match_count, "Comparing to assignment"
);
if !submissions[sprint_index].submissions[assignment_index].is_submitted()
&& match_count
> best_match
.as_ref()
.map(|best_match| best_match.match_count)
.unwrap_or_default()
{
debug!(match_count, "Best match!");
best_match = Some(Match {
match_count,
sprint_index,
Expand Down Expand Up @@ -1047,10 +1054,10 @@ fn title_word_set(title: &str) -> IndexSet<String> {
title
.to_lowercase()
.split(" ")
.filter(|s| !s.is_empty())
.flat_map(|word| word.split("_"))
.flat_map(|word| word.split("-"))
.flat_map(|word| word.split("/"))
.flat_map(|word| word.split("|"))
.map(|s| s.to_owned())
.collect()
}
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use axum::response::{Html, IntoResponse, Response};
use moka::future::Cache;
use slack_with_types::client::RateLimiter;
use tracing::error;
use tracing_subscriber::Layer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use uuid::Uuid;

pub mod auth;
Expand Down Expand Up @@ -145,3 +148,15 @@ impl From<anyhow::Error> for Error {
Error::Fatal(error)
}
}

pub fn setup_logging() {
let stderr_log_level = tracing_subscriber::filter::LevelFilter::INFO;
let stderr_layer = tracing_subscriber::fmt::layer()
.pretty()
.with_writer(std::io::stderr);

tracing_subscriber::registry()
.with(stderr_layer.with_filter(stderr_log_level))
.try_init()
.expect("Failed to configure logging");
}