Skip to content

Instantly share code, notes, and snippets.

@markhalliwell
Last active December 22, 2015 12:29
Show Gist options
  • Select an option

  • Save markhalliwell/6473218 to your computer and use it in GitHub Desktop.

Select an option

Save markhalliwell/6473218 to your computer and use it in GitHub Desktop.
Drupal project post commit (copies thanks and commit link to pasteboard). Follow instructions at https://coderwall.com/p/jp7d5q
#!/bin/sh
# Ensure repo is hosted on drupal.org.
repoRemote=`git remote -v | grep push | perl -lne 'print $& if /git\.drupal\.org[:\/]project\/[^.]*/'`;
if [ ! -z "${repoRemote}" ]; then
# Extract the project and commit info.
project=`echo "${repoRemote}" | sed -e 's/git\.drupal\.org[:\/]//'`;
commitHash=`git log -n 1 --pretty=format:"%h"`;
commitName=`git log -n 1 --pretty=format:"%cn"`;
commitMessage=`git log -n 1 --pretty=format:"%B"`;
authorName=`git log -n 1 --pretty=format:"%an"`;
if [ "${commitName}" != "${authorName}" ]; then
authorName="Thanks @${authorName}!\n\n";
else
authorName='';
fi
upstreamBranch="$(git rev-parse --symbolic-full-name --abbrev-ref @{u} | cut -d '/' -f2)";
if [[ ! -z "${upstreamBranch}" ]]; then
upstreamBranch=" to <a href=\"http://drupalcode.org/${project}.git/shortlog/refs/heads/${upstreamBranch}\">${upstreamBranch}</a>";
fi
printf "${authorName}Committed <a href=\"http://drupalcode.org/${project}.git/commitdiff/$commitHash\">${commitHash}</a>${upstreamBranch}:\n<blockquote>\n${commitMessage}\n</blockquote>" | pbcopy;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment