Git因其鼓励的提交邮件标题长度限制而臭名昭着:第一行不应超过50个字符(适合电子邮件标题).
这让我想起......好吧,是否有一个钩子会在推送到服务器后自动将提交消息发布到Twitter?
Jör*_*tag 14
干得好:
#!/bin/sh
username=<your Twitter account>
password=<your Twitter password>
service_uri=http://api.twitter.com/1/statuses/update.json
subject=`git log --pretty=format:%s -n1`
curl -u "${username}:${password}" -d status="${subject}" $service_uri
Run Code Online (Sandbox Code Playgroud)
保存.git/hooks/post-commit在您的存储库中并使其可执行.
[注意:完全没有经过测试,我刚刚在现场做了这个.]
我设置了一个Git提交后钩子,每次我在开发存储库中进行本地提交时,该钩子都会发布到我的私有Twitter帐户中。这是我所做的:
make和make install)。确保可以从中访问它PATH。PATH。最后,将以下脚本保存到Git存储库中的.git / hooks / post-commit中。
#!/bin/sh
# PATH modification needed for http_post and oauth_sign
export PATH=$PATH:/usr/local/bin
toplevel_path=`git rev-parse --show-toplevel`
toplevel_dir=`basename "$toplevel_path"`
branch=`git rev-parse --abbrev-ref HEAD`
subject=`git log --pretty=format:%s -n1`
hashtags="#code #$toplevel_dir"
tweet=$hashtags' ['$branch']: "'$subject'"'
# truncate tweets that are longer than 140 characters
if [ ${#tweet} -gt 140 ]
then
tweet_trunc=$(echo $tweet | cut -c1-137)
tweet=${tweet_trunc}...
fi
consumer_key="<Put your computer key here>"
consumer_secret="<Put your consumer secret here>"
access_token="<Put your access token here>"
access_secret="<Put your access token secret here>"
url="https://api.twitter.com/1.1/statuses/update.json"
http_post -h Authorization "$(oauth_sign \
$consumer_key $consumer_secret \
$access_token $access_secret \
POST "$url" status="$tweet")" \
"$url" status="$tweet"
Run Code Online (Sandbox Code Playgroud)确保使文件可执行。(chmod a+x .git/hooks/post-commit)
注意:所有这些都很大程度上基于此脚本:http : //fanf.livejournal.com/108436.html
祝好运!
- 大卫