Skip to content

perf(github): skip comment edit when body is already up to date#2452

Merged
chmouel merged 1 commit intotektoncd:mainfrom
theakshaypant:perf-optimize-github-comment-update
Feb 5, 2026
Merged

perf(github): skip comment edit when body is already up to date#2452
chmouel merged 1 commit intotektoncd:mainfrom
theakshaypant:perf-optimize-github-comment-update

Conversation

@theakshaypant
Copy link
Copy Markdown
Member

📝 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_comment API 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.

image Github only shows the edited tag if the body is changed after editing. We save a single API call in cases where validation errors are to being reported in subsequent triggers without any change in the comment body.

👨🏻‍ Linked Jira

N/A

🔗 Linked GitHub Issue

N/A

🚀 Type of Change

  • 🐛 Bug fix (fix:)
  • ✨ New feature (feat:)
  • 💥 Breaking change (feat!:, fix!:)
  • 📚 Documentation update (docs:)
  • ⚙️ Chore (chore:)
  • 💅 Refactor (refactor:)
  • 🔧 Enhancement (enhance:)
  • 📦 Dependency update (deps:)

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

If you have used AI assistance, please provide the following details:

Which LLM was used?

  • GitHub Copilot
  • ChatGPT (OpenAI)
  • Claude (Anthropic)
  • Cursor
  • Gemini (Google)
  • Other: ____________

Extent of AI Assistance:

  • Documentation and research only
  • Unit tests or E2E tests only
  • Code generation (parts of the code)
  • Full code generation (most of the PR)
  • PR description and comments
  • Commit message(s)

Important

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer 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.sh to automatically add
these co-author trailers to your commits.

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @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

  • Performance Optimization: Added a check to prevent GitHub API edit_comment calls when the comment body has not changed, optimizing API usage and reducing unnecessary network requests.
  • Code Consistency: Standardized the use of github.Ptr() for setting the comment body in the EditComment API call, aligning with GitHub Go client best practices.
Changelog
  • pkg/provider/github/github.go
    • Modified the CreateComment function to include a check (comment.GetBody() != commit) before attempting to edit an existing GitHub issue comment. This ensures the edit_comment API is only called when the comment's content genuinely needs an update.
    • Updated the Body field in the github.IssueComment struct passed to EditComment from &commit to github.Ptr(commit) for consistency with GitHub Go client best practices.
Activity
  • The author identified an opportunity for performance improvement by observing unnecessary edit_comment API calls that did not result in visible changes on GitHub.
  • AI assistance (Cursor) was used for generating commit messages.
  • The author performed local checks including make test and make lint.
  • The author ensured commit messages adhere to project guidelines.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@pipelines-as-code
Copy link
Copy Markdown

pipelines-as-code bot commented Feb 5, 2026

🔍 PR Lint Feedback

Note: This automated check helps ensure your PR follows our contribution guidelines.

⚠️ Items that need attention:

🎫 Jira reference

Add a Jira reference in the description using one of the following formats:

  • https://issues.redhat.com/browse/SRVKP-<number>

If no SRVKP ticket exists yet, link a GitHub issue instead (e.g., Fixes #123).
Minor housekeeping PRs without Jira coverage can skip this after confirming with reviewers.


🤖 AI attribution

The following commits lack an explicit AI attribution footer:

  • 2612189 perf(github): skip comment edit when body is already up to date

If no AI assistance was used for a commit, you can ignore this warning.
Otherwise add an Assisted-by: or Co-authored-by: footer referencing the AI used.


ℹ️ Next Steps

  • Review and address the items above
  • Push new commits to update this PR
  • This comment will be automatically updated when issues are resolved
🔧 Admin Tools (click to expand)

Automated Issue/Ticket Creation:

  • /issue-create - Generate a GitHub issue from this PR content using AI
  • /jira-create - Create a SRVKP Jira ticket from this PR content using AI

⚠️ Important: Always review and edit generated content before finalizing tickets/issues.
The AI-generated content should be used as a starting point and may need adjustments.

These commands are available to maintainers and will post the generated content as PR comments for review.

🤖 This feedback was generated automatically by the PR CI system

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@theakshaypant theakshaypant force-pushed the perf-optimize-github-comment-update branch from 93121ad to 855e591 Compare February 5, 2026 12:37
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>
@theakshaypant theakshaypant force-pushed the perf-optimize-github-comment-update branch from 855e591 to 2612189 Compare February 5, 2026 12:38
@theakshaypant
Copy link
Copy Markdown
Member Author

/gemini review

@theakshaypant
Copy link
Copy Markdown
Member Author

/review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +780 to +782
if comment.GetBody() == commit {
return nil
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
if comment.GetBody() == commit {
return nil
}
if strings.ReplaceAll(comment.GetBody(), "\r\n", "\n") == strings.ReplaceAll(commit, "\r\n", "\n") {
return nil
}

@chmouel
Copy link
Copy Markdown
Member

chmouel commented Feb 5, 2026

at this point i am willing to tryu anything 🙃

@chmouel chmouel merged commit 12db9d1 into tektoncd:main Feb 5, 2026
40 of 43 checks passed
@theakshaypant theakshaypant deleted the perf-optimize-github-comment-update branch February 6, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants