Skip to content

Instantly share code, notes, and snippets.

@grahamc
Last active June 7, 2017 10:53
Show Gist options
  • Save grahamc/337e8874a8d63ffbd40ae20ea30d3ccd to your computer and use it in GitHub Desktop.
Save grahamc/337e8874a8d63ffbd40ae20ea30d3ccd to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eux
dbg() {
echo "$@" >&2
}
readonly CHAN="#christensen-test"
readonly URL="https://channels.nix.gsc.io"
readonly remote="origin"
readonly gitrepo="$1"
readonly dest="$2"
(
cd "$gitrepo" >&2
git fetch "$remote" >&2
git for-each-ref --format '%(refname:strip=3)' \
"refs/remotes/$remote"
) | grep -v HEAD |
(
cd "$dest"
touch summary
echo -n "" > summary
summary="$(pwd)/summary"
while read -r branch; do
name=$(echo "$branch" | sed -e "s#/#_#g" -e "s#\.\.#_#g")
mkdir -p "$name"
(
cd "$name"
touch latest
(
cd "$gitrepo" >&2
git show -s --format="%H %at" "$remote/$branch"
) > latest.next
if [ "$(md5sum < latest.next)" != "$(md5sum < latest)" ]; then
dbg "Change in ${branch}"
(
cd "$gitrepo" >&2
echo -n "Channel $branch advanced to "
git show -s --format="https://github.com/NixOS/nixpkgs/commit/%H (from %cr, history: $URL/$name/history)" "$remote/$branch"
) >> "$summary"
mv latest.next latest
chmod a+r latest
touch history
(
cat history
cat latest
) | tail -n10000 > history.next
mv history.next history
chmod a+r history
else
dbg "No change in ${branch}"
rm latest.next
fi
)
done
if [ $(wc -l "$summary" | cut -d' ' -f1) -gt 0 ]; then
(
sleep 5
echo 'NICK testbot'
sleep 2
echo 'USER testbot 0 * :testbot'
sleep 2
echo "JOIN :$CHAN"
sleep 10
cat "$summary" | sed -e "s/^/NOTICE $CHAN :/"
sleep 3
echo "QUIT :Info at $URL"
sleep 5
) | telnet irc.freenode.net 6667 || true
fi
rm -f summary
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment