Skip to content

Conversation

theakshaypant
Copy link
Contributor

@theakshaypant theakshaypant commented Oct 17, 2025

📝 Description of the Change

Add gloab pattern matching support for incoming webhook targets.
Implements first-match-wins strategy when multiple targets match.

  • Add matchTarget() helper with glo pattern matching
  • Implement IncomingWebhookRule() with first-match semantics
  • Add comprehensive unit an e2e tests
  • Update documentation with gloab examples and best practices
  • Update sample with gloa pattern target matching for Repository

👨🏻‍ Linked Jira

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

🔗 Linked GitHub Issue

Addresses a comment in #1398

🚀 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 [email protected]
Co-authored-by: ChatGPT [email protected]
Co-authored-by: Claude [email protected]
Co-authored-by: Cursor [email protected]
Co-authored-by: Copilot [email protected]

**💡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

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 significantly enhances the flexibility of incoming webhook configurations by introducing support for regular expressions in target matching. It ensures that users can define more sophisticated rules for triggering pipelines based on branch names, while also incorporating robust security validations to prevent common misconfigurations that could lead to unintended access or behavior. The 'first-match-wins' logic provides clear precedence for rule resolution.

Highlights

  • Regex Support for Webhook Targets: Incoming webhook targets now support regular expressions, allowing for more flexible and dynamic matching of branch names (e.g., ^feature/.*).
  • Automatic Regex Detection: The system automatically detects if a target string is a regex pattern by checking for common metacharacters, simplifying configuration.
  • First-Match-Wins Strategy: When multiple incoming webhook rules match a branch, the first rule defined in the YAML configuration will be applied, emphasizing the importance of rule order.
  • Security Validation and Warnings: New security checks validate target patterns and log warnings for potentially dangerous configurations, such as overly broad catch-all patterns or unanchored regexes that could inadvertently expose sensitive secrets.
  • Comprehensive Documentation: The documentation has been updated with detailed examples, best practices, and security guidance for using regex patterns in incoming webhook targets.
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 pipelines-as-code bot added documentation Improvements or additions to documentation feature New feature or request incoming-webhook labels Oct 17, 2025
Copy link

@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 adding regex support for incoming webhook targets, along with important security validations. The implementation is solid, and the documentation and tests are comprehensive.

My review focuses on a few areas for improvement:

  • Correctness and Duplication: There's a small bug in the regex detection logic, and this logic is duplicated in two places. Consolidating it into a single, corrected helper function would improve maintainability.
  • Performance: Regex patterns are compiled on every request, which could be optimized by caching the compiled expressions.
  • Usability: The security warnings for unanchored patterns, while well-intentioned, might be too aggressive for common use cases, potentially leading to excessive noise.

Overall, this is a great addition. Addressing these points will make the feature even more robust and efficient.

Copy link
Contributor Author

@theakshaypant theakshaypant left a comment

Choose a reason for hiding this comment

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

There is another discussion that can be potentially be had regarding the usage of glob patterns instead of regex here.

My thoughts on this are

  • Regex provides stricter, auditable control over branch naming conventions.
    For example, enforce rules like ^PROJECT-\d+/feature/[a-z0-9._-]+$ or ^release-(\d+\.\d+)$
  • Fine grained control - anchors, groups, etc
  • Glob doesn’t offer the same level of flexibility and is harder to define for advanced use cases
  • While using glob patterns may be easier for casual users, regex provides more control to the users defining the pipeline.

Copy link
Contributor Author

@theakshaypant theakshaypant Oct 17, 2025

Choose a reason for hiding this comment

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

We can potentially also link some regex best practices or link a tool which can help the users with their patterns.
Did not want to endorse any random blog so skipped it for now.

Copy link
Contributor Author

@theakshaypant theakshaypant Oct 17, 2025

Choose a reason for hiding this comment

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

Go's regex uses the RE2 engine, which intentionally excludes features that can cause catastrophic backtracking protecting from ReDoS but have still added them some tests for them as I wanted to confirm the process wouldn't be slowed down in case someone does add an evil regex (maliciously or mistakenly)!

@theakshaypant theakshaypant force-pushed the SRVKP-7364-feat-support-regexp-incoming-webhook-targets branch 2 times, most recently from d24f0f8 to e423be4 Compare October 17, 2025 08:37
@chmouel
Copy link
Member

chmouel commented Oct 17, 2025

I think we need multiple scenarios for E2E Tests for that, there is already a e2e capability in the tests for incoming tests that could be extended i believe.

@theakshaypant theakshaypant force-pushed the SRVKP-7364-feat-support-regexp-incoming-webhook-targets branch from e423be4 to 4b8d8ae Compare October 22, 2025 05:13
@theakshaypant theakshaypant marked this pull request as draft October 22, 2025 05:24
@theakshaypant theakshaypant force-pushed the SRVKP-7364-feat-support-regexp-incoming-webhook-targets branch 3 times, most recently from 6c65541 to b63f0ea Compare October 22, 2025 07:48
@theakshaypant theakshaypant marked this pull request as ready for review October 22, 2025 09:46
}

// Auto-detect regex patterns by checking for metacharacters.
if strings.ContainsAny(target, "^$*+|[](){}") ||
Copy link
Member

@chmouel chmouel Oct 22, 2025

Choose a reason for hiding this comment

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

I don't really like doing strings.Contains to try to detect regexp, this feels fragile, but i can live with it if we are sure there is no bug,

are we sure that git branch cannot contains those chars (for ex if i a user called their branch foo-.+-bar) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point, did not consider users having "unconventional" branch names.
Was trying to add break early mechanism in case of a non-regex target.
IMO wouldn't make a difference removing this condition completely, any invalid regex would be rejected by the Compile.

Will get rid of the condition and add test case(s) for such creative branch names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chmouel Spent some time thinking about this and trying out a few things.
We cannot expect users to give conventional branch names and targets. Due to this, one fundamental regex problem will prevail - dots. For example, target v1.2.0 would match with v1.230 and so on.

Some alternate options I considered
1. Adding a new regexTarget in the CR (dont want to do this would cause confusion on which target should be used in case of multiple matches in 2 different fields)
2. Have a regex:/re: prefix for targets specifying a regex but here again we would be asking users to put restrictions on branch naming.
3. Use glob patterns instead, I know there is a comment on why we should use regex over glob but having seen more examples and our ther options, I feel this is the way forward

Copy link
Member

@chmouel chmouel Oct 23, 2025

Choose a reason for hiding this comment

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

yeah i think globbing is good enough for me and we don't need to do crazy things like regexp detection.. it's rare that people needs more than that...

the other options are good option too, I was thinking about that same alternative options as well 👏🏻 this may be something for later if some customers/users somehow really really want regexp instead

Add glob pattern matching support for incoming webhook targets
using shell-style wildcards for intuitive branch filtering.

- Add matchTarget() helper to match glob patterns
- Implement IncomingWebhookRule() with first-match-wins semantics
- Support glob wildcards: * (any chars), ? (single char),
  [0-9] (ranges), {a,b} (alternation)
- Add comprehensive unit and e2e tests
- Update documentation with glob syntax, examples, and best
  practices
- Update sample repository with glob pattern examples

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

Signed-off-by: Akshay Pant <[email protected]>
Assisted-by: Claude-Sonnet-4.5 (via Cursor)
@theakshaypant theakshaypant force-pushed the SRVKP-7364-feat-support-regexp-incoming-webhook-targets branch from b63f0ea to 9958898 Compare October 23, 2025 04:23
@theakshaypant theakshaypant changed the title feat: support regex in incoming webhook targets feat: support gloab in incoming webhook targets Oct 23, 2025
@theakshaypant theakshaypant changed the title feat: support gloab in incoming webhook targets feat: support glob in incoming webhook targets Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feature New feature or request incoming-webhook

Development

Successfully merging this pull request may close these issues.

2 participants