Created
May 6, 2012 13:22
-
-
Save sergeylukin/2622308 to your computer and use it in GitHub Desktop.
Git hook: Export pushed commit to RSS FEED
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
<?xml version="1.0" encoding="UTF-8"?> | |
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xml:lang="en"> | |
<title type="text">Git push feed</title> | |
</feed> |
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/sh | |
# | |
# This script adds every pushed commit info to XML file | |
# Make sure to place it in your bare repo's /hooks dir and make it executable | |
# | |
git update-server-info | |
FILE=/path/to/feed.xml | |
# Get diapasone of pushed commits | |
while read oldrev newrev refname | |
do | |
# Loop over pushed commits and concatenate XML data into $commits variable | |
commits=$(git log $oldrev~..$newrev --pretty=format:'%h|%an|%s|%at' | | |
while IFS='|' read hash author message timestamp | |
do | |
date=`date -d @$timestamp +%Y-%m-%dT%H:%M:%SZ` | |
echo "\<entry\>\n\ | |
\<author\>\<name\>$author\<\/name\>\<\/author\>\n\ | |
\<title\>$message\<\/title\>\n\ | |
\<published\>$date\<\/published\>\n\ | |
\<summary type=\"html\"\>\n\ | |
\<![CDATA[\n\ | |
]]\>\n\ | |
\<\/summary\>\n\ | |
\<\/entry\>" | |
done) | |
# Add $commits variable value after 3rd line in XML file | |
sed -i "3 a $(echo $commits)" $FILE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment