Sha256: d414b6ea37e4c006410b8a20a4d0286c856c2b8fc33666ad44b95183a5bb85ed
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
module Hubstats class Comment < ActiveRecord::Base scope :pull_reviews_count, lambda { select("hubstats_comments.user_id") .select("COUNT(DISTINCT hubstats_pull_requests.id) as total") .joins("LEFT JOIN hubstats_pull_requests ON hubstats_pull_requests.id = hubstats_comments.pull_request_id") .where("hubstats_pull_requests.user_id != hubstats_comments.user_id") .group("hubstats_comments.user_id") } scope :created_since, lambda {|time| where("created_at > ?", time) } scope :belonging_to_pull_request, lambda {|pull_request_id| where(pull_request_id: pull_request_id)} scope :belonging_to_user, lambda {|user_id| where(user_id: user_id)} scope :belonging_to_repo, lambda {|repo_id| where(repo_id: repo_id)} attr_accessible :id, :html_url, :url, :pull_request_url, :diff_hunk, :path, :position, :original_position, :line, :commit_id, :original_commit_id, :body, :created_at, :updated_at, :user_id, :pull_request_id, :repo_id, :kind belongs_to :user belongs_to :pull_request belongs_to :repo def self.create_or_update(github_comment) logger.warn github_comment.inspect github_comment = github_comment.to_h if github_comment.respond_to? :to_h user = Hubstats::User.create_or_update(github_comment[:user]) github_comment[:user_id] = user.id if github_comment[:pull_number] pull_request = Hubstats::PullRequest.belonging_to_repo(github_comment[:repo_id]).where(number: github_comment[:pull_number]).first if pull_request github_comment[:pull_request_id] = pull_request.id end end comment_data = github_comment.slice(*Hubstats::Comment.column_names.map(&:to_sym)) comment = where(:id => comment_data[:id]).first_or_create(comment_data) return comment if comment.update_attributes(comment_data) puts comment.errors.inspect end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hubstats-0.0.15 | app/models/hubstats/comment.rb |