From 15387af2725318cd98b00b1f01cf59eafaf7ccd5 Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Tue, 13 May 2025 16:12:46 -0700 Subject: [PATCH 1/4] Updated message that displays in terminal when codeflash creates a PR --- codeflash/result/create_pr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/codeflash/result/create_pr.py b/codeflash/result/create_pr.py index da0c61961..dd1a40051 100644 --- a/codeflash/result/create_pr.py +++ b/codeflash/result/create_pr.py @@ -132,7 +132,9 @@ def check_create_pr( coverage_message=coverage_message, ) if response.ok: - logger.info(f"Successfully created a new PR #{response.text} with the optimized code.") + pr_number = response.text + pr_url = f"https://github.com/{owner}/{repo}/pull/{pr_number}" + logger.info(f"Successfully created a new PR #{pr_number} with the optimized code: {pr_url}") else: logger.error( f"Optimization was successful, but I failed to create a PR with the optimized code." From 217adfac857eca6b9e685b8aae1a725d38867b46 Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Tue, 13 May 2025 16:30:27 -0700 Subject: [PATCH 2/4] Factored out creation of the GitHub PR URL into a function in github_utils --- codeflash/code_utils/github_utils.py | 3 +++ codeflash/result/create_pr.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/codeflash/code_utils/github_utils.py b/codeflash/code_utils/github_utils.py index fcabd9823..2b053a326 100644 --- a/codeflash/code_utils/github_utils.py +++ b/codeflash/code_utils/github_utils.py @@ -26,3 +26,6 @@ def require_github_app_or_exit(owner: str, repo: str) -> None: f"Note: if you want to find optimizations without opening PRs, you can run Codeflash with the --no-pr flag.{LF}" ) apologize_and_exit() + +def github_pr_url(owner: str, repo: str, pr_number: str) -> str: + return f"https://github.com/{owner}/{repo}/pull/{pr_number}" diff --git a/codeflash/result/create_pr.py b/codeflash/result/create_pr.py index dd1a40051..882c39d2e 100644 --- a/codeflash/result/create_pr.py +++ b/codeflash/result/create_pr.py @@ -15,6 +15,7 @@ get_repo_owner_and_name, git_root_dir, ) +from codeflash.code_utils.github_utils import github_pr_url from codeflash.github.PrComment import FileDiffContent, PrComment if TYPE_CHECKING: @@ -133,7 +134,7 @@ def check_create_pr( ) if response.ok: pr_number = response.text - pr_url = f"https://github.com/{owner}/{repo}/pull/{pr_number}" + pr_url = github_pr_url(owner, repo, pr_number) logger.info(f"Successfully created a new PR #{pr_number} with the optimized code: {pr_url}") else: logger.error( From 792a4d589da53b2bd39c0ae6e126593eabc8a5a5 Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Tue, 13 May 2025 16:38:32 -0700 Subject: [PATCH 3/4] Stopped shadowing pr_number variable from outer scope --- codeflash/result/create_pr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codeflash/result/create_pr.py b/codeflash/result/create_pr.py index 882c39d2e..ce43541dc 100644 --- a/codeflash/result/create_pr.py +++ b/codeflash/result/create_pr.py @@ -133,8 +133,8 @@ def check_create_pr( coverage_message=coverage_message, ) if response.ok: - pr_number = response.text - pr_url = github_pr_url(owner, repo, pr_number) + pr_id = response.text + pr_url = github_pr_url(owner, repo, pr_id) logger.info(f"Successfully created a new PR #{pr_number} with the optimized code: {pr_url}") else: logger.error( From 84686b2e10b46bc64bff7acfd3ede2ca7fdc08a8 Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Tue, 13 May 2025 16:39:41 -0700 Subject: [PATCH 4/4] Forgot to change an instance of pr_number for pr_id --- codeflash/result/create_pr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/result/create_pr.py b/codeflash/result/create_pr.py index ce43541dc..502c811eb 100644 --- a/codeflash/result/create_pr.py +++ b/codeflash/result/create_pr.py @@ -135,7 +135,7 @@ def check_create_pr( if response.ok: pr_id = response.text pr_url = github_pr_url(owner, repo, pr_id) - logger.info(f"Successfully created a new PR #{pr_number} with the optimized code: {pr_url}") + logger.info(f"Successfully created a new PR #{pr_id} with the optimized code: {pr_url}") else: logger.error( f"Optimization was successful, but I failed to create a PR with the optimized code."