Skip to content

Add support for branches resource type

What does this MR do and why?

This is an implementation proposal for #215

The use cases in mind are :

  • Remove stale branches
  • Removing branches matching a particular pattern
  • Remove branches that has been merged

It add support for a new resource_type : branches.
It add support or a new action : delete , that can also be used with the existing types.
It add new filters :
BranchDateFilter : filters branches using last commit committed_date or authored_date attribute.
BranchProtectedFilter : filters branches using the protected attribute. If not specified, protected branches are filtered out by default as deleting protected branches requires extra actions.
I may add filters to filters branches that are merged later.

The summary, comment_on_summary and issue actions can be used with branches. comment based actions cannot, so I added a extra check in the comment action.

I will update the README soon, in the mean time here is an example policy : I updated the example policy in the README, but here is a more complete one you can try :

resource_rules:
  branches:
    rules:
      - name: Test branch policy
        conditions:
          date:
            attribute: committed_date
            condition: older_than
            interval_type: months
            interval: 30
          name: ^dev
          protected: false
        actions:
          delete: true
          issue:
            title: |
              The branch {{name}} was deleted
            description: |
              The branch {{name}} was deleted

          summarize:
            destination: julesaaelio/gitlab-triage
            title: |
              Deleted branches
            item: |
              - [ ] [{{name}}]({{web_url}})
            redact_confidential_resources: false
            summary: |
              The following branches were deleted:

              {{items}}
Edited by LAURENT Jules

Merge request reports