Skip to content

Commit bad1046

Browse files
committed
Merge branch '__rultor'
2 parents 0ba68ed + 6f2c0b4 commit bad1046

16 files changed

+440
-20
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ tokio = { version = "1.39.1", features = ["rt", "rt-multi-thread", "macros"] }
5555
tokio-macros = "2.4.0"
5656
reqwest = { version = "0.12.5", features = ["json"] }
5757
serde_json = "1.0.120"
58+
testing_logger = "0.1.1"
5859

5960
[dev-dependencies]
6061
assert_cmd = "2.0.14"

src/github/github.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2024 Aliaksei Bialiauski
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included
13+
// in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
use octocrab::Octocrab;
23+
24+
/// Build GitHub client.
25+
pub fn github(token: String) -> Octocrab {
26+
Octocrab::builder()
27+
.personal_token(token)
28+
.build()
29+
.expect("Cannot create GitHub client")
30+
}

src/github/github_issue.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222
use crate::github::issue::Issue;
23+
use octocrab::Octocrab;
2324

2425
/// GitHub issue.
2526
#[derive(Clone)]
@@ -29,8 +30,8 @@ pub struct GithubIssue {
2930

3031
impl GithubIssue {
3132
/// GitHub issue from origin.
32-
pub async fn new(origin: Issue, token: String) -> GithubIssue {
33-
let issue = origin.on_github(token).await;
33+
pub async fn new(origin: Issue, github: Octocrab) -> GithubIssue {
34+
let issue = origin.on_github(github).await;
3435
GithubIssue { origin: issue }
3536
}
3637
}

src/github/issue.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@ impl Issue {
4040
/// Fetch issue details.
4141
pub async fn on_github(
4242
self,
43-
token: String,
43+
github: Octocrab,
4444
) -> octocrab::models::issues::Issue {
4545
let parts: Vec<&str> = self.repo.split('/').collect();
46-
let github = Octocrab::builder()
47-
.personal_token(token)
48-
.build()
49-
.expect("Cannot create GitHub client");
5046
let option = github
5147
.issues(parts[0], parts[1])
5248
.get(self.number as u64)

src/github/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22+
/// GitHub.
23+
#[allow(clippy::module_inception)]
24+
pub mod github;
2225
/// GitHub issue.
2326
pub mod github_issue;
2427
/// Issue.

src/main.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ Application entry point.
2727
extern crate hamcrest;
2828
use crate::args::cli::Cli;
2929
use crate::args::env::env;
30+
use crate::github::github::github;
3031
use crate::github::github_issue::GithubIssue;
3132
use crate::github::issue::Issue;
32-
use crate::probe::deep_infra_request::{ProbeDeepInfra, ProbeMessage};
33+
use crate::probe::assistant::assistant;
34+
use crate::probe::probe_deep_infra::ProbeDeepInfra;
3335
use crate::probe::probe_request::ProbeRequest;
36+
use crate::report::report::Report;
37+
use crate::report::report_fork::ReportFork;
38+
use crate::report::tagged_response::tagged;
3439
use clap::Parser;
3540
use log::{debug, info};
3641

@@ -40,6 +45,8 @@ pub mod args;
4045
pub mod github;
4146
/// Probes.
4247
pub mod probe;
48+
/// Reporting.
49+
pub mod report;
4350

4451
#[tokio::main]
4552
async fn main() {
@@ -57,24 +64,26 @@ async fn main() {
5764
let ghtoken = env(String::from("GITHUB_TOKEN"));
5865
debug!("Reading DEEPINFRA_TOKEN from environment...");
5966
let deeptoken = env(String::from("DEEPINFRA_TOKEN"));
60-
let issue =
61-
GithubIssue::new(Issue::new(args.repo, args.issue), ghtoken).await;
67+
let github = github(ghtoken);
68+
let issue = GithubIssue::new(
69+
Issue::new(args.repo.clone(), args.issue),
70+
github.clone(),
71+
)
72+
.await;
6273
info!(
6374
"Issue says (created by @{}): {}",
6475
issue.clone().author(),
6576
issue.clone().body()
6677
);
78+
let author = issue.clone().author();
6779
let response = ProbeDeepInfra::new(
6880
String::from("https://api.deepinfra.com/v1/openai/chat/completions"),
6981
deeptoken,
7082
)
71-
.complete(vec![ProbeMessage::new(
72-
String::from("user"),
73-
// @todo #7:30min Develop a prompt as probe message.
74-
// Let's create a prompt for a probe message that would
75-
// analyze quality of given bug report.
76-
String::from("Hello!"),
77-
)])
83+
.complete(assistant(issue))
7884
.await;
79-
info!("{}", response);
85+
debug!("Received response: {}", response);
86+
ReportFork::new(args.stdout, github, args.repo, args.issue)
87+
.publish(tagged(response, author))
88+
.await;
8089
}

src/probe/assistant.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2024 Aliaksei Bialiauski
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included
13+
// in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
use crate::github::github_issue::GithubIssue;
23+
use crate::probe::probe_deep_infra::ProbeMessage;
24+
25+
/// Assistant.
26+
pub fn assistant(issue: GithubIssue) -> Vec<ProbeMessage> {
27+
vec![
28+
ProbeMessage::new(
29+
String::from("system"),
30+
String::from(
31+
"You are developer tasked to review incoming bug reports that developers are submit on GitHub Issue platform"
32+
),
33+
), ProbeMessage::new(
34+
String::from("user"),
35+
format!(
36+
"Please review the following bug report and generate a simple summary.\
37+
Summary should contain 1 main quality problem related to this bug report formulation, and 1 specific suggestion on how to improve it.\
38+
Summary should be short, less than 30 words.\
39+
Don't generate any other info.\
40+
Bug report: {}",
41+
issue.body()
42+
),
43+
),
44+
]
45+
}

src/probe/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22+
/// Assistant with prompts.
23+
pub mod assistant;
2224
/// Deep Infra request.
23-
pub mod deep_infra_request;
25+
pub mod probe_deep_infra;
2426
/// Probe request.
2527
pub mod probe_request;
File renamed without changes.

src/probe/probe_request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22-
use crate::probe::deep_infra_request::ProbeMessage;
22+
use crate::probe::probe_deep_infra::ProbeMessage;
2323

2424
/// Probe request.
2525
pub trait ProbeRequest {

src/report/github_report.rs

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2024 Aliaksei Bialiauski
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included
13+
// in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
use crate::report::report::Report;
23+
use log::debug;
24+
use octocrab::Octocrab;
25+
use tracing::info;
26+
27+
/// GitHub report in issue comments.
28+
#[derive(Clone)]
29+
pub struct GithubReport {
30+
/// GitHub.
31+
github: Octocrab,
32+
/// Repo.
33+
repo: String,
34+
/// Issue number.
35+
issue: usize,
36+
}
37+
38+
impl GithubReport {
39+
/// New GitHub report.
40+
pub fn new(github: Octocrab, repo: String, issue: usize) -> GithubReport {
41+
GithubReport {
42+
github,
43+
repo,
44+
issue,
45+
}
46+
}
47+
}
48+
49+
impl Report for GithubReport {
50+
async fn publish(self, text: String) {
51+
debug!("Publishing to {}#{}...", self.repo, self.issue);
52+
let parts: Vec<&str> = self.repo.split('/').collect();
53+
self.github
54+
.issues(parts[0], parts[1])
55+
.create_comment(self.issue as u64, text)
56+
.await
57+
.expect("Cannot post report to the GitHub issue comments");
58+
info!(
59+
"Report should be delivered to {}#{}!",
60+
self.repo, self.issue
61+
);
62+
}
63+
}

src/report/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2024 Aliaksei Bialiauski
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included
13+
// in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
/// GitHub report.
23+
pub mod github_report;
24+
/// Report.
25+
#[allow(clippy::module_inception)]
26+
pub mod report;
27+
/// Report fork.
28+
pub mod report_fork;
29+
/// Stdout report.
30+
pub mod stdout_report;
31+
/// Tagged response.
32+
pub mod tagged_response;

src/report/report.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2024 Aliaksei Bialiauski
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included
13+
// in all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
/// The report.
23+
pub trait Report {
24+
/// Publish report.
25+
#[allow(async_fn_in_trait)]
26+
async fn publish(self, text: String);
27+
}

0 commit comments

Comments
 (0)