cleanup_project_branches

in lib/release_tools/auto_deploy/cleanup.rb [45:96]


      def cleanup_project_branches(path, client)
        
        
        
        to_delete = Set.new

        client.branches(path, search: '-auto-deploy-').auto_paginate do |branch|
          next unless branch.name.match?(GitlabClient::AUTO_DEPLOY_BRANCH_REGEX)

          begin
            date = auto_deploy_branch_date(branch.name)
          rescue ArgumentError
            ReleaseTools.logger.error(
              "The branch #{branch.name} is not a using a valid auto-deploy branch name",
              project: path
            )

            next
          end

          
          
          
          
          
          
          to_delete.add(branch.name) if date <= @minimum_date
        end

        if to_delete.empty?
          ReleaseTools.logger.info(
            'There are no outdated auto-deploy branches to remove',
            project: path
          )

          return
        end

        ReleaseTools.logger.info(
          "Removing #{to_delete.length} outdated auto-deploy branches",
          project: path
        )

        
        
        to_delete.each do |branch|
          Retriable.with_context(:api) do
            client.delete_branch(branch, path)
          end
        end
      end