Sha256: 2bb870b070a5035f08ae84093d465e999abff7babf9e00e8ca8f53db9320a366

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 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, :repos, :sandbox, :all_neeto_repos

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

        def run
          check_for_apps_and_all_neeto_repos_option(repos, all_neeto_repos)
          matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox, false, all_neeto_repos)
          inform_about_default_rules_file
          matching_repos.each do |repo|
            ui.info("\n Working on \"#{repo}\" 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(repo, 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

1 entries across 1 versions & 1 rubygems

Version Path
neetob-0.2.3 lib/neetob/cli/github/protect_branch.rb