Sha256: d00184241326ea47abec1107e4d4b79eb14d03bbcc40d1e8121be59a8ddd8d91

Contents?: true

Size: 1.8 KB

Versions: 12

Compression:

Stored size: 1.8 KB

Contents

require_relative "../scripts"
require_relative "../pull_request_merger"
require_relative "../github"

module Octopolo
  module Scripts
    class Deployable
      include CLIWrapper
      include ConfigWrapper

      attr_accessor :pull_request_id

      def self.execute(pull_request_id=nil, options={})
        new(pull_request_id, options).execute
      end

      def self.deployable_label
        Octopolo::GitHub::Label.new(name: "deployable", color: "428BCA")
      end

      def initialize(pull_request_id=nil, options={})
        @pull_request_id = pull_request_id
        @force = options[:force]
      end

      # Public: Perform the script
      def execute
        if (!self.pull_request_id)
          current = GitHub::PullRequest.current
          self.pull_request_id = current.number if current
        end
        self.pull_request_id ||= cli.prompt("Pull Request ID: ")
        GitHub.connect do
          unless deployable? || @force
            CLI.say 'Pull request status checks have not passed. Cannot be marked deployable.'
            exit!
          end

          merge_result = merge
          add_deployable_label if config.deployable_label && merge_result
        end
      end

      def merge
        PullRequestMerger.new(Git::DEPLOYABLE_PREFIX, Integer(@pull_request_id), :user_notifications => config.user_notifications).perform
      end
      private :merge

      def add_deployable_label
        pull_request.add_labels(Deployable.deployable_label)
      end
      private :add_deployable_label

      def deployable?
        pull_request.mergeable? && pull_request.status_checks_passed?
      end
      private :deployable?

      def pull_request
        @pull_request ||= Octopolo::GitHub::PullRequest.new(config.github_repo, @pull_request_id)
      end
      private :pull_request
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
octopolo-1.12.0 lib/octopolo/scripts/deployable.rb
octopolo-1.11.4 lib/octopolo/scripts/deployable.rb
octopolo-1.11.3 lib/octopolo/scripts/deployable.rb
octopolo-1.11.1 lib/octopolo/scripts/deployable.rb
octopolo-1.11.0 lib/octopolo/scripts/deployable.rb
octopolo-1.9.0 lib/octopolo/scripts/deployable.rb
octopolo-1.8.1 lib/octopolo/scripts/deployable.rb
octopolo-1.8.0 lib/octopolo/scripts/deployable.rb
octopolo-1.7.1 lib/octopolo/scripts/deployable.rb
octopolo-1.7.0 lib/octopolo/scripts/deployable.rb
octopolo-1.6.0 lib/octopolo/scripts/deployable.rb
octopolo-1.5.3 lib/octopolo/scripts/deployable.rb