perf(github): skip comment edit when body is already up to date#2452
Conversation
Summary of ChangesHello @theakshaypant, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a performance optimization by preventing redundant GitHub API calls. Specifically, it modifies the comment editing logic to first verify if the new comment body differs from the existing one. If the content is identical, the API call to edit the comment is skipped, thereby reducing unnecessary network traffic and improving efficiency. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🔍 PR Lint Feedback
|
There was a problem hiding this comment.
Code Review
This pull request aims to optimize comment creation by avoiding unnecessary API calls when comment content is already up-to-date. However, a critical logic flaw in pkg/provider/github/github.go could lead to the creation of duplicate comments, potentially causing API rate limit exhaustion and comment spam. A fix is recommended to ensure the function returns early once a matching comment is identified. The change to use github.Ptr() for consistency is a good improvement.
93121ad to
855e591
Compare
Avoid unnecessary GitHub API calls by checking if comment body already matches before editing. Use github.Ptr() for consistency. Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com>
855e591 to
2612189
Compare
|
/gemini review |
|
/review |
There was a problem hiding this comment.
Code Review
This pull request introduces a performance optimization by skipping the API call to edit a GitHub comment if the content is already up-to-date. This is a sensible improvement to reduce unnecessary API traffic. The change also consistently uses github.Ptr() for setting the comment body, which is good practice. I've added one suggestion to make the content comparison more robust by normalizing line endings.
| if comment.GetBody() == commit { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
This is a great optimization to avoid unnecessary API calls. However, the direct string comparison might be brittle if there are differences in line endings (e.g., \n vs \r\n). GitHub's API may normalize line endings, so a comment body retrieved via GetBody() might have different line endings than the commit string you are comparing against, even if the content is semantically identical. This would lead to an unnecessary edit_comment call. To make this check more robust, consider normalizing line endings before comparison.
| if comment.GetBody() == commit { | |
| return nil | |
| } | |
| if strings.ReplaceAll(comment.GetBody(), "\r\n", "\n") == strings.ReplaceAll(commit, "\r\n", "\n") { | |
| return nil | |
| } |
|
at this point i am willing to tryu anything 🙃 |
📝 Description of the Change
Avoid unnecessary GitHub API calls by checking if comment body already matches before editing. Use github.Ptr() for consistency.
Saw
edit_commentAPI call being made which returns 200 status{ "level": "debug", "ts": "2026-02-04T09:14:15.527Z", "logger": "pipelinesascode", "caller": "github/profiler.go:131", "msg": "GitHub API call completed", "commit": "43bf4b1", "provider": "github", "event-id": "ddbe19c0-01a9-11f1-961c-7f1fee891363", "event-sha": "0afb7232f1c85b17c7a7aac7c416d6ad3fb775be", "event-type": "pull_request", "source-repo-url": "https://github.com/openshift-pipelines/pipelines-as-code-e2e-tests", "target-branch": "main", "source-branch": "pac-e2e-test-fg4nl", "namespace": "pac-e2e-ns-nnzz2", "operation": "edit_comment", "duration_ms": 430, "provider": "github", "repo": "pac-e2e-ns-nnzz2/pac-e2e-ns-nnzz2", "url_path": "/repos/openshift-pipelines/pipelines-as-code-e2e-tests/issues/comments/3846247136", "rate_limit_remaining": "5746", "status_code": 200 }However, the said comment does not show the "edited" tag.
👨🏻 Linked Jira
N/A
🔗 Linked GitHub Issue
N/A
🚀 Type of Change
fix:)feat:)feat!:,fix!:)docs:)chore:)refactor:)enhance:)deps:)🧪 Testing Strategy
🤖 AI Assistance
If you have used AI assistance, please provide the following details:
Which LLM was used?
Extent of AI Assistance:
Important
If the majority of the code in this PR was generated by an AI, please add a
Co-authored-bytrailer to your commit message.For example:
Co-authored-by: Gemini gemini@google.com
Co-authored-by: ChatGPT noreply@chatgpt.com
Co-authored-by: Claude noreply@anthropic.com
Co-authored-by: Cursor noreply@cursor.com
Co-authored-by: Copilot Copilot@users.noreply.github.com
**💡You can use the script
./hack/add-llm-coauthor.shto automatically addthese co-author trailers to your commits.
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit installtoautomate these checks.