Sha256: 79a88845d1d361eb587c9c0a54329d1ae208300243d6e7cc5c10aca19c7b6c9c

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require "github/event"

module Github
  class PullRequestEvent < Event
    attr_reader :action, :pull_request

    # https://developer.github.com/v3/activity/events/types/#pullrequestevent
    def initialize(payload)
      super
      @action = payload.fetch "action"
      @pull_request = payload.fetch "pull_request"
    end

    def process!
      Rails.logger.info "\e[34m[github] Processing Pull Request Event (action: #{action})\e[0m"

      # Ignore when pull requests are assigned
      if action == "assigned" || action == "unassigned"
        return
      end

      # Delete pull requests when they are closed
      if action == "closed"
        PullRequest.close! pull_request
        return
      end

      # Ensure that we have a record of this open pull request
      # action: labeled, unlabeled, opened, reopened, or synchronized
      pr = PullRequest.upsert! pull_request

      # The Pull Request may be invalid if it isn't for a
      # project that exists in Houston.
      return unless pr && pr.persisted?

      case action
      when "labeled" then pr.add_label! payload["label"]["name"]
      when "unlabeled" then pr.remove_label! payload["label"]["name"]
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
houston-core-0.5.0.beta1 app/models/github/pull_request_event.rb