Last active
October 14, 2015 04:56
-
-
Save thejspr/d2eaa484376c338a22ff to your computer and use it in GitHub Desktop.
Checkout branch named after title of a Github issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'json' | |
token = ENV['GITHUB_TOKEN'] | |
issue_id = ARGV.first | |
# get org and repo | |
repo_url = `git config --get remote.origin.url`.strip | |
repo = /([\w,-]*\/.*)\.git/.match(repo_url)[1] | |
unless token || issue_id || repo | |
puts "Missing parameter. Known values: issue-id=#{issue_id.inspect} repo=#{repo.inspect} token=#{token.inspect}" | |
exit(1) | |
end | |
# fetch issue details | |
uri = URI.parse("https://api.github.com/repos/#{repo}/issues/#{issue_id}?access_token=#{token}") | |
json = Net::HTTP.get(uri) | |
response = JSON.parse(json) | |
title = response['title'] | |
.downcase | |
.gsub(/[^0-9A-Za-z\s]/, '') # remove special characters | |
.gsub(' ', '-').strip # replace whitespace with dash | |
# checkout branch | |
system "git checkout -b #{title}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Requires a github token in env as
GITHUB_TOKEN
. Create one here https://github.com/settings/tokens/new