GitHub PullRequestReviewCommentEvent at 2014-09-20 07:30:54
Repository: ontohub
Actor: houndci
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/ontohub/ontohub/pulls/comments/17818508","id":17818508,"diff_hunk":"@@ -0,0 +1,396 @@\n+#!/usr/bin/env ruby\n+\n+require 'active_support'\n+require 'fileutils'\n+require 'pathname'\n+\n+module RenameRefactor\n+  AFFECTED_FILETYPES = %w[\n+    rb\n+    js\n+    coffee\n+    html\n+    haml\n+    erb\n+    css\n+    sass\n+    scss\n+    yml\n+  ]\n+\n+  DIRECTORIES = %w[\n+    app\n+    config\n+    git\n+    lib\n+    spec\n+    test\n+  ]\n+\n+  REPLACE_WORDS = {\n+    'entity' => 'symbol',\n+    'link' => 'mapping',\n+  }\n+\n+  class RenameRefactorProvider\n+    include ActiveSupport::Inflector\n+\n+    attr_accessor :verbose, :dry_run\n+\n+    def initialize(verbose: false, dry_run: true)\n+      self.verbose = verbose\n+      self.dry_run = dry_run\n+    end\n+\n+    def run\n+      REPLACE_WORDS.each { |old_word, new_word| replace old_word, new_word }\n+    end\n+\n+    def replace(old_word, new_word)\n+      affected_files.each do |file|\n+        replace_in_file(file, old_word, new_word)\n+        rename_file(file, old_word, new_word)\n+      end\n+    end\n+\n+    def replace_in_file(file, old_word, new_word)\n+      commands = [\n+        \"gsub(\\\"#{old_word}\\\",\\\"#{new_word}\\\")\",\n+        \"gsub(\\\"#{pluralize(old_word)}\\\",\\\"#{pluralize(new_word)}\\\")\",\n+        \"gsub(\\\"#{camelize(old_word)}\\\",\\\"#{camelize(new_word)}\\\")\",\n+        \"gsub(\\\"#{camelize(pluralize(old_word))}\\\",\"\\\n+          \"\\\"#{camelize(pluralize(new_word))}\\\")\",\n+      ]\n+      tmp_file = \"> /tmp/awk_tmp_file && mv /tmp/awk_tmp_file #{file}\"\n+      command = \"#{awk} '{#{commands.join(';')};print}' #{file} #{tmp_file}\"\n+      puts command if verbose\n+      system(command) unless dry_run\n+    end\n+\n+    def rename_file(old_filename, old_word, new_word)\n+      new_filename = old_filename.gsub(\n+        /(?<=_|\\b)(#{old_word}|#{pluralize(old_word)})/) do |match|\n+        match == old_word ? new_word : pluralize(new_word)\n+      end\n+      if new_filename != old_filename\n+        puts \"#{old_filename} --> #{new_filename}\" if verbose\n+        if !dry_run\n+          FileUtils.mkdir_p(File.dirname(new_filename))\n+          FileUtils.mv(old_filename, new_filename)\n+        end\n+      end\n+    end\n+\n+    def affected_files\n+      filetype = AFFECTED_FILETYPES.first\n+      loc = DIRECTORIES.join(' ')\n+      out = `find #{loc} -iname \"*.#{filetype}\" #{other_filetype_options}`\n+      out.lines.map { |l| l.delete(\"\\n\") }\n+    end\n+\n+    def other_filetype_options\n+      AFFECTED_FILETYPES[1..-1].reduce('') do |options, filetype|\n+        options << \"-o -iname \\\"*.#{filetype}\\\" \"\n+      end\n+    end\n+\n+    def awk\n+      'awk'\n+    end\n+  end\n+\n+  class MigrationProvider\n+    include ActiveSupport::Inflector\n+\n+    STRUCTURE_SQL_PATH = Pathname.new('db/structure.sql')\n+    MIGRATION_DIRPATH  = Pathname.new('db/migrate')","path":"script/rename_refactor.rb","position":106,"original_position":106,"commit_id":"b5bc74df17da2832eeaadb52fc7e4bf7971e1a40","original_commit_id":"b5bc74df17da2832eeaadb52fc7e4bf7971e1a40","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=2","gravatar_id":"38d9cefd9971a05bf447f07c6cd332cc","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.","created_at":"2014-09-20T07:30:54Z","updated_at":"2014-09-20T07:30:54Z","html_url":"https://github.com/ontohub/ontohub/pull/1046#discussion_r17818508","pull_request_url":"https://api.github.com/repos/ontohub/ontohub/pulls/1046","_links":{"self":{"href":"https://api.github.com/repos/ontohub/ontohub/pulls/comments/17818508"},"html":{"href":"https://github.com/ontohub/ontohub/pull/1046#discussion_r17818508"},"pull_request":{"href":"https://api.github.com/repos/ontohub/ontohub/pulls/1046"}}},"pull_request":{"url":"https://api.github.com/repos/ontohub/ontohub/pulls/1046","id":21485606,"html_url":"https://github.com/ontohub/ontohub/pull/1046","diff_url":"https://github.com/ontohub/ontohub/pull/1046.diff","patch_url":"https://github.com/ontohub/ontohub/pull/1046.patch","issue_url":"https://api.github.com/repos/ontohub/ontohub/issues/1046","number":1046,"state":"open","locked":false,"title":"455 script for model name changing","user":{"login":"eugenk","id":339751,"avatar_url":"https://avatars.githubusercontent.com/u/339751?v=2","gravatar_id":"1b777dd0f315bb88d60e3a62fc7348f1","url":"https://api.github.com/users/eugenk","html_url":"https://github.com/eugenk","followers_url":"https://api.github.com/users/eugenk/followers","following_url":"https://api.github.com/users/eugenk/following{/other_user}","gists_url":"https://api.github.com/users/eugenk/gists{/gist_id}","starred_url":"https://api.github.com/users/eugenk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eugenk/subscriptions","organizations_url":"https://api.github.com/users/eugenk/orgs","repos_url":"https://api.github.com/users/eugenk/repos","events_url":"https://api.github.com/users/eugenk/events{/privacy}","received_events_url":"https://api.github.com/users/eugenk/received_events","type":"User","site_admin":false},"body":"This script renames\r\n* words in the code\r\n* code files\r\n* everything in the database by creating a new migration file\r\n * tables\r\n * columns\r\n * indexes\r\n * functions\r\n * words in function bodies\r\n* factory files (appends _factory) to the filename\r\n\r\nI only tested if the migrations can be executed. After running this script, we need to check the renames manually. It will rename more than it is supposed to. I *think* that it won't refrain renaming what needs to be renamed, but we should have an eye on that, too.","created_at":"2014-09-19T09:04:23Z","updated_at":"2014-09-20T07:30:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"79a09de8156259f3298d43559b02704b6850ec27","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ontohub/ontohub/pulls/1046/commits","review_comments_url":"https://api.github.com/repos/ontohub/ontohub/pulls/1046/comments","review_comment_url":"https://api.github.com/repos/ontohub/ontohub/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ontohub/ontohub/issues/1046/comments","statuses_url":"https://api.github.com/repos/ontohub/ontohub/statuses/b5bc74df17da2832eeaadb52fc7e4bf7971e1a40","head":{"label":"ontohub:455-script_for_model_name_changing","ref":"455-script_for_model_name_changing","sha":"b5bc74df17da2832eeaadb52fc7e4bf7971e1a40","user":{"login":"ontohub","id":1575984,"avatar_url":"https://avatars.githubusercontent.com/u/1575984?v=2","gravatar_id":"a7f409f3674b52f44a0c6aa8dbef61d1","url":"https://api.github.com/users/ontohub","html_url":"https://github.com/ontohub","followers_url":"https://api.github.com/users/ontohub/followers","following_url":"https://api.github.com/users/ontohub/following{/other_user}","gists_url":"https://api.github.com/users/ontohub/gists{/gist_id}","starred_url":"https://api.github.com/users/ontohub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontohub/subscriptions","organizations_url":"https://api.github.com/users/ontohub/orgs","repos_url":"https://api.github.com/users/ontohub/repos","events_url":"https://api.github.com/users/ontohub/events{/privacy}","received_events_url":"https://api.github.com/users/ontohub/received_events","type":"Organization","site_admin":false},"repo":{"id":3643206,"name":"ontohub","full_name":"ontohub/ontohub","owner":{"login":"ontohub","id":1575984,"avatar_url":"https://avatars.githubusercontent.com/u/1575984?v=2","gravatar_id":"a7f409f3674b52f44a0c6aa8dbef61d1","url":"https://api.github.com/users/ontohub","html_url":"https://github.com/ontohub","followers_url":"https://api.github.com/users/ontohub/followers","following_url":"https://api.github.com/users/ontohub/following{/other_user}","gists_url":"https://api.github.com/users/ontohub/gists{/gist_id}","starred_url":"https://api.github.com/users/ontohub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontohub/subscriptions","organizations_url":"https://api.github.com/users/ontohub/orgs","repos_url":"https://api.github.com/users/ontohub/repos","events_url":"https://api.github.com/users/ontohub/events{/privacy}","received_events_url":"https://api.github.com/users/ontohub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ontohub/ontohub","description":"A web-based repository for distributed ontologies.","fork":false,"url":"https://api.github.com/repos/ontohub/ontohub","forks_url":"https://api.github.com/repos/ontohub/ontohub/forks","keys_url":"https://api.github.com/repos/ontohub/ontohub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ontohub/ontohub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ontohub/ontohub/teams","hooks_url":"https://api.github.com/repos/ontohub/ontohub/hooks","issue_events_url":"https://api.github.com/repos/ontohub/ontohub/issues/events{/number}","events_url":"https://api.github.com/repos/ontohub/ontohub/events","assignees_url":"https://api.github.com/repos/ontohub/ontohub/assignees{/user}","branches_url":"https://api.github.com/repos/ontohub/ontohub/branches{/branch}","tags_url":"https://api.github.com/repos/ontohub/ontohub/tags","blobs_url":"https://api.github.com/repos/ontohub/ontohub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ontohub/ontohub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ontohub/ontohub/git/refs{/sha}","trees_url":"https://api.github.com/repos/ontohub/ontohub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ontohub/ontohub/statuses/{sha}","languages_url":"https://api.github.com/repos/ontohub/ontohub/languages","stargazers_url":"https://api.github.com/repos/ontohub/ontohub/stargazers","contributors_url":"https://api.github.com/repos/ontohub/ontohub/contributors","subscribers_url":"https://api.github.com/repos/ontohub/ontohub/subscribers","subscription_url":"https://api.github.com/repos/ontohub/ontohub/subscription","commits_url":"https://api.github.com/repos/ontohub/ontohub/commits{/sha}","git_commits_url":"https://api.github.com/repos/ontohub/ontohub/git/commits{/sha}","comments_url":"https://api.github.com/repos/ontohub/ontohub/comments{/number}","issue_comment_url":"https://api.github.com/repos/ontohub/ontohub/issues/comments/{number}","contents_url":"https://api.github.com/repos/ontohub/ontohub/contents/{+path}","compare_url":"https://api.github.com/repos/ontohub/ontohub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ontohub/ontohub/merges","archive_url":"https://api.github.com/repos/ontohub/ontohub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ontohub/ontohub/downloads","issues_url":"https://api.github.com/repos/ontohub/ontohub/issues{/number}","pulls_url":"https://api.github.com/repos/ontohub/ontohub/pulls{/number}","milestones_url":"https://api.github.com/repos/ontohub/ontohub/milestones{/number}","notifications_url":"https://api.github.com/repos/ontohub/ontohub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ontohub/ontohub/labels{/name}","releases_url":"https://api.github.com/repos/ontohub/ontohub/releases{/id}","created_at":"2012-03-06T22:05:27Z","updated_at":"2014-09-02T10:07:12Z","pushed_at":"2014-09-20T07:30:47Z","git_url":"git://github.com/ontohub/ontohub.git","ssh_url":"git@github.com:ontohub/ontohub.git","clone_url":"https://github.com/ontohub/ontohub.git","svn_url":"https://github.com/ontohub/ontohub","homepage":"","size":38611,"stargazers_count":17,"watchers_count":17,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":288,"forks":4,"open_issues":288,"watchers":17,"default_branch":"staging"}},"base":{"label":"ontohub:staging","ref":"staging","sha":"63c0df8296fa33ccdfb1c5f57fd1a2309e3c4c45","user":{"login":"ontohub","id":1575984,"avatar_url":"https://avatars.githubusercontent.com/u/1575984?v=2","gravatar_id":"a7f409f3674b52f44a0c6aa8dbef61d1","url":"https://api.github.com/users/ontohub","html_url":"https://github.com/ontohub","followers_url":"https://api.github.com/users/ontohub/followers","following_url":"https://api.github.com/users/ontohub/following{/other_user}","gists_url":"https://api.github.com/users/ontohub/gists{/gist_id}","starred_url":"https://api.github.com/users/ontohub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontohub/subscriptions","organizations_url":"https://api.github.com/users/ontohub/orgs","repos_url":"https://api.github.com/users/ontohub/repos","events_url":"https://api.github.com/users/ontohub/events{/privacy}","received_events_url":"https://api.github.com/users/ontohub/received_events","type":"Organization","site_admin":false},"repo":{"id":3643206,"name":"ontohub","full_name":"ontohub/ontohub","owner":{"login":"ontohub","id":1575984,"avatar_url":"https://avatars.githubusercontent.com/u/1575984?v=2","gravatar_id":"a7f409f3674b52f44a0c6aa8dbef61d1","url":"https://api.github.com/users/ontohub","html_url":"https://github.com/ontohub","followers_url":"https://api.github.com/users/ontohub/followers","following_url":"https://api.github.com/users/ontohub/following{/other_user}","gists_url":"https://api.github.com/users/ontohub/gists{/gist_id}","starred_url":"https://api.github.com/users/ontohub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ontohub/subscriptions","organizations_url":"https://api.github.com/users/ontohub/orgs","repos_url":"https://api.github.com/users/ontohub/repos","events_url":"https://api.github.com/users/ontohub/events{/privacy}","received_events_url":"https://api.github.com/users/ontohub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ontohub/ontohub","description":"A web-based repository for distributed ontologies.","fork":false,"url":"https://api.github.com/repos/ontohub/ontohub","forks_url":"https://api.github.com/repos/ontohub/ontohub/forks","keys_url":"https://api.github.com/repos/ontohub/ontohub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ontohub/ontohub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ontohub/ontohub/teams","hooks_url":"https://api.github.com/repos/ontohub/ontohub/hooks","issue_events_url":"https://api.github.com/repos/ontohub/ontohub/issues/events{/number}","events_url":"https://api.github.com/repos/ontohub/ontohub/events","assignees_url":"https://api.github.com/repos/ontohub/ontohub/assignees{/user}","branches_url":"https://api.github.com/repos/ontohub/ontohub/branches{/branch}","tags_url":"https://api.github.com/repos/ontohub/ontohub/tags","blobs_url":"https://api.github.com/repos/ontohub/ontohub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ontohub/ontohub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ontohub/ontohub/git/refs{/sha}","trees_url":"https://api.github.com/repos/ontohub/ontohub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ontohub/ontohub/statuses/{sha}","languages_url":"https://api.github.com/repos/ontohub/ontohub/languages","stargazers_url":"https://api.github.com/repos/ontohub/ontohub/stargazers","contributors_url":"https://api.github.com/repos/ontohub/ontohub/contributors","subscribers_url":"https://api.github.com/repos/ontohub/ontohub/subscribers","subscription_url":"https://api.github.com/repos/ontohub/ontohub/subscription","commits_url":"https://api.github.com/repos/ontohub/ontohub/commits{/sha}","git_commits_url":"https://api.github.com/repos/ontohub/ontohub/git/commits{/sha}","comments_url":"https://api.github.com/repos/ontohub/ontohub/comments{/number}","issue_comment_url":"https://api.github.com/repos/ontohub/ontohub/issues/comments/{number}","contents_url":"https://api.github.com/repos/ontohub/ontohub/contents/{+path}","compare_url":"https://api.github.com/repos/ontohub/ontohub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ontohub/ontohub/merges","archive_url":"https://api.github.com/repos/ontohub/ontohub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ontohub/ontohub/downloads","issues_url":"https://api.github.com/repos/ontohub/ontohub/issues{/number}","pulls_url":"https://api.github.com/repos/ontohub/ontohub/pulls{/number}","milestones_url":"https://api.github.com/repos/ontohub/ontohub/milestones{/number}","notifications_url":"https://api.github.com/repos/ontohub/ontohub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ontohub/ontohub/labels{/name}","releases_url":"https://api.github.com/repos/ontohub/ontohub/releases{/id}","created_at":"2012-03-06T22:05:27Z","updated_at":"2014-09-02T10:07:12Z","pushed_at":"2014-09-20T07:30:47Z","git_url":"git://github.com/ontohub/ontohub.git","ssh_url":"git@github.com:ontohub/ontohub.git","clone_url":"https://github.com/ontohub/ontohub.git","svn_url":"https://github.com/ontohub/ontohub","homepage":"","size":38611,"stargazers_count":17,"watchers_count":17,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":288,"forks":4,"open_issues":288,"watchers":17,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/ontohub/ontohub/pulls/1046"},"html":{"href":"https://github.com/ontohub/ontohub/pull/1046"},"issue":{"href":"https://api.github.com/repos/ontohub/ontohub/issues/1046"},"comments":{"href":"https://api.github.com/repos/ontohub/ontohub/issues/1046/comments"},"review_comments":{"href":"https://api.github.com/repos/ontohub/ontohub/pulls/1046/comments"},"review_comment":{"href":"https://api.github.com/repos/ontohub/ontohub/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ontohub/ontohub/pulls/1046/commits"},"statuses":{"href":"https://api.github.com/repos/ontohub/ontohub/statuses/b5bc74df17da2832eeaadb52fc7e4bf7971e1a40"}}}}