Last active
December 20, 2016 01:29
-
-
Save liubin/97cf88ebc474696332a68ee0a09d9004 to your computer and use it in GitHub Desktop.
git commit messages to bearychat
This file contains hidden or 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
| #!/bin/bash | |
| # How to use: | |
| # export ENV_BEARYCHAT_URL=YOUR_BEARYCHAT_CHANNEL | |
| # $ cp thisfile .git/hook/post-commit | |
| commitid=$(git log -1 --pretty=format:"%h" --branches) | |
| commitmessage=$(git log -1 --pretty=format:"%s" --branches) | |
| committer=$(git log -1 --pretty=format:"%an" --branches) | |
| var=`python - <<EOF | |
| import xml.etree.ElementTree as ET | |
| import requests | |
| import random | |
| import re | |
| import sys | |
| reload(sys) | |
| sys.setdefaultencoding('utf8') | |
| url='https://www.pinterest.com/liubin/git-messages.rss' | |
| r = requests.get(url) | |
| root = ET.fromstring(r.text.encode('utf-8')) | |
| items = root.findall('.//item') | |
| i = random.randint(1, len(items)-1) | |
| item = items[i] | |
| title = item.find('.//title').text | |
| desc = item.find('.//description').text | |
| match = re.search(r'(src="(.*?)")', desc) | |
| desc = match.groups()[1] | |
| print title + ';' + desc | |
| EOF` | |
| IFS=';' read title img <<< "$var" | |
| if [ -z "$title" ]; then | |
| title="好好学习,天天向上" | |
| fi | |
| if [ -z "$img" ]; then | |
| img="http://r2.ykimg.com/05410408528523AC6A0A4E4BBC9F221B" | |
| fi | |
| payload="payload={ | |
| \"text\": \"${title}\", | |
| \"attachments\": [ | |
| { | |
| \"pretext\": \"git pull\", | |
| \"title\": \"${committer}\", | |
| \"text\": \"${commitid} - ${commitmessage}\", | |
| \"images\": [{\"url\":\"${img}\"}] | |
| } | |
| ] | |
| }" | |
| curl -X POST --data-urlencode "${payload}" "${ENV_BEARYCHAT_URL}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment