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:

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`
if [ ! -d "js" ] 
  mkdir "js"
/usr/bin/wget -O ${JS_OUTPUT}
/usr/bin/python -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" ]                            
  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

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

1 comment:

  1. BlueHost is ultimately one of the best hosting provider with plans for all of your hosting needs.