Skip to content

Instantly share code, notes, and snippets.

@gouf
Created Dec 2, 2017
Embed
What would you like to do?
「今日のローカルでの作業(コミット)」を、GitHub Compare URL 形式に加工する(※コミットは要 push)
#!/home/gouf/.anyenv/envs/rbenv/shims/ruby
# vim: ft=ruby
Dir.chdir(Dir.pwd)
#
# リポジトリ/ユーザ名の抽出
#
origin = %x(git remote -v)
user_name_and_repository_name = %r{([^:/]+)/([^/]+)\(.+\)$}
user_name, repository_name =
origin.match(user_name_and_repository_name)
.captures
.map { |x| x.strip.gsub('.git', '') }
#
# 今日のローカルでのコミットを抽出
#
# Ref: https://coderwall.com/p/7jbwww/git-today-quickly-see-what-you-ve-done-today
todays_commit = %x(git log --reverse --no-merges --branches=* --date=local --since=midnight --oneline --author="$(git config --get user.name)"|(head -n 1;tail -n 1))
commit_a, commit_b = todays_commit.lines.map { |x| x.match(/^\w+/) }
puts %W[
https://github.com/
#{user_name}/
#{repository_name}/
compare/
#{commit_a}...#{commit_b}
].join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment