Sha256: 0bc95a782082dc86497816f117ea1780900e375d79e2a403f13debe87a7651b2

Contents?: true

Size: 1.51 KB

Versions: 5

Compression:

Stored size: 1.51 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)
        new(pull_request_id).execute
      end

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

      def initialize(pull_request_id=nil)
        @pull_request_id = pull_request_id
      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
          if config.deployable_label
            with_labelling do
              merge
            end
          else
            merge
          end
        end
      end

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

      def with_labelling(&block)
        pull_request = Octopolo::GitHub::PullRequest.new(config.github_repo, @pull_request_id)
        pull_request.add_labels(Deployable.deployable_label)
        unless yield
          pull_request.remove_labels(Deployable.deployable_label)
        end
      end
      private :with_labelling
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
octopolo-1.3.0 lib/octopolo/scripts/deployable.rb
octopolo-1.2.1 lib/octopolo/scripts/deployable.rb
octopolo-1.2.0 lib/octopolo/scripts/deployable.rb
octopolo-1.1.1 lib/octopolo/scripts/deployable.rb
octopolo-1.1.0 lib/octopolo/scripts/deployable.rb