Sha256: 3e9f23bb192b05c01a4e551ea1be263fd6f607dab74d41454669f2f3ef0e4d02

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Ruboty
  module Github
    module Actions
      class CreateDeployPullRequest < CreatePullRequest
        private

        def create
          super

          message.reply('@here :warning: This deployment includes some database migrations') if database_schema_changed?
        end

        # e.g. master
        def to_branch
          to.split(':').last
        end

        def body
          lines = included_pull_requests.map do |pr|
            "- [##{pr[:number]}](#{pr[:html_url]}): #{pr[:title]} by @#{pr[:user][:login]}"
          end
          lines.unshift('## Pull Requests to deploy', '')
          lines.join("\n")
        end

        def included_pull_requests
          numbers = comparison.commits.map do |commit|
            /^Merge pull request #(\d+) from/ =~ commit[:commit][:message]
            ::Regexp.last_match(1)
          end
          numbers.compact.map { |number| client.pull_request(repository, number.to_i) }
        end

        def database_schema_changed?
          comparison.files.any? { |file| file.filename == 'db/schema.rb' }
        end

        def comparison
          @comparison ||= begin
            start = client.branch(repository, to_branch)[:commit][:sha]
            endd  = client.branch(repository, from_branch)[:commit][:sha]
            client.compare(repository, start, endd)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruboty-qiita-github-0.3.0 lib/ruboty/github/actions/create_deploy_pull_request.rb