Compare commits

..

No commits in common. "652b83b54116a6f608816347b25d306d8aef69fd" and "76a047b9cae0e66e53577cd1557608508bd70aab" have entirely different histories.

8 changed files with 1 additions and 129 deletions

View file

@ -12,10 +12,6 @@ mod scanner;
mod tests;
fn main() -> Result<()> {
run()
}
fn run() -> std::result::Result<(), anyhow::Error> {
println!("Forgejo TODO Checker!");
let config = init_config()?;

View file

@ -3,11 +3,10 @@ use std::path::Path;
use crate::model::{Config, FoundMarkers, Line, Marker};
use anyhow::Result;
use ignore::Walk;
pub fn find_markers(config: Config) -> Result<FoundMarkers, anyhow::Error> {
let mut markers = FoundMarkers::default();
for file in Walk::new(config.fs().base()).flatten() {
for file in ignore::Walk::new(config.fs().base()).flatten() {
let path = file.path();
if config.fs().path_is_file(path)? {
scan_file(path, &config, &mut markers)?;

View file

@ -1,7 +0,0 @@
This is a text file.
It contains a todo comment: // TODO: this is it
It also contains a fix-me comment: // FIXME: and this is it
Both of these are missing an issue identifier.

View file

@ -1,5 +0,0 @@
This is another text file.
It also has a todo comment: // TODO: (#23) and it has an issue number
Here is a fix-me comment: // FIXME: (#43) and is also has an issue number

View file

@ -8,7 +8,6 @@ use patterns::{issue_pattern, marker_pattern};
#[test]
fn init_when_all_valid() -> anyhow::Result<()> {
//given
let _env = THE_ENVIRONMENT.lock();
let fs = kxio::fs::temp()?;
std::env::set_var("GITHUB_WORKSPACE", fs.base());
std::env::set_var("GITHUB_REPOSITORY", "repo");
@ -44,7 +43,6 @@ fn init_when_all_valid() -> anyhow::Result<()> {
#[test]
fn init_when_no_workspace() -> anyhow::Result<()> {
//given
let _env = THE_ENVIRONMENT.lock();
std::env::remove_var("GITHUB_WORKSPACE");
std::env::set_var("GITHUB_REPOSITORY", "repo");
std::env::set_var("GITHUB_SERVER_URL", "server");
@ -62,7 +60,6 @@ fn init_when_no_workspace() -> anyhow::Result<()> {
#[test]
fn init_when_no_repository() -> anyhow::Result<()> {
//given
let _env = THE_ENVIRONMENT.lock();
let fs = kxio::fs::temp()?;
std::env::set_var("GITHUB_WORKSPACE", fs.base());
std::env::remove_var("GITHUB_REPOSITORY");
@ -81,7 +78,6 @@ fn init_when_no_repository() -> anyhow::Result<()> {
#[test]
fn init_when_no_server_url() -> anyhow::Result<()> {
//given
let _env = THE_ENVIRONMENT.lock();
let fs = kxio::fs::temp()?;
std::env::set_var("GITHUB_WORKSPACE", fs.base());
std::env::set_var("GITHUB_REPOSITORY", "repo");

View file

@ -1,10 +1,4 @@
use std::sync::{LazyLock, Mutex};
//
use super::*;
mod init;
mod run;
mod scanner;
pub static THE_ENVIRONMENT: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));

View file

@ -1,54 +0,0 @@
//
use super::*;
use anyhow::Result;
#[test]
fn run_with_some_invalids() -> Result<()> {
//given
let _env = THE_ENVIRONMENT.lock();
let fs = kxio::fs::temp()?;
fs.file_write(
&fs.base().join("file_with_invalids.txt"),
include_str!("data/file_with_invalids.txt"),
)?;
fs.file_write(
&fs.base().join("file_with_valids.txt"),
include_str!("data/file_with_valids.txt"),
)?;
std::env::set_var("GITHUB_WORKSPACE", fs.base());
std::env::set_var("GITHUB_REPOSITORY", "kemitix/test");
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
//when
run()?;
//then
// TODO: add check that run fails because file_1.txt is invalid
// TODO: add check that network requests were made to get issues
Ok(())
}
#[test]
fn run_with_no_invalids() -> Result<()> {
//given
let _env = THE_ENVIRONMENT.lock();
let fs = kxio::fs::temp()?;
fs.file_write(
&fs.base().join("file_with_valids.txt"),
include_str!("data/file_with_valids.txt"),
)?;
std::env::set_var("GITHUB_WORKSPACE", fs.base());
std::env::set_var("GITHUB_REPOSITORY", "kemitix/test");
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
//when
run()?;
//then
// TODO: add check that run fails because file_1.txt is invalid
// TODO: add check that network requests were made to get issues
Ok(())
}

View file

@ -1,47 +0,0 @@
use model::Config;
use patterns::{issue_pattern, marker_pattern};
//
use super::*;
#[test]
fn find_markers_in_dir() -> anyhow::Result<()> {
//given
let fs = kxio::fs::temp()?;
fs.file_write(
&fs.base().join("file_with_invalids.txt"),
include_str!("data/file_with_invalids.txt"),
)?;
fs.file_write(
&fs.base().join("file_with_valids.txt"),
include_str!("data/file_with_valids.txt"),
)?;
let config = Config::builder()
.fs(fs.clone())
.server("".to_string())
.repo("".to_string())
.prefix_pattern(marker_pattern()?)
.issue_pattern(issue_pattern()?)
.build();
//when
let markers = find_markers(config)?;
//then
assert_eq!(
markers.to_string().lines().collect::<Vec<_>>(),
vec![
"- Invalid: file_with_invalids.txt#2:",
" It contains a todo comment: // TODO: this is it",
"- Invalid: file_with_invalids.txt#4:",
" It also contains a fix-me comment: // FIXME: and this is it",
"- Valid : file_with_valids.txt#2:",
" It also has a todo comment: // TODO: (#23) and it has an issue number",
"- Valid : file_with_valids.txt#4:",
" Here is a fix-me comment: // FIXME: (#43) and is also has an issue number"
]
);
Ok(())
}