Sha256: 6b2512e7e5087c4c9a25e995e3e0a0b5df371056a447301dd8e5fca9c5d5bf98

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

module Danger
  # Show the greeting on a pull request.
  #
  # @example Show the greeting
  #          welcome_message.greet
  #
  # @example When you want to greet with your words
  #          welcome_message.custom_words = <<-CUSTOM_WORDS
  #            Hi, @#{github.pr_author}!!
  #            Welcome to #{github.pr_json[:base][:repo][:full_name]}! Thanks so much for joining us.
  #          CUSTOM_WORDS
  #
  #          welcome_message.greet
  #
  # @example When you want to see the greeting irrespective of the conditions
  #          welcome_message.greet_test
  #
  # @see  soudai-s/danger-welcome_message
  # @tags monday, weekends, time, rattata
  #
  class DangerWelcomeMessage < Plugin


    # Custom words for greeting
    #
    # @return [String]
    attr_writer :custom_words

    # Greet when a new member makes a first pull request
    #
    # @return [void]
    def greet
      message greeting_words if new_member?
    end

    # Greet every time
    #
    # @return [void]
    def greet_test
      message greeting_words
    end

    private

      def repo
        @repository ||= github.pr_json[:base][:repo][:full_name]
      end

      def collaborators
        @collaborators ||= github.api.collaborators(repo).map { |c| c.login }
      end

      def experienced_people
        @experienced_people ||= github.api.pull_requests(repo).map { |pr| pr.user.login }.uniq
      end

      def new_member?
        new_members = collaborators - experienced_people
        new_members.include? github.pr_author
      end

      def greeting_words
        @custom_words || "Welcome, #{github.pr_author} 🎉"
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-welcome_message-0.0.1 lib/welcome_message/plugin.rb