diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8920edf..dd923ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/action.yml b/action.yml index 4ae2d96..fb2f2f7 100644 --- a/action.yml +++ b/action.yml @@ -23,4 +23,5 @@ runs: image: "Dockerfile" args: - ${{ inputs.enable_fib }} - - ${{ inputs.max_threshold }} \ No newline at end of file + - ${{ inputs.max_threshold }} + - ${{ inputs.pr_number }} \ No newline at end of file diff --git a/src/comment.rs b/src/comment.rs index 80f5b46..8cd0677 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -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 = 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::() - .expect("Invalid PR_NUMBER"); + + let pr_number = args.get(3).unwrap_or(&"1".to_string()).parse::().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 diff --git a/src/main.rs b/src/main.rs index ea8735a..5b3ea51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,7 @@ async fn main() { // .parse::() // .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::().unwrap_or(1); println!("FibBot application is running..."); println!("Fibonacci Calculation Enabled: {}", enable_fib); @@ -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::>(); let owner = github_repository_vec[0]; let repo = github_repository_vec[1]; @@ -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 {