{"action":"created","comment":{"url":"https://api.github.com/repos/github/linguist/pulls/comments/78297573","id":78297573,"diff_hunk":"@@ -0,0 +1,92 @@\n+#!/usr/bin/env ruby\n+\n+require \"optparse\"\n+\n+ROOT = File.expand_path(\"../../\", __FILE__)\n+\n+\n+# Break a repository URL into its separate components\n+def parse_url(input)\n+  hosts = \"github\\.com|bitbucket\\.org|gitlab\\.com\"\n+  \n+  # HTTPS/HTTP link pointing to recognised hosts\n+  if input =~ /^(?:https?:\\/\\/)?(?:[^.@]+@)?(?:www\\.)?(#{hosts})\\/([^\\/]+)\\/([^\\/]+)/i\n+    { host: $1.downcase(), user: $2, repo: $3.sub(/\\.git$/, \"\") }\n+  # SSH\n+  elsif input =~ /^git@(#{hosts}):([^\\/]+)\\/([^\\/]+)\\.git$/i\n+    { host: $1.downcase(), user: $2, repo: $3 }\n+  # provider:user/repo\n+  elsif input =~ /^(github|bitbucket|gitlab):\\/?([^\\/]+)\\/([^\\/]+)\\/?$/i\n+    { host: $1.downcase(), user: $2, repo: $3 }\n+  # user/repo - Common GitHub shorthand\n+  elsif input =~ /^\\/?([^\\/]+)\\/([^\\/]+)\\/?$/\n+    { host: \"github.com\", user: $1, repo: $2 }\n+  else\n+    raise \"Unsupported URL: #{input}\"\n+  end\n+end\n+\n+# Isolate the vendor-name component of a submodule path\n+def parse_submodule(name)\n+  name =~ /^(?:.*(?:vendor\\/)?grammars\\/)?([^\\/]+)/i\n+  path = \"vendor/grammars/#{$1}\"\n+  unless File.exist?(\"#{ROOT}/\" + path)\n+    warn \"Submodule '#{path}' does not exist. Aborting.\"\n+    exit 1\n+  end\n+  path\n+end\n+\n+# Print debugging feedback to STDOUT if running with --verbose\n+def log(msg)\n+  puts msg if $verbose\n+end\n+\n+\n+usage = \"\"\"Usage:\n+  #{$0} [--replace grammar] url\n+Examples:\n+  #{$0} https://github.com/Alhadis/language-roff\n+  #{$0} --replace sublime-apl https://github.com/Alhadis/language-apl\n+\"\"\"\n+\n+$replace = nil\n+$verbose = false\n+\n+OptionParser.new do |opts|\n+  opts.banner = usage\n+  opts.on(\"-v\", \"--verbose\", \"Print verbose feedback to STDOUT\") do\n+    $verbose = true\n+  end\n+  opts.on(\"-rSUBMODULE\", \"--replace=SUBMODDULE\", \"Replace an existing grammar submodule.\") do |name|\n+    $replace = name\n+  end\n+end.parse!\n+\n+\n+$url = ARGV[0]\n+\n+# No URL? Print a usage message and bail.\n+unless $url\n+  warn usage\n+  exit 1;\n+end\n+\n+# Ensure the given URL is an HTTPS link\n+parts    = parse_url $url\n+https    = \"https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}\"\n+repo_new = \"vendor/grammars/#{parts[:repo]}\"\n+repo_old = parse_submodule($replace) if $replace\n+\n+if repo_old\n+  log \"Deregistering: #{repo_old}\"\n+  `git submodule deinit #{repo_old}`\n+  `git rm -rf #{repo_old}`\n+end\n+\n+log \"Registering new submodule: #{repo_new}\"\n+`git submodule add -f #{https} #{repo_new}`","path":"script/add-grammar","position":88,"original_position":88,"commit_id":"be316c29434b62c79aa989174986948ad02394fb","original_commit_id":"be316c29434b62c79aa989174986948ad02394fb","user":{"login":"pchaigno","id":1764210,"avatar_url":"https://avatars.githubusercontent.com/u/1764210?v=3","gravatar_id":"","url":"https://api.github.com/users/pchaigno","html_url":"https://github.com/pchaigno","followers_url":"https://api.github.com/users/pchaigno/followers","following_url":"https://api.github.com/users/pchaigno/following{/other_user}","gists_url":"https://api.github.com/users/pchaigno/gists{/gist_id}","starred_url":"https://api.github.com/users/pchaigno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pchaigno/subscriptions","organizations_url":"https://api.github.com/users/pchaigno/orgs","repos_url":"https://api.github.com/users/pchaigno/repos","events_url":"https://api.github.com/users/pchaigno/events{/privacy}","received_events_url":"https://api.github.com/users/pchaigno/received_events","type":"User","site_admin":false},"body":"We should check the output code here before continuing execution. If the directory already exists for instance, it will error out and add a second line in `grammars.yml` anyway (because the next line which runs whatever happens).","created_at":"2016-09-11T15:57:49Z","updated_at":"2016-09-11T15:57:49Z","html_url":"https://github.com/github/linguist/pull/3193#discussion_r78297573","pull_request_url":"https://api.github.com/repos/github/linguist/pulls/3193","_links":{"self":{"href":"https://api.github.com/repos/github/linguist/pulls/comments/78297573"},"html":{"href":"https://github.com/github/linguist/pull/3193#discussion_r78297573"},"pull_request":{"href":"https://api.github.com/repos/github/linguist/pulls/3193"}}},"pull_request":{"url":"https://api.github.com/repos/github/linguist/pulls/3193","id":84184690,"html_url":"https://github.com/github/linguist/pull/3193","diff_url":"https://github.com/github/linguist/pull/3193.diff","patch_url":"https://github.com/github/linguist/pull/3193.patch","issue_url":"https://api.github.com/repos/github/linguist/issues/3193","number":3193,"state":"open","locked":false,"title":"Add script to add or replace grammars","user":{"login":"Alhadis","id":2346707,"avatar_url":"https://avatars.githubusercontent.com/u/2346707?v=3","gravatar_id":"","url":"https://api.github.com/users/Alhadis","html_url":"https://github.com/Alhadis","followers_url":"https://api.github.com/users/Alhadis/followers","following_url":"https://api.github.com/users/Alhadis/following{/other_user}","gists_url":"https://api.github.com/users/Alhadis/gists{/gist_id}","starred_url":"https://api.github.com/users/Alhadis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alhadis/subscriptions","organizations_url":"https://api.github.com/users/Alhadis/orgs","repos_url":"https://api.github.com/users/Alhadis/repos","events_url":"https://api.github.com/users/Alhadis/events{/privacy}","received_events_url":"https://api.github.com/users/Alhadis/received_events","type":"User","site_admin":false},"body":"The current procedure for adding or replacing grammars is fiddly and error-prone, and definitely not contributor-friendly. So I wrote a script to automate the process:\r\n\r\n```bash\r\nscript/add-grammar https://github.com/JaneSmith/MyGrammar\r\nscript/add-grammar --replace old.tmbundle https://github.com/JaneSmith/NewBundle\r\n```\r\n\r\nThe script attempts to be idiot-proof: it accepts a variety of URL syntaxes, resolving them all to an HTTPS link:\r\n\r\n```bash\r\nscript/add-grammar https://Alhadis@bitbucket.org/Alhadis/language-roff\r\nscript/add-grammar git@github.com:Alhadis/language-roff.git\r\nscript/add-grammar Alhadis/language-roff\r\nscript/add-grammar http://github.com/Alhadis/language-roff.git\r\nscript/add-grammar github.com/Alhadis/language-roff.git\r\n```\r\n\r\nTo replace an existing grammar, the argument for `--replace` is the name of the unwanted submodule, without or without a leading `vendor/grammars/` attached:\r\n\r\n```bash\r\nscript/add-grammar --replace vendor/grammars/old.tmbundle\r\nscript/add-grammar --replace old.tmbundle\r\n```\r\nBoth resolve to the same thing. If the resolved name doesn't match a path in the `vendor/grammars` directory, it barks at the user and exits.\r\n","created_at":"2016-09-06T19:49:48Z","updated_at":"2016-09-11T15:57:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4d1820590c2ff3a1f44ff8e869126490dc574990","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/github/linguist/pulls/3193/commits","review_comments_url":"https://api.github.com/repos/github/linguist/pulls/3193/comments","review_comment_url":"https://api.github.com/repos/github/linguist/pulls/comments{/number}","comments_url":"https://api.github.com/repos/github/linguist/issues/3193/comments","statuses_url":"https://api.github.com/repos/github/linguist/statuses/be316c29434b62c79aa989174986948ad02394fb","head":{"label":"Alhadis:grammar-scripts","ref":"grammar-scripts","sha":"be316c29434b62c79aa989174986948ad02394fb","user":{"login":"Alhadis","id":2346707,"avatar_url":"https://avatars.githubusercontent.com/u/2346707?v=3","gravatar_id":"","url":"https://api.github.com/users/Alhadis","html_url":"https://github.com/Alhadis","followers_url":"https://api.github.com/users/Alhadis/followers","following_url":"https://api.github.com/users/Alhadis/following{/other_user}","gists_url":"https://api.github.com/users/Alhadis/gists{/gist_id}","starred_url":"https://api.github.com/users/Alhadis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alhadis/subscriptions","organizations_url":"https://api.github.com/users/Alhadis/orgs","repos_url":"https://api.github.com/users/Alhadis/repos","events_url":"https://api.github.com/users/Alhadis/events{/privacy}","received_events_url":"https://api.github.com/users/Alhadis/received_events","type":"User","site_admin":false},"repo":{"id":60364942,"name":"linguist","full_name":"Alhadis/linguist","owner":{"login":"Alhadis","id":2346707,"avatar_url":"https://avatars.githubusercontent.com/u/2346707?v=3","gravatar_id":"","url":"https://api.github.com/users/Alhadis","html_url":"https://github.com/Alhadis","followers_url":"https://api.github.com/users/Alhadis/followers","following_url":"https://api.github.com/users/Alhadis/following{/other_user}","gists_url":"https://api.github.com/users/Alhadis/gists{/gist_id}","starred_url":"https://api.github.com/users/Alhadis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Alhadis/subscriptions","organizations_url":"https://api.github.com/users/Alhadis/orgs","repos_url":"https://api.github.com/users/Alhadis/repos","events_url":"https://api.github.com/users/Alhadis/events{/privacy}","received_events_url":"https://api.github.com/users/Alhadis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Alhadis/linguist","description":"Hub of various pull requests submitted to GitHub's linguist.","fork":true,"url":"https://api.github.com/repos/Alhadis/linguist","forks_url":"https://api.github.com/repos/Alhadis/linguist/forks","keys_url":"https://api.github.com/repos/Alhadis/linguist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Alhadis/linguist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Alhadis/linguist/teams","hooks_url":"https://api.github.com/repos/Alhadis/linguist/hooks","issue_events_url":"https://api.github.com/repos/Alhadis/linguist/issues/events{/number}","events_url":"https://api.github.com/repos/Alhadis/linguist/events","assignees_url":"https://api.github.com/repos/Alhadis/linguist/assignees{/user}","branches_url":"https://api.github.com/repos/Alhadis/linguist/branches{/branch}","tags_url":"https://api.github.com/repos/Alhadis/linguist/tags","blobs_url":"https://api.github.com/repos/Alhadis/linguist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Alhadis/linguist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Alhadis/linguist/git/refs{/sha}","trees_url":"https://api.github.com/repos/Alhadis/linguist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Alhadis/linguist/statuses/{sha}","languages_url":"https://api.github.com/repos/Alhadis/linguist/languages","stargazers_url":"https://api.github.com/repos/Alhadis/linguist/stargazers","contributors_url":"https://api.github.com/repos/Alhadis/linguist/contributors","subscribers_url":"https://api.github.com/repos/Alhadis/linguist/subscribers","subscription_url":"https://api.github.com/repos/Alhadis/linguist/subscription","commits_url":"https://api.github.com/repos/Alhadis/linguist/commits{/sha}","git_commits_url":"https://api.github.com/repos/Alhadis/linguist/git/commits{/sha}","comments_url":"https://api.github.com/repos/Alhadis/linguist/comments{/number}","issue_comment_url":"https://api.github.com/repos/Alhadis/linguist/issues/comments{/number}","contents_url":"https://api.github.com/repos/Alhadis/linguist/contents/{+path}","compare_url":"https://api.github.com/repos/Alhadis/linguist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Alhadis/linguist/merges","archive_url":"https://api.github.com/repos/Alhadis/linguist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Alhadis/linguist/downloads","issues_url":"https://api.github.com/repos/Alhadis/linguist/issues{/number}","pulls_url":"https://api.github.com/repos/Alhadis/linguist/pulls{/number}","milestones_url":"https://api.github.com/repos/Alhadis/linguist/milestones{/number}","notifications_url":"https://api.github.com/repos/Alhadis/linguist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Alhadis/linguist/labels{/name}","releases_url":"https://api.github.com/repos/Alhadis/linguist/releases{/id}","deployments_url":"https://api.github.com/repos/Alhadis/linguist/deployments","created_at":"2016-06-03T17:16:52Z","updated_at":"2016-07-05T12:36:32Z","pushed_at":"2016-09-10T14:51:40Z","git_url":"git://github.com/Alhadis/linguist.git","ssh_url":"git@github.com:Alhadis/linguist.git","clone_url":"https://github.com/Alhadis/linguist.git","svn_url":"https://github.com/Alhadis/linguist","homepage":"https://github.com/github/linguist","size":32681,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"nah"}},"base":{"label":"github:master","ref":"master","sha":"04e1cc6d0afc74d90ab600d891ffd89c24afd3c8","user":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"repo":{"id":1725199,"name":"linguist","full_name":"github/linguist","owner":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/github/linguist","description":"Language Savant. If your repository's language is being reported incorrectly, send us a pull request!","fork":false,"url":"https://api.github.com/repos/github/linguist","forks_url":"https://api.github.com/repos/github/linguist/forks","keys_url":"https://api.github.com/repos/github/linguist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/github/linguist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/github/linguist/teams","hooks_url":"https://api.github.com/repos/github/linguist/hooks","issue_events_url":"https://api.github.com/repos/github/linguist/issues/events{/number}","events_url":"https://api.github.com/repos/github/linguist/events","assignees_url":"https://api.github.com/repos/github/linguist/assignees{/user}","branches_url":"https://api.github.com/repos/github/linguist/branches{/branch}","tags_url":"https://api.github.com/repos/github/linguist/tags","blobs_url":"https://api.github.com/repos/github/linguist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/github/linguist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/github/linguist/git/refs{/sha}","trees_url":"https://api.github.com/repos/github/linguist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/github/linguist/statuses/{sha}","languages_url":"https://api.github.com/repos/github/linguist/languages","stargazers_url":"https://api.github.com/repos/github/linguist/stargazers","contributors_url":"https://api.github.com/repos/github/linguist/contributors","subscribers_url":"https://api.github.com/repos/github/linguist/subscribers","subscription_url":"https://api.github.com/repos/github/linguist/subscription","commits_url":"https://api.github.com/repos/github/linguist/commits{/sha}","git_commits_url":"https://api.github.com/repos/github/linguist/git/commits{/sha}","comments_url":"https://api.github.com/repos/github/linguist/comments{/number}","issue_comment_url":"https://api.github.com/repos/github/linguist/issues/comments{/number}","contents_url":"https://api.github.com/repos/github/linguist/contents/{+path}","compare_url":"https://api.github.com/repos/github/linguist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/github/linguist/merges","archive_url":"https://api.github.com/repos/github/linguist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/github/linguist/downloads","issues_url":"https://api.github.com/repos/github/linguist/issues{/number}","pulls_url":"https://api.github.com/repos/github/linguist/pulls{/number}","milestones_url":"https://api.github.com/repos/github/linguist/milestones{/number}","notifications_url":"https://api.github.com/repos/github/linguist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/github/linguist/labels{/name}","releases_url":"https://api.github.com/repos/github/linguist/releases{/id}","deployments_url":"https://api.github.com/repos/github/linguist/deployments","created_at":"2011-05-09T22:53:13Z","updated_at":"2016-09-11T14:30:32Z","pushed_at":"2016-09-11T14:59:44Z","git_url":"git://github.com/github/linguist.git","ssh_url":"git@github.com:github/linguist.git","clone_url":"https://github.com/github/linguist.git","svn_url":"https://github.com/github/linguist","homepage":"","size":46691,"stargazers_count":4074,"watchers_count":4074,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1642,"mirror_url":null,"open_issues_count":102,"forks":1642,"open_issues":102,"watchers":4074,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/github/linguist/pulls/3193"},"html":{"href":"https://github.com/github/linguist/pull/3193"},"issue":{"href":"https://api.github.com/repos/github/linguist/issues/3193"},"comments":{"href":"https://api.github.com/repos/github/linguist/issues/3193/comments"},"review_comments":{"href":"https://api.github.com/repos/github/linguist/pulls/3193/comments"},"review_comment":{"href":"https://api.github.com/repos/github/linguist/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/github/linguist/pulls/3193/commits"},"statuses":{"href":"https://api.github.com/repos/github/linguist/statuses/be316c29434b62c79aa989174986948ad02394fb"}}}}
{"actor":{"display_login":"pchaigno"}}