From 915ad69db82a12ee9ec7682e54722012cc3b64be Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 15:02:09 +0100 Subject: [PATCH 01/10] update main.rs to get pr_number --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index ea8735a..a3cee5c 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); From 1fbb0bd0284a731c1210d21bbee00c52cc71cba7 Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 15:10:16 +0100 Subject: [PATCH 02/10] update main.rs to get pr_number --- src/comment.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index 80f5b46..6c552d8 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -1,12 +1,12 @@ 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"); From e4a1aac157733f218aad2739aa856d8840fdc4bc Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 15:22:20 +0100 Subject: [PATCH 03/10] update main.rs to get github_token --- .github/workflows/ci.yml | 1 - src/comment.rs | 2 +- src/main.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8920edf..b26fec0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,5 +29,4 @@ jobs: enable_fib: "true" max_threshold: "100" pr_number: ${{ github.event.pull_request.number }} - env: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/comment.rs b/src/comment.rs index 6c552d8..d977fee 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -8,7 +8,7 @@ pub async fn post_comment(pr_content: &str) -> Result<(), reqwest::Error> { let repo = env::var("GITHUB_REPOSITORY").expect("GITHUB_REPOSITORY not set"); 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"); + let github_token = args.get(4).expect("GITHUB_TOKEN not set"); let url = format!( "https://api.github.com/repos/{}/issues/{}/comments", diff --git a/src/main.rs b/src/main.rs index a3cee5c..e60b729 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,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]; From e460ca50e1765a3164a19aa587220e290a8ddeb4 Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 15:37:25 +0100 Subject: [PATCH 04/10] update main.rs and ci.yml to get github_token --- .github/workflows/ci.yml | 1 + src/comment.rs | 5 +++-- src/main.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b26fec0..8920edf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,4 +29,5 @@ jobs: enable_fib: "true" max_threshold: "100" pr_number: ${{ github.event.pull_request.number }} + env: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/comment.rs b/src/comment.rs index d977fee..0564a84 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -6,9 +6,10 @@ 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 = args.get(3).unwrap_or(&"1".to_string()).parse::().unwrap_or(1); - let github_token = args.get(4).expect("GITHUB_TOKEN not set"); + let pr_number = args.get(3).unwrap().parse::().unwrap_or(1); + + let github_token = env::var("INPUT_GITHUB_TOKEN").expect("GITHUB_TOKEN not set"); let url = format!( "https://api.github.com/repos/{}/issues/{}/comments", diff --git a/src/main.rs b/src/main.rs index e60b729..afc10e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ async fn main() { // .parse::() // .expect("Invalid PR_NUMBER"); - let pr_number = args.get(3).unwrap_or(&"1".to_string()).parse::().unwrap_or(1); + let pr_number = args.get(3).unwrap().parse::().unwrap_or(1); println!("FibBot application is running..."); println!("Fibonacci Calculation Enabled: {}", enable_fib); From 6e9c428491bccfa5107ec5f9beb758632f000348 Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 15:43:03 +0100 Subject: [PATCH 05/10] update main.rs --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index afc10e0..e60b729 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ async fn main() { // .parse::() // .expect("Invalid PR_NUMBER"); - let pr_number = args.get(3).unwrap().parse::().unwrap_or(1); + 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); From a11f7ea6c1b7b9caa85b8aeb6490b7e9204da29c Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 15:48:59 +0100 Subject: [PATCH 06/10] update main.rs --- src/comment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/comment.rs b/src/comment.rs index 0564a84..59c25c7 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -7,7 +7,7 @@ pub async fn post_comment(pr_content: &str) -> Result<(), reqwest::Error> { let repo = env::var("GITHUB_REPOSITORY").expect("GITHUB_REPOSITORY not set"); - let pr_number = args.get(3).unwrap().parse::().unwrap_or(1); + let pr_number = args.get(3).unwrap_or(&"1".to_string()).parse::().unwrap_or(1); let github_token = env::var("INPUT_GITHUB_TOKEN").expect("GITHUB_TOKEN not set"); From 2a63776fc3b7379ec24f736f44687aebb6ef957f Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 16:07:16 +0100 Subject: [PATCH 07/10] update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }} From 598a158a8544241b884288834371465c4bf67801 Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 16:12:05 +0100 Subject: [PATCH 08/10] update ci.yml --- src/comment.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/comment.rs b/src/comment.rs index 59c25c7..ade78f5 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -11,6 +11,7 @@ pub async fn post_comment(pr_content: &str) -> Result<(), reqwest::Error> { let github_token = env::var("INPUT_GITHUB_TOKEN").expect("GITHUB_TOKEN not set"); + println!("{}", github_token); let url = format!( "https://api.github.com/repos/{}/issues/{}/comments", repo, pr_number From 7f1b339b636be59e67b0052df76498a1f081f5a3 Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 16:47:46 +0100 Subject: [PATCH 09/10] added line to post --- src/comment.rs | 2 +- src/main.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/comment.rs b/src/comment.rs index ade78f5..8cd0677 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -9,7 +9,7 @@ pub async fn post_comment(pr_content: &str) -> Result<(), reqwest::Error> { let pr_number = args.get(3).unwrap_or(&"1".to_string()).parse::().unwrap_or(1); - let github_token = env::var("INPUT_GITHUB_TOKEN").expect("GITHUB_TOKEN not set"); + let github_token = env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN not set"); println!("{}", github_token); let url = format!( diff --git a/src/main.rs b/src/main.rs index e60b729..5b3ea51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,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 { From ff5c97d99306759062d2a5b563bf29d79fda2eeb Mon Sep 17 00:00:00 2001 From: Guy-Ghis Date: Sat, 1 Mar 2025 17:17:38 +0100 Subject: [PATCH 10/10] update action.yml --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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