palantir / policy-bot

A GitHub App that enforces approval policies on pull requests
Apache License 2.0
780 stars 108 forks source link

targets_branch "pattern" action lacks NOT (a OR b) ability. #299

Open derac opened 3 years ago

derac commented 3 years ago

Hi,

In the _targetsbranch section, the user can select a branch with regex using the pattern action. This uses the Go regex system which is linear, and so doesn't support negative lookaheads. This makes it impossible to say NOT (a OR b OR c).

It would be useful if this section had functionality similar to the title section, which has matches and not_matches functions.

Thanks, Derek

james-soak commented 2 years ago

This would also be very useful to us, we have a defined branching policy but once a rule fails to match it skips it entirely. It would be nice to be able to require elevated approvals for deviations from our standard processes.

For example this was an attempted rule restricting the source and target of a PR:

  - name: Task into parent branch
    if:
      targets_branch:
        pattern: "^(feature|amend|update|fix|refactor)/[a-z0-9._-]+$"
      from_branch:
        pattern: "^task/[a-z]{2}/[a-z0-9._-]+$"

If this was updated we could do something like:

  - name: Invalid child branch
    if:
      targets_branch:
        matches: "^(feature|amend|update|fix|refactor)/[a-z0-9._-]+$"
      from_branch:
        not_matches: "^task/[a-z]{2}/[a-z0-9._-]+$"

  - name: Invalid parent branch
    if:
      targets_branch:
        not_matches: "^(feature|amend|update|fix|refactor)/[a-z0-9._-]+$"
      from_branch:
        matches: "^task/[a-z]{2}/[a-z0-9._-]+$"