Skip to content

Instantly share code, notes, and snippets.

@hata6502
Last active May 21, 2022 09:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hata6502/d3bb634ec9beb9443a040c90733284bd to your computer and use it in GitHub Desktop.
Save hata6502/d3bb634ec9beb9443a040c90733284bd to your computer and use it in GitHub Desktop.
git push して Twitter に通知します。
#!/bin/bash
url=`git config --get remote.origin.url`
domain=${url#*@}
domain=${domain#https://}
domain=${domain/:/}
branch=`git rev-parse --abbrev-ref HEAD`
tweet=""
if git rev-parse --verify origin/${branch} >/dev/null 2>&1
then
remote=${branch}
else
remote=HEAD
fi
tweet="${tweet}https://${domain}/compare/`git rev-parse --short origin/${remote}`...`git rev-parse --short ${branch}`\n"
tweet="${tweet}`basename ${url}`/${branch} を更新しました。\n"
log=`git log --pretty=format:"・%s\n" origin/${remote}..${branch}`
tweet="${tweet}${log}"
if git push $@
then
echo -e ${tweet} | tweet
fi
@hata6502
Copy link
Author

hata6502 commented Mar 16, 2019

・環境要件
tweet コマンドをインストールする必要があります。
https://github.com/Hato6502/tweet

・インストール
/usr/local/bin などに直接配置します。

・使用例

$ git commit -m "This is gitwitter test. "
$ gitwitter

・その他
push 先の URL などによって正常動作しない場合や、ツイート内容の調整をする場合は gitweet シェルスクリプトを直接改変します。
引数を指定すると、そのまま git push の引数になります。

@hata6502
Copy link
Author

スクリプトを「git-twitter」として保存することで、gitwitterではなくgit twitterとしてコマンドを実行可能です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment