Skip to content

Commit

Permalink
feat(#36): no labels, no tests
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Aug 26, 2024
1 parent ce49a45 commit adc92ab
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 14 deletions.
3 changes: 0 additions & 3 deletions src/args/ignore_facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
use std::collections::HashMap;

/// Parse facts from list of strings (lines).
// @todo #27:30min Read ignore.ghiqc file as list of strings.
// We should read file first in the main.rs, and then pass list of strings in
// parse_facts function.
pub fn parse_facts(content: Vec<String>) -> HashMap<String, Vec<String>> {
let mut facts: HashMap<String, Vec<String>> = HashMap::new();
let mut author = vec![];
Expand Down
34 changes: 34 additions & 0 deletions src/args/ignore_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::args::ignore_facts::parse_facts;
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;

/// Ignore file.
/// `name` Ignore file name
#[derive(Clone)]
pub struct IgnoreFile {
name: String,
}

impl IgnoreFile {
/// New ignore file.
pub fn new(name: String) -> IgnoreFile {
IgnoreFile { name }
}

/// Is file exists?
pub fn exists(self) -> bool {
Path::new(&self.name).exists()
}

/// Facts.
pub fn facts(self) -> HashMap<String, Vec<String>> {
let file = File::open(self.name);
let reader = BufReader::new(file);
let facts: Vec<String> = reader.lines()
.filter_map(Result::ok)
.collect();
parse_facts(facts)
}
}
27 changes: 27 additions & 0 deletions src/args/ignore_issue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::args::ignore_facts::{ignores_dim, ignores_title};
use crate::args::ignore_file::IgnoreFile;
use crate::github::github_issue::GithubIssue;

/// Ignore issue?
/// * `issue`: Issue
/// * `file`: File with facts
pub fn ignore_issue(issue: GithubIssue, file: IgnoreFile) -> bool {
let facts = file.facts();
let mut result = false;
if ignores_title(issue.clone().title(), facts.clone()) {
result = true
} else if ignores_dim(
issue.author(),
String::from("author"),
facts.clone(),
) {
result = true
} else if ignores_dim(
issue.labels(),
String::from("label"),
facts,
) {
result = true
}
result
}
4 changes: 4 additions & 0 deletions src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ pub mod cli;
pub mod env;
/// Ignore issue based on facts.
pub mod ignore_facts;
/// Ignore issue.
pub mod ignore_issue;
/// Ignore file.
pub mod ignore_file;
10 changes: 10 additions & 0 deletions src/github/github_issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ impl GithubIssue {
}

impl GithubIssue {
/// Issue number.
pub fn number(self) -> u64 {
self.origin.number
}

/// Issue body.
pub fn body(self) -> String {
self.origin
Expand All @@ -48,4 +53,9 @@ impl GithubIssue {
pub fn author(self) -> String {
self.origin.user.login
}

/// Issue title.
pub fn title(self) -> String {
self.origin.title
}
}
38 changes: 27 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Application entry point.
#[allow(unused_imports)]
#[macro_use]
extern crate hamcrest;

use std::io::{BufRead, BufReader};
use crate::args::cli::Cli;
use crate::args::env::env;
use crate::github::github::github;
Expand All @@ -37,7 +39,13 @@ use crate::report::report::Report;
use crate::report::report_fork::ReportFork;
use crate::report::tagged_response::tagged;
use clap::Parser;
use hamcrest::is;
use hamcrest::matchers::existing_path::PathType::File;
use log::{debug, info};
use tokio::io::AsyncBufReadExt;
use crate::args::ignore_facts::{ignores_title, parse_facts};
use crate::args::ignore_file::IgnoreFile;
use crate::args::ignore_issue::ignore_issue;

/// Arguments.
pub mod args;
Expand Down Expand Up @@ -69,21 +77,29 @@ async fn main() {
Issue::new(args.repo.clone(), args.issue),
github.clone(),
)
.await;
.await;
info!(
"Issue says (created by @{}): {}",
issue.clone().author(),
issue.clone().body()
);
let author = issue.clone().author();
let response = ProbeDeepInfra::new(
String::from("https://api.deepinfra.com/v1/openai/chat/completions"),
deeptoken,
)
.complete(assistant(issue))
.await;
debug!("Received response: {}", response);
ReportFork::new(args.stdout, github, args.repo, args.issue)
.publish(tagged(response, author))
.await;
let ignore = IgnoreFile::new(String::from("ignore.ghiqc"));
if ignore.clone().exists() && ignore_issue(issue.clone(), ignore) {
info!(
"We are going to ignore issue #{}, since title {} matches with ignore facts in ignore.ghiqc",
issue.clone().number(), issue.title()
);
} else {
let response = ProbeDeepInfra::new(
String::from("https://api.deepinfra.com/v1/openai/chat/completions"),
deeptoken,
)
.complete(assistant(issue))
.await;
debug!("Received response: {}", response);
ReportFork::new(args.stdout, github, args.repo, args.issue)
.publish(tagged(response, author))
.await;
}
}

0 comments on commit adc92ab

Please sign in to comment.