Thursday, June 23, 2011

Daily snapshots of Facebook Connect Library

Nathan Friedly from Sociable Labs put together a set of utils to grab daily snapshots of Facebook's connect.js here:

https://github.com/nfriedly/connect-js

One thing you can do to keep yourself informed of changes that Facebook makes is to fork the repo, git clone the repo to your dev server, install the crontab script, and put a GitHub post-receive email hook to notify you of all changes.  Then the changes made by Facebook can more quickly diagnosed by developers like you!



Often times Facebook only updates the Unix timestamp on the file, so here is a revised version of the script to only download/update the all_deminified.js file if there is more than one line of change made.
#!/bin/bash  -ex
cd `dirname $0`
TODAY=`date --rfc-3339=date`
JS_OUTPUT="js/all_${TODAY}.js"
if [ ! -d "js" ] 
then
  mkdir "js"
fi
/usr/bin/wget https://connect.facebook.net/en_US/all.js -O ${JS_OUTPUT}
/usr/bin/python jsbeautifier.py -o all_deminified.js ${JS_OUTPUT}
# Avoid sending out unnecessary updates if only the timestamp has changed.
ALL_JS_DIFF=`git diff --shortstat all_deminified.js | grep -v "1 insertions"`
if [ ! -z "$ALL_JS_DIFF" ]                            
then                                                  
  echo "Commit has changed..."                        
  git --no-pager diff . # Just to see what changed...turn off the pager.
  /usr/bin/git add all_deminified.js
  /usr/bin/git commit -m "Facebook Connect changes for $TODAY"
  /usr/bin/git push origin
fi                     

Since the GitHub post-receive hook does not provide nice friendly diffs, we can also add a post-commit hook in our local repository and use the Ruby git-commit notifier to notify us whenever a change has been made. This script dumps out last two revisions made in the commit(older to newer revision first). Since the git-commit-notifier will only trigger if there is something more than the timestamp, we should expect diff emails only when there is a more substantial change made in the Facebook JavaScript. You have to setup your own git-commit-notifier.yml and point it to an SMTP host (it apparently does not work with Gmail hosts since STARTTLS may be required).

vi .git/hooks/post-commit
#!/bin/bash -ex
HASH_DIFF=`git log --pretty=%H --reverse | tail -2 | xargs echo`
git-commit-notifier /home/rhu/fb/connect-js/git-commit-notifier.yml ${HASH_DIFF} refs/heads/master

No comments:

Post a Comment