|
1 | | -#!/bin/sh |
| 1 | +#!/bin/bash |
| 2 | +# vim: et tw=0 sw=4 ts=4 |
2 | 3 |
|
3 | 4 | usage() { |
4 | 5 | echo "Usage: $0 <from> [to]" |
| 6 | + echo "The REPOROOT and TYPES variables may be used to customize" |
| 7 | + echo "what is scraped from the commit logs. Current settings are:" |
| 8 | + echo |
| 9 | + echo " REPOROOT = $REPOROOT" |
| 10 | + echo " TYPES = $TYPES" |
| 11 | + echo |
5 | 12 | } |
6 | 13 |
|
| 14 | +# Print the information scraped from git |
7 | 15 | retrieve() { |
8 | | - git --no-pager log --oneline --no-merges --grep="$1" $FROM..$TO |
| 16 | + while read commit hash message |
| 17 | + do |
| 18 | + # Extract the subsystem where type(subsystem): message |
| 19 | + SUBSYSTEM=$(echo $message | cut -d'(' -f2 | cut -d')' -f1 | sed 's/\*/\(all\)/g') |
| 20 | + # Extract the message where type(subsystem): message |
| 21 | + MESSAGE=$(echo $message | awk -F ")" '{ print $2}' | sed 's/://' | cut -f2- -d' ') |
| 22 | + # Generate a link to the full legal commit on GitHub |
| 23 | + LINK="$REPOROOT/commit/$hash" |
| 24 | + # Echo all this in a way that makes the commit hash and message a link |
| 25 | + # to the commit in markdown |
| 26 | + echo ' -' "[\`$commit\`]($LINK)" "$SUBSYSTEM": "$MESSAGE" |
| 27 | + done < <(git --no-pager log --oneline --no-merges --oneline --format="%h %H %s" --grep="$1" "$FROM".."$TO") |
| 28 | + # Scrape the information from git |
9 | 29 | } |
10 | 30 |
|
| 31 | +# Wrap feature type and show its relevant commits |
11 | 32 | subheading() { |
12 | | - echo "#### $1\n" |
| 33 | + echo "#### $1" |
| 34 | + echo |
13 | 35 | retrieve "$2" |
14 | 36 | echo |
15 | 37 | } |
16 | 38 |
|
17 | | -FROM=$1 |
18 | | -TO=${2:-"HEAD"} |
| 39 | +main() { |
| 40 | + # if REPOROOT is already in the environment, don't overload it and use that |
| 41 | + if [ -z "$REPOROOT" ]; |
| 42 | + then |
| 43 | + REPOROOT="http://github.com/deis/deis" |
| 44 | + fi |
19 | 45 |
|
20 | | -if [ -z $1 ]; |
21 | | -then |
22 | | - usage |
23 | | - exit 1 |
24 | | -fi |
| 46 | + # if TYPES is already in the environment, don't overload it and use that |
| 47 | + if [ -z "$TYPES" ]; |
| 48 | + then |
| 49 | + # Based on https://github.com/deis/deis/blob/master/CONTRIBUTING.md |
| 50 | + # The format is in the form of $shortname;$longname $shortname;longname. |
| 51 | + TYPES="feat(;Features fix(;Fixes docs(;Documentation chore(;Maintenance" |
| 52 | + fi |
| 53 | + |
| 54 | + # Print usage summary if user didn't specify a beginning |
| 55 | + if [ -z "$1" ]; |
| 56 | + then |
| 57 | + usage |
| 58 | + exit 1 |
| 59 | + fi |
25 | 60 |
|
26 | | -echo "### $FROM -> $TO\n" |
| 61 | + FROM=$1 |
| 62 | + TO=${2:-"HEAD"} |
27 | 63 |
|
28 | | -subheading "Features" "feat(" |
29 | | -subheading "Fixes" "fix(" |
30 | | -subheading "Documentation" "docs(" |
| 64 | + printf "### $FROM -> $TO \n\n" |
| 65 | + |
| 66 | + # Iterate over the types of messages specified |
| 67 | + for LEGALTYPE in $TYPES |
| 68 | + do |
| 69 | + SHORT=$(echo "$LEGALTYPE" | cut -f1 -d';') |
| 70 | + LONG=$(echo "$LEGALTYPE" | cut -f2 -d';') |
| 71 | + |
| 72 | + subheading $LONG $SHORT |
| 73 | + done |
| 74 | +} |
| 75 | + |
| 76 | +if (( $SHLVL == 2 )) |
| 77 | +then |
| 78 | + # If this is being run as a command |
| 79 | + main $* |
| 80 | + exit |
| 81 | +else |
| 82 | + # Otherwise this is being sourced |
| 83 | + unset -f main |
| 84 | + unset -f usage |
| 85 | +fi |
0 commit comments