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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
max_threshold: "100"
pr_number: ${{ github.event.pull_request.number }}
env:
github_token: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ runs:
image: "Dockerfile"
args:
- ${{ inputs.enable_fib }}
- ${{ inputs.max_threshold }}
- ${{ inputs.max_threshold }}
- ${{ inputs.pr_number }}
12 changes: 7 additions & 5 deletions src/comment.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use reqwest::Client;
use std::env;
use std::env::{self};

pub async fn post_comment(pr_content: &str) -> Result<(), reqwest::Error> {

let args: Vec<String> = env::args().collect();

let repo = env::var("GITHUB_REPOSITORY").expect("GITHUB_REPOSITORY not set");
let pr_number = env::var("PR_NUMBER")
.expect("PR_NUMBER not set")
.parse::<i128>()
.expect("Invalid PR_NUMBER");

let pr_number = args.get(3).unwrap_or(&"1".to_string()).parse::<u64>().unwrap_or(1);

let github_token = env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN not set");

println!("{}", github_token);
let url = format!(
"https://api.github.com/repos/{}/issues/{}/comments",
repo, pr_number
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ async fn main() {
// .parse::<u64>()
// .expect("Invalid PR_NUMBER");

let pr_number = &args[3];
let pr_number: u64 = pr_number.parse().expect("failed to parse PR_NUMBER");
let pr_number = args.get(3).unwrap_or(&"1".to_string()).parse::<u64>().unwrap_or(1);

println!("FibBot application is running...");
println!("Fibonacci Calculation Enabled: {}", enable_fib);
Expand All @@ -37,7 +36,7 @@ async fn main() {


let github_repository =
env::var("GITHUB_REPOSITORY").unwrap_or_else(|_| "t-Guy-Ghis/fibBot".to_string());
env::var("GITHUB_REPOSITORY").unwrap_or_else(|_| "Guy-Ghis/fibBot".to_string());
let github_repository_vec = github_repository.split("/").collect::<Vec<&str>>();
let owner = github_repository_vec[0];
let repo = github_repository_vec[1];
Expand Down Expand Up @@ -66,6 +65,10 @@ println!("Extracted numbers: {:?}", pull_request_numbers);
if pr_files.items.is_empty() {
println!("No numbers found in this pull_request.");
}

let pr_content = pr_files.items.first().unwrap().patch.clone().unwrap();
let _ = post_comment(&pr_content).await;

let mut response =
String::from("#### Fibonacci output of each number in the pull_request is:\n");
for file in &pr_files {
Expand Down