Sha256: d10af8f636905ac915f046cb11ff044b6ffcbf2039b62738069df0330c14334a

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

require_relative "base"

module Neetob
  class CLI
    module Github
      class ProtectBranch < Base
        attr_accessor :branch_name, :required_rules_json_file_path, :apps, :sandbox

        def initialize(branch_name, apps, required_rules_json_file_path = "", sandbox = false)
          super()
          @branch_name = branch_name
          @required_rules_json_file_path = required_rules_json_file_path
          @apps = apps
          @sandbox = sandbox
        end

        def run
          matching_apps = find_all_matching_apps(apps, :github, sandbox)
          inform_about_default_rules_file
          matching_apps.each do |app|
            ui.info("\n Working on \"#{app}\" repo")
            ui.info(" Updating \"#{branch_name}\" branch protection rules")
            rules = read_json_file(required_rules_json_file_path || default_rules_file_path)
            rules_with_symbol_keys = rules.transform_keys(&:to_sym)
            client.protect_branch(app, branch_name, rules_with_symbol_keys)
            ui.success("Branch protection rules updated successfully")
          end
        end

        private

          def default_rules_file_path
            File.expand_path("../../../../data/branch-protection-rules.json", __dir__)
          end

          def inform_about_default_rules_file
            if required_rules_json_file_path.nil?
              ui.info("Updating protection rules from the \"neetob/data/branch-protection-rules.json\" file")
            end
          end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neetob-0.1.2 lib/neetob/cli/github/protect_branch.rb
neetob-0.1.1 lib/neetob/cli/github/protect_branch.rb
neetob-0.1.0 lib/neetob/cli/github/protect_branch.rb