Sha256: 88b0adca29b828f8c750661b79a67b7f5dd2f56394b0666f6675ad6db9273959

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 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

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

        def run
          matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
          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

7 entries across 7 versions & 1 rubygems

Version Path
neetob-0.3.2 lib/neetob/cli/github/protect_branch.rb
neetob-0.3.1 lib/neetob/cli/github/protect_branch.rb
neetob-0.3.0 lib/neetob/cli/github/protect_branch.rb
neetob-0.2.7 lib/neetob/cli/github/protect_branch.rb
neetob-0.2.6 lib/neetob/cli/github/protect_branch.rb
neetob-0.2.5 lib/neetob/cli/github/protect_branch.rb
neetob-0.2.4 lib/neetob/cli/github/protect_branch.rb