<commit_before>require 'open-uri'

class Project < ActiveRecord::Base
  belongs_to :owner, class_name: 'User'
  has_many :assignments
  has_many :organizations, through: :assignments
  has_many :issues

  def self.load_from_github params
    info = JSON.parse open("https://api.github.com/repos/%s/%s" % [params[:owner], params[:github_name]]).read

    project = Project.find_or_create_by id: info['id']

    project.github_name = params[:github_name]
    project.name = params[:github_name].gsub(/_/, ' ').titleize
    project.description = info['description']
    project.owner = User.find_or_create_by github_name: params[:owner]

    project.reload_issues

    project.save
  end

  def reload_issues
    issues = JSON.parse open("https://api.github.com/repos/%s/%s/issues" % [owner.github_name, github_name]).read

    issues.each do |issue_res|
      issue = Issue.find_or_create_by project: self, github_id: issue_res['id']
      issue.name = issue_res['title']
      issue.url = issue_res['html_url']
      issue.milestone = Milestone.find_or_create_by name: issue_res.try(:[], 'milestone').try(:[], 'title')
      issue.description = issue_res['body']
      issue.save
    end
  end
end<commit_msg>changing name<commit_after>require 'open-uri'

class Project < ActiveRecord::Base
  belongs_to :owner, class_name: 'User'
  has_many :assignments
  has_many :organizations, through: :assignments
  has_many :issues

  def self.load_from_github params
    info = JSON.parse open("https://api.github.com/repos/%s/%s" % [params[:owner], params[:github_name]]).read

    project = Project.find_or_create_by id: info['id']

    project.github_name = params[:github_name]
    project.name = params[:github_name].gsub(/_/, ' ').titleize
    project.description = info['description']
    project.owner = User.find_or_create_by github_name: params[:owner]

    project.reload_issues

    project.save
  end

  def reload_issues
    issues = JSON.parse open("https://api.github.com/repos/%s/%s/issues" % [owner.username, github_name]).read

    issues.each do |issue_res|
      issue = Issue.find_or_create_by project: self, github_id: issue_res['id']
      issue.name = issue_res['title']
      issue.url = issue_res['html_url']
      issue.milestone = Milestone.find_or_create_by name: issue_res.try(:[], 'milestone').try(:[], 'title')
      issue.description = issue_res['body']
      issue.save
    end
  end
end
{'fraction_non_alphanumeric': 0.13675922088686282, 'fraction_numerical': 0.0, 'mean_word_length': 4.050209205020921, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1962071', 'n_tokens_mistral': 800, 'n_tokens_neox': 779, 'n_words': 150}