Skip to content

Instantly share code, notes, and snippets.

@totten totten/0-intro.md Secret
Last active Jun 14, 2018

Embed
What would you like to do?
Example: Writing a personalized report on interesting changes

Let's say Alice is a developer in the Civi community. She has a few interests:

  • Her clients all do membership management. None of them do grants or mail blasts. When upgrading, she's particularly interested in patches that affect the membership and payment subsystems.
  • She maintains an extension which adds a highly-polished (and highly-opinionated) member signup form in Angular. She's generally interested in changes to APIv3 and the AngularJS libraries.

Whenever there's a new RC or new release or she prepares an upgrade, she'd like to see a list of changes that are relevant to her work. She could write a custom report -- a bash script which queries git for changes to particular files/folders/subsystems.

  cd "$SRC"
  show_header "All changes in CiviMember"
  show_report_by_subsystem Member

  cd "$SRC"
  show_header "All changes in payment processing"
  show_report_by_path CRM/Core/Payment* tests/phpunit/CRM/Core/Payment*

  cd "$SRC"
  show_header "All changes in APIv3 framework"
  show_report_by_path api Civi/API CRM/Utils/API

  cd "$SRC"
  show_header "All changes in AngularJS helper modules"
  show_report_by_path ang/crmUi* ang/crmUtil* Civi/Angular

  cd "$SRC/packages"
  show_header "All changes in HTML_QuickForm"
  show_report_by_path HTML/Quick*

which would output something like:

To make your own version:

  • Copy the raw version of the script below.
  • Save it to a file on your system.
  • Edit the function "show_my_full_report()" to taste.
  • Run the report (like the in the screenshot).
#!/bin/bash
## Generate Alice's report about interesting changes between version X and Y.
###############################################################################
## Main report definition
function show_my_full_report() {
show_header "Update git databases"
update_repos origin "$SRC" "$SRC/packages" "$SRC/drupal" "$SRC/WordPress" "$SRC/joomla"
cd "$SRC"
show_header "All changes in CiviMember"
show_report_by_subsystem Member
cd "$SRC"
show_header "All changes in payment processing"
show_report_by_path CRM/Core/Payment* tests/phpunit/CRM/Core/Payment*
cd "$SRC"
show_header "All changes in APIv3 framework"
show_report_by_path api Civi/API CRM/Utils/API
cd "$SRC"
show_header "All changes in AngularJS helper modules"
show_report_by_path ang/crmUi* ang/crmUtil* Civi/Angular
cd "$SRC/packages"
show_header "All changes in HTML_QuickForm"
show_report_by_path HTML/Quick*
}
###############################################################################
## Constants
## The FMT constants are color-codes to make the console output prettier.
FMT_H1=""
FMT_H2=""
FMT_RESET=""
# Note: We may not have up-to-date local branches for all the versions, so
# we automatically prefix version numbers (e.g. "origin/5.1" and "origin/5.2").
# If you prefer to report on tags (e.g. `5.1.0`), set this blank.
VERSION_PREFIX="origin/"
###############################################################################
## Utilities
## Show a simple header line -- start a new section of the report
function show_header() {
echo
echo ${FMT_H1}==================[ $1 ]==================${FMT_RESET}
}
## Show a log of changes in some folder(s). Include tips for drilling down.
##
## Usage: show_report_by_path <paths...>
## Ex: show_report_by_path api/v3 Civi/API
function show_report_by_path() {
echo
echo ${FMT_H2}## Files${FMT_RESET}
git diff --name-only "$RANGE" -- "$@" | cat
echo
echo ${FMT_H2}## Commits${FMT_RESET}
git log --oneline "$RANGE" -- "$@" | cat
echo
echo ${FMT_H2}## Want more info? Try one of these:${FMT_RESET}
echo
echo "cd \"$PWD\""
echo
echo "git diff \"$RANGE\" -- $@"
echo
echo "git log -p \"$RANGE\" -- $@"
echo
echo "gitk \"$RANGE\" -- $@"
}
## Show a log for a major subsystem, such as CiviMember or CiviMail or CiviContribute.
## These subsystems tend to follow a naming convention ("CRM/Foo", "templates/CRM/Foo", "xml/schema/Foo")
##
## Usage: show_report_by_subsystem <subsystem>
## Ex: show_report_by_subsystem Member
function show_report_by_subsystem() {
for SUBSYSTEM in "$@" ; do
show_report_by_path api/v3/${SUBSYSTEM}* CRM/${SUBSYSTEM} templates/CRM/${SUBSYSTEM} xml/schema/${SUBSYSTEM} tests/phpunit/CRM/${SUBSYSTEM} tests/phpunit/api/v3/${SUBSYSTEM}*
done
}
## Usage: update_repos <remote> <paths...>
## Ex: update_repos origin "$SRC" "$SRC/packages" "$SRC/drupal" "$SRC/WordPress" "$SRC/joomla"
function update_repos() {
local remote="$1"
shift
for REPO in "$@" ; do
if [ -d "$REPO" ]; then
pushd "$REPO" >> /dev/null
git fetch $remote
popd >> /dev/null
fi
done
}
###############################################################################
## Parse CLI options and run
if [ -z "$1" -o -z "$2" -o -z "$3" ]; then
echo "usage: bash upgrade-report.sh <source-path> <last-version> <new-version>"
echo "ex: bash upgrade-report.sh /var/www/sites/all/modules/civicrm 5.2 5.3"
exit 1
fi
SRC="$1"
RANGE="${VERSION_PREFIX}$2..${VERSION_PREFIX}$3"
show_my_full_report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.