policy-bot icon indicating copy to clipboard operation
policy-bot copied to clipboard

Dynamic team approval requirements based on file path

Open jmcampanini opened this issue 5 years ago • 1 comments

It would be great if we could somehow specify that the team required for approval for a rule would be dynamically determined based on the file path.

As an example, in MyCloud we have deployment-specific files in several repos whose path is a particular structure, and includes the MyCloud identifier. We want to be able to have a rule, therefore, that says if there are changes only to a specific deployment's files, allow members of that deployment's team to approve. We can have explicit rules for each identifier to do this, but there are over 100 identifiers and there is churn, so it would be awesome if we could just specify one rule that is dynamic.

An example implementation would be having capture groups in the file path regex, and then being able to use the captured text in the list of teams that can approve for that rule

rough outline of a spitball idea we talked about:

  - name: match a team to a file
    if:
      changed_files:
        paths:
          - "^folder/{{captured}}/somefile\\.yml$"
    requires:
      count: 1
      teams: ["team-{{captured}}"]

jmcampanini avatar Oct 12 '18 22:10 jmcampanini

An alternative to capture groups might be to have a list of variable values that are expanded internally:

  - name: match a team to a file
    repeat_for:
      - team1
      - team2
      - team3
    if:
      changed_files:
        paths:
          - "^folder/{{loop.value}}/somefile\\.yml$"
    requires:
      count: 1
      teams: ["team-{{loop.value}}"]

I think this would be easier to implement, but has the downside of forcing users to list out all the possible values.

bluekeyes avatar Nov 09 '20 21:11 bluekeyes