github.com/arkadijs/deis@v1.5.1/contrib/util/generate-changelog.sh (about)

     1  #!/usr/bin/env bash
     2  # vim: et tw=0 sw=4 ts=4
     3  
     4  usage() {
     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
    12  }
    13  
    14  # Print the information scraped from git
    15  retrieve() {
    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
    29  }
    30  
    31  # Wrap feature type and show its relevant commits
    32  subheading() {
    33      echo "#### $1"
    34      echo
    35      retrieve "$2"
    36      echo
    37  }
    38  
    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="https://github.com/deis/deis"
    44      fi
    45  
    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
    60  
    61      FROM=$1
    62      TO=${2:-"HEAD"}
    63  
    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