Sha256: 79d5bb3d4eeb8190c6fd73cc64c9f36d060b012459c3bbde0f852797a1cd1e73

Contents?: true

Size: 1.71 KB

Versions: 22

Compression:

Stored size: 1.71 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, :all_neeto_repos

        def initialize(branch_name, apps, 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
          @apps = apps
          @sandbox = sandbox
          @all_neeto_repos = all_neeto_repos
        end

        def run
          check_for_apps_and_all_neeto_repos_option(apps, all_neeto_repos)
          matching_apps = find_all_matching_apps(apps, :github, sandbox, false, all_neeto_repos)
          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

22 entries across 22 versions & 2 rubygems

Version Path
neetob-ud-1.0.59 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.8 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.6 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.4 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.3 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.2 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.1 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.0 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.1.3 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.1.2 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.1.1 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.1.0 lib/neetob/cli/github/protect_branch.rb
neetob-0.2.2 lib/neetob/cli/github/protect_branch.rb
neetob-0.2.1 lib/neetob/cli/github/protect_branch.rb
neetob-0.2.0 lib/neetob/cli/github/protect_branch.rb
neetob-0.1.5 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.14 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.13 lib/neetob/cli/github/protect_branch.rb
neetob-0.1.4 lib/neetob/cli/github/protect_branch.rb
neetob-ud-0.2.11 lib/neetob/cli/github/protect_branch.rb