Skip to content

Commit f39eda3

Browse files
committed
Remove unnecessary system time info from submissions and small updates to courses mooc support
1 parent 3049375 commit f39eda3

File tree

11 files changed

+42
-14
lines changed

11 files changed

+42
-14
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ cargo test
4040

4141
The `docker.sh` script can be conveniently used to build and test the project. To build the binary and copy it out of the container to the project root, simply run `docker.sh`. To run tests, you can run `docker.sh "cargo test"`, or `docker.sh "cargo test -p tmc-langs-r"` and so on. The script also supports the special argument `interactive` to launch into an interactive bash shell inside the Docker container.
4242

43+
## Generating the TypeScript bindings
44+
45+
```bash
46+
cargo test --features ts-rs generate_cli_bindings -- --ignored
47+
```
48+
49+
The bindings are written to `crates/tmc-langs-cli/bindings.d.ts`.
50+
4351
## Formatting and linting
4452

4553
Use `cargo +nightly fmt` and `cargo clippy` for formatting and linting. All crates should have the clippy lints `print_stdout` and `print_stderr` set to deny to allow the CLI to have total control over stdout and stderr. The CLI has one function where writing to stdout is allowed.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings/tmc-langs-node/src/bin/generate-node-bindings.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ fn main() {
3737
tmc_langs::ExerciseDownload,
3838
// getCourseData
3939
tmc_langs::CombinedCourseData,
40+
41+
// TMC
4042
// getCourseData
4143
tmc_langs::tmc::response::CourseDetails,
4244
tmc_langs::tmc::response::Exercise,
@@ -75,6 +77,10 @@ fn main() {
7577
tmc_langs::tmc::response::SubmissionFeedbackKind,
7678
// listSettings
7779
tmc_langs::TmcConfig,
80+
81+
// MOOC
82+
// course-instances
83+
tmc_langs::mooc::CourseInstance,
7884
}
7985
.unwrap();
8086
println!("Wrote bindings to `{path}`");

crates/tmc-langs-cli/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Binaries for the supported targets are built and the binaries deployed to Google
2222

2323
| var name | usage |
2424
| -------------------------------- | -------------------------------------------------------------- |
25-
| `TMC_LANGS_TMC_ROOT_URL` | Sets the TMC server url. |
25+
| `TMC_LANGS_LOG` | Sets the logging level. |
26+
| `TMC_LANGS_TMC_ROOT_URL` | Sets the courses.mooc.fi server url. |
27+
| `TMC_LANGS_MOOC_ROOT_URL` | Sets the tmc.mooc.fi server url. |
2628
| `TMC_LANGS_CONFIG_DIR` | Sets the config directory. |
2729
| `TMC_LANGS_DEFAULT_PROJECTS_DIR` | Sets the default projects directory. |
2830
| `TMC_SANDBOX` | If set, the CLI considers itself to be running in tmc-sandbox. |

crates/tmc-langs-cli/bindings.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export interface TmcConfig { projects_dir: string, }
110110

111111
export interface CourseInstance { id: string, course_id: string, course_slug: string, course_name: string, course_description: string | null, instance_name: string | null, instance_description: string | null, }
112112

113-
export interface TmcExerciseSlide { slide_id: string, exercise_id: string, exercise_name: string, exercise_order_number: number, deadline: Date | null, tasks: Array<TmcExerciseTask>, }
113+
export interface TmcExerciseSlide { slide_id: string, exercise_id: string, exercise_name: string, exercise_order_number: number, deadline: string | null, tasks: Array<TmcExerciseTask>, }
114114

115115
export interface TmcExerciseTask { task_id: string, order_number: number, assignment: unknown, public_spec: PublicSpec | null, model_solution_spec: ModelSolutionSpec | null, }
116116

crates/tmc-langs-cli/src/app.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use clap::Parser;
55
use schemars::JsonSchema;
66
use std::{path::PathBuf, str::FromStr};
77
use tmc_langs::{
8+
mooc::CourseInstance,
89
tmc::{
910
response::{
1011
Course, CourseData, CourseDetails, CourseExercise, ExerciseDetails, NewSubmission,
@@ -541,6 +542,8 @@ pub struct Mooc {
541542

542543
#[derive(Parser)]
543544
pub enum MoocCommand {
545+
/// Fetches the user's enrolled courses.
546+
#[clap(long_about = schema_leaked::<Vec<CourseInstance>>())]
544547
CourseInstances,
545548
CourseInstanceExercises {
546549
#[clap(long)]

crates/tmc-langs-cli/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,8 @@ fn run_tmc_inner(
972972
}
973973

974974
fn run_mooc(mooc: Mooc) -> Result<CliOutput> {
975-
let root_url =
976-
env::var("TMC_LANGS_MOOC_ROOT_URL").unwrap_or_else(|_| "https://tmc.mooc.fi".to_string());
975+
let root_url = env::var("TMC_LANGS_MOOC_ROOT_URL")
976+
.unwrap_or_else(|_| "https://courses.mooc.fi".to_string());
977977

978978
let (mut client, credentials) =
979979
tmc_langs::init_mooc_client_with_credentials(root_url, &mooc.client_name)?;

crates/tmc-langs-cli/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ use tmc_langs_cli::{
1212
};
1313

1414
fn main() -> ExitCode {
15+
// convert `TMC_LANGS_LOG` into the appropriate `RUST_LOG`
16+
if let Ok(level) = std::env::var("TMC_LANGS_LOG") {
17+
let level = level.to_uppercase();
18+
let level = match level.as_str() {
19+
"WARN" => "WARN,reqwest=ERROR,rustls=ERROR",
20+
"INFO" => "INFO,reqwest=WARN,rustls=WARN",
21+
"DEBUG" => "DEBUG,reqwest=INFO,rustls=INFO",
22+
"TRACE" => "TRACE,reqwest=DEBUG,rustls=DEBUG",
23+
other => other,
24+
};
25+
let _ = std::env::set_var("RUST_LOG", level);
26+
}
27+
1528
env_logger::init();
1629
match run() {
1730
Ok(()) => ExitCode::SUCCESS,

crates/tmc-mooc-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ reqwest = { version = "0.11.18", default-features = false, features = [
2121
"multipart",
2222
"cookies",
2323
] }
24+
schemars = { version = "0.8.8", features = ["uuid1"] }
2425
serde = { version = "1.0.163", features = ["derive"] }
2526
serde_json = "1.0.96"
2627
thiserror = "1.0.40"

crates/tmc-mooc-client/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use reqwest::{
2121
},
2222
Method, StatusCode,
2323
};
24+
use schemars::JsonSchema;
2425
use serde::{de::DeserializeOwned, Serialize};
2526
use std::{borrow::Cow, path::Path, sync::Arc};
2627
use tmc_langs_util::{serialize, JsonError};
@@ -61,7 +62,7 @@ impl MoocClient {
6162
fn request_to_url(&self, method: Method, url: String) -> MoocRequest {
6263
log::debug!("building a request to {url}");
6364

64-
let trusted_urls = &["https://courses.mooc.fi/", "http://project-331.local"];
65+
let trusted_urls = &["https://courses.mooc.fi/", "http://project-331.local/"];
6566
let include_bearer_token = trusted_urls.iter().any(|tu| url.starts_with(tu));
6667
let mut builder = self.0.client.request(method.clone(), url.clone());
6768
if let Some(token) = self.0.token.as_ref() {
@@ -276,7 +277,7 @@ impl MoocRequest {
276277
}
277278
}
278279

279-
#[derive(Debug, Serialize)]
280+
#[derive(Debug, Serialize, JsonSchema)]
280281
#[cfg_attr(feature = "ts-rs", derive(TS))]
281282
pub struct CourseInstance {
282283
pub id: Uuid,

0 commit comments

Comments
 (0)