app/helpers/dispatch_helper.rb
# Parse the incoming payload and do something with it...
Parse the incoming payload and do something with it
Parse the incoming payload and do something with it
def parse_payload!
      return if assigned?
      return if opened?
      return if closed?
      return if locked?
      return if pinned?
      return if unlocked?
      if edited?
        if issues.has_key?('last_edits')
          issues['last_edits'][sender] = payload['issue']['updated_at']
        else
          issues['last_edits'] = {}
          issues['last_edits'][sender] = payload['issue']['updated_at']
        end
        paper.percent_complete = paper.fraction_check_boxes_complete
        paper.last_activity = payload['issue']['updated_at']
        paper.save and return
      end
      if labeled?
        new_labels = Hash.new
        labels.each do |label|
          new_labels.merge!(label['name'] => label['color'])
        end
        paper.labels = new_labels
        paper.save and return
      end
      if commented?
        if issues.has_key?('last_comments')
          issues['last_comments'][sender] = payload['issue']['updated_at']
        else
          issues['last_comments'] = {}
          issues['last_comments'][sender] = payload['issue']['updated_at']
        end
        paper.last_activity = payload['issue']['updated_at']
      end
      if pre_review?
        kind = 'pre-review'
        return if issue_number != paper.meta_review_issue_id
      else
        kind = 'review'
        return if issue_number != paper.review_issue_id
      end
      issues['comments'].unshift(
        'author' => sender,
        'comment' => comment_body,
        'commented_at' => commented_at,
        'comment_url' => comment_url,
        'kind' => kind
      )
      if issues['commenters'][kind].has_key?(sender)
        issues['commenters'][kind][sender] += 1
      else
        issues['commenters'][kind].merge!(sender => 1)
      end
      issues['comments'] = issues['comments'].take(5)
      paper.last_activity = commented_at
      paper.save
    end
def parse_payload! return if assigned? return if opened? return if closed? return if locked? return if pinned? return if unlocked? if edited? if issues . has_key? ( 'last_edits' ) issues [ 'last_edits' ] [ sender ] = payload [ 'issue' ] [ 'updated_at' ] else issues [ 'last_edits' ] = { } issues [ 'last_edits' ] [ sender ] = payload [ 'issue' ] [ 'updated_at' ] end paper . percent_complete = paper . fraction_check_boxes_complete paper . last_activity = payload [ 'issue' ] [ 'updated_at' ] paper . save and return end if labeled? new_labels = Hash . new labels . each do | label | new_labels . merge! ( label [ 'name' ] => label [ 'color' ] ) end paper . labels = new_labels paper . save and return end if commented? if issues . has_key? ( 'last_comments' ) issues [ 'last_comments' ] [ sender ] = payload [ 'issue' ] [ 'updated_at' ] else issues [ 'last_comments' ] = { } issues [ 'last_comments' ] [ sender ] = payload [ 'issue' ] [ 'updated_at' ] end paper . last_activity = payload [ 'issue' ] [ 'updated_at' ] end if pre_review? kind = 'pre-review' return if issue_number != paper . meta_review_issue_id else kind = 'review' return if issue_number != paper . review_issue_id end issues [ 'comments' ] . unshift ( 'author' => sender , 'comment' => comment_body , 'commented_at' => commented_at , 'comment_url' => comment_url , 'kind' => kind ) if issues [ 'commenters' ] [ kind ] . has_key? ( sender ) issues [ 'commenters' ] [ kind ] [ sender ] += 1 else issues [ 'commenters' ] [ kind ] . merge! ( sender => 1 ) end issues [ 'comments' ] = issues [ 'comments' ] . take ( 5 ) paper . last_activity = commented_at paper . save end
Parse the incoming payload and do something with it...
Parse the incoming payload and do something with it ...
# Parse the labels and update papers with the new labels. # New addition to keep track of the last comments by each  # person on the thread. # Something has gone wrong if this isn't the case... # Only keep the last 5 comments