Sha256: 040a12cfa4502e2ac82e896cdf8abe21a5418d08ecc8970ed3523b8ca6fe8cba

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

require "github/event"

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

    # https://developer.github.com/v3/activity/events/types/#pullrequestevent
    def initialize(payload)
      super
      @action = payload.fetch "action"
      @pull_request = payload.fetch "pull_request"
      @actor = payload.fetch("sender", {})["login"]
    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

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

      # 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"], as: actor
      when "unlabeled" then pr.remove_label! payload["label"], as: actor
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre app/models/github/pull_request_event.rb
houston-core-0.7.0 app/models/github/pull_request_event.rb
houston-core-0.7.0.beta4 app/models/github/pull_request_event.rb
houston-core-0.7.0.beta3 app/models/github/pull_request_event.rb
houston-core-0.7.0.beta2 app/models/github/pull_request_event.rb
houston-core-0.7.0.beta app/models/github/pull_request_event.rb