<commit_before>module Tissues
  module Sync
    include Octopi
    include Tissues::Helpers
    extend self
    
    def go!
      authenticated do
        local_todos = area.todos
        sync_back_to_github = []

        repository = Repository.find(:name => origin_path.split('/').last,
                                     :user => origin_path.split('/').first)
        repository.all_issues.each do |issue|
          if todo = Things::Todo.find(name_with_id(issue))
            todo.area = area
            unless todo.completed?
              todo.status = issue.state.to_status
            else
              sync_back_to_github << todo
            end
            todo.notes = issue.body
            todo.save
            todo.reference.area.set(area.reference)
          else
            todo = Things::Todo.create(
              :name   => name_with_id(issue),
              :status => issue.state.to_status,
              :notes  => issue.body,
              :area   => area
            )
          end
          local_todos.reject!{|todo| todo.name == name_with_id(issue)}
        end

        local_todos.each do |todo|
          issue = Issue.open(
            :params => {
              :title => todo.name,
              :state => todo.status.to_s.to_state,
              :body => todo.notes
            },
            :repository => repository
          )
          todo.name = name_with_id(issue)
          todo.save
          todo.reference.area.set(area.reference) # resave area association
        end

        sync_back_to_github.each do |todo|
          issue = Issue.find(:repository => repository, :number => todo.number)
          (todo.status == 'open') ? issue.reopen! : issue.close!
        end
      end
    end

    def area
      return @area if defined? @area
      @area = Things::Area.find(origin_path) || 
              Things::Area.create(:name => origin_path)
    end
    
    def origin_path
      return @origin_path if defined? @origin_path
      @origin_path = `git remote -v | grep fetch`.
                      split(':').
                      last.
                      split('.git ').
                      first
      @origin_path = 'holman/tissuestest'
    end

  end
end<commit_msg>and holman said let there be light<commit_after>module Tissues
  module Sync
    include Octopi
    include Tissues::Helpers
    extend self
    
    def go!
      authenticated do
        local_todos = area.todos
        sync_back_to_github = []

        repository = Repository.find(:name => origin_path.split('/').last,
                                     :user => origin_path.split('/').first)
        repository.all_issues.each do |issue|
          if todo = Things::Todo.find(name_with_id(issue))
            todo.area = area
            unless todo.completed?
              todo.status = issue.state.to_status
            else
              sync_back_to_github << todo
            end
            todo.notes = issue.body
            todo.save
            todo.reference.area.set(area.reference)
          else
            todo = Things::Todo.create(
              :name   => name_with_id(issue),
              :status => issue.state.to_status,
              :notes  => issue.body,
              :area   => area
            )
          end
          local_todos.reject!{|todo| todo.name == name_with_id(issue)}
        end

        local_todos.each do |todo|
          issue = Issue.open(
            :params => {
              :title => todo.name,
              :state => todo.status.to_s.to_state,
              :body => todo.notes
            },
            :repository => repository
          )
          todo.name = name_with_id(issue)
          todo.save
          todo.reference.area.set(area.reference) # resave area association
        end

        sync_back_to_github.each do |todo|
          issue = Issue.find(:repository => repository, :number => todo.number)
          (todo.status == 'open') ? issue.reopen! : issue.close!
        end
      end
    end

    def area
      return @area if defined? @area
      @area = Things::Area.find(origin_path) || 
              Things::Area.create(:name => origin_path)
    end
    
    def origin_path
      return @origin_path if defined? @origin_path
      @origin_path = `git remote -v | grep fetch`.
                      split(':').
                      last.
                      split('.git ').
                      first
    end

  end
end
{'fraction_non_alphanumeric': 0.10011248593925759, 'fraction_numerical': 0.0, 'mean_word_length': 1.4176182707993474, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6050712', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1235, 'n_words': 261}