Skip to content

feat(github): enrich comment event body for CEL evaluation#2355

Closed
theakshaypant wants to merge 1 commit intotektoncd:mainfrom
theakshaypant:SRVKP-8617-fix-enrich-comment-event-body-for-cel
Closed

feat(github): enrich comment event body for CEL evaluation#2355
theakshaypant wants to merge 1 commit intotektoncd:mainfrom
theakshaypant:SRVKP-8617-fix-enrich-comment-event-body-for-cel

Conversation

@theakshaypant
Copy link
Copy Markdown
Member

@theakshaypant theakshaypant commented Dec 15, 2025

📝 Description of the Change

When processing comment events on GitHub, we now enrich the event body with the complete pull request data. This allows CEL expressions to access all pull request details when evaluating conditions on comment webhooks (/test, /retest, /ok-to-test).

👨🏻‍ Linked Jira

https://issues.redhat.com/browse/SRVKP-8617

🔗 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 significant enhancement for GitHub App users by enriching the event payload for issue comment webhooks. Previously, CEL expressions evaluating conditions on commands like /test or /retest only had access to the comment's body. With this change, the full pull request object is now automatically injected into the event body, allowing for more comprehensive and flexible CEL evaluations based on detailed pull request attributes such as its draft status or author. This provides greater control and automation capabilities for workflows triggered by comments.

Highlights

  • Enhanced GitHub Comment Events: GitHub App comment events (e.g., /test, /retest, /ok-to-test) are now enriched with the complete pull request data in their event body.
  • Improved CEL Evaluation: Common Expression Language (CEL) expressions can now access full pull request details (e.g., body.pull_request.draft, body.pull_request.user.login) when evaluating conditions on these enriched comment webhooks.
  • New Enrichment Logic: A new enrichIssueCommentEventBody function has been implemented in the GitHub provider to fetch the pull request object and merge it into the issue comment event payload.
  • Documentation Update: The documentation has been updated to clarify this new functionality for GitHub App users and to note that this enrichment is not available for other Git providers.
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 Dec 15, 2025

🔍 PR Lint Feedback

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

⚠️ Items that need attention:

🤖 AI attribution

The following commits lack an explicit AI attribution footer:

  • ac3faaa feat(github): enrich comment event body for CEL evaluation

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

@pipelines-as-code pipelines-as-code bot added documentation Improvements or additions to documentation feature New feature or request github labels Dec 15, 2025
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 valuable feature by enriching comment event bodies with pull request data for CEL evaluations on GitHub. The implementation is solid, and the accompanying documentation update is clear.

I've provided a couple of suggestions to improve the efficiency and clarity of the enrichment logic by avoiding a JSON marshal/unmarshal cycle. This involves using an anonymous struct for enrichment and updating the corresponding test to reflect this change. These are medium-severity suggestions aimed at improving performance and maintainability.

Comment on lines +1331 to +1342
eventMap, ok := tt.event.Event.(map[string]any)
assert.Assert(t, ok, "event should be a map after enrichment")

prData, ok := eventMap["pull_request"]
assert.Assert(t, ok, "event should contain pull_request field")
assert.Assert(t, prData != nil, "pull_request data should not be nil")

// Verify some PR fields are present
prMap, ok := prData.(map[string]any)
if ok {
assert.Assert(t, prMap["number"] != nil, "PR should have number field")
}
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 change is necessary to align with the suggested refactoring in pkg/provider/github/parse_payload.go. With the suggested change to use an anonymous struct for enrichment, the type of tt.event.Event will no longer be map[string]any. The test needs to be updated to handle the enriched struct. You can marshal the event to JSON and then unmarshal it into a map to inspect its contents.

				// Marshal the enriched event to check its contents as it's now a struct
				enrichedBytes, err := json.Marshal(tt.event.Event)
				assert.NilError(t, err)

				var eventMap map[string]any
				err = json.Unmarshal(enrichedBytes, &eventMap)
				assert.NilError(t, err)

				prData, ok := eventMap["pull_request"]
				assert.Assert(t, ok, "event should contain pull_request field")
				assert.Assert(t, prData != nil, "pull_request data should not be nil")

				// Verify some PR fields are present
				prMap, ok := prData.(map[string]any)
				if ok {
					assert.Assert(t, prMap["number"] != nil, "PR should have number field")
				}

@zakisk
Copy link
Copy Markdown
Member

zakisk commented Dec 15, 2025

@theakshaypant this is kind of changing schema of the event payload so if someone is looking at GitHub event schema they will find it different and will conflict and we specify in our docs that event variable holds the git event payload. I've added do-not-merge label and waiting for others to comment.

@theakshaypant theakshaypant force-pushed the SRVKP-8617-fix-enrich-comment-event-body-for-cel branch from 690a448 to 59c8943 Compare December 15, 2025 05:00
@theakshaypant
Copy link
Copy Markdown
Member Author

@theakshaypant this is kind of changing schema of the event payload so if someone is looking at GitHub event schema they will find it different and will conflict and we specify in our docs that event variable holds the git event payload. I've added do-not-merge label and waiting for others to comment.

Thanks for the info. Have it in a draft state as this is not ready yet.
Will see if I can accommodate your comment before moving it to ready.

@theakshaypant
Copy link
Copy Markdown
Member Author

this is kind of changing schema of the event payload so if someone is looking at GitHub event schema they will find it different and will conflict and we specify in our docs that event variable holds the git event payload.

@chmouel WDYT? I have restricted this change to github only (and not gitlab) as github issue_comment body.pull_request only contains URLs which might not be very helpful to the user. (?)

    "pull_request": {
      "url": "https://api.github.com/repos/theakshaypant/akshay-pac-test-repo/pulls/62",
      "html_url": "https://github.com/theakshaypant/akshay-pac-test-repo/pull/62",
      "diff_url": "https://github.com/theakshaypant/akshay-pac-test-repo/pull/62.diff",
      "patch_url": "https://github.com/theakshaypant/akshay-pac-test-repo/pull/62.patch",
      "merged_at": null
    },

Did find some use cases where the issue_comment body is used for fetching the PR number but there is already a body.issue.number field available for the same and body.issue.url and body.issue.html_url for URLs if anyone is using those in their plrs.

IMO overwriting the body.pull_request for issue_comment with PR details has far more usage compared to not allowing altering the event payload.

Keeping this conversation restricted to github for now given the paylaod structure is completely different for gitlab and the same overwriting would not work there.

@theakshaypant theakshaypant marked this pull request as ready for review December 23, 2025 07:36

{{< hint info >}}
When matching the body payload in a Pull Request, the GitOps comments such as
**GitHub App only**: When using GitOps comments such as `/test` or `/retest` on a Pull Request,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there is too much hints :D

Copy link
Copy Markdown
Member Author

@theakshaypant theakshaypant Dec 23, 2025

Choose a reason for hiding this comment

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

Docs are hard 🥲
Will clean them up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Merged both the hints into a single one as it was earlier

When processing comment events on GitHub, we now enrich the event body
with the complete pull request data. This allows CEL expressions
to access all pull request details when evaluating conditions on
comment webhooks (/test, /retest, /ok-to-test).

Jira: https://issues.redhat.com/browse/SRVKP-8617

Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com>
@theakshaypant theakshaypant force-pushed the SRVKP-8617-fix-enrich-comment-event-body-for-cel branch from 59c8943 to ac3faaa Compare December 24, 2025 07:28
@theakshaypant
Copy link
Copy Markdown
Member Author

Closing PR for now since there are some reservations about this implementation for the issue. Will reopen if necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge documentation Improvements or additions to documentation feature New feature or request github

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants