| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Interactively generates a changelog over a range of commits: |
| 4 | |
| 5 | commit_summary() { |
| 6 | local hash="$1" |
| 7 | |
| 8 | pr=$(git show $hash | grep -o "#\([0-9]*\)" | cut -c 2-) |
| 9 | prjson="$(curl -n https://api.github.com/repos/git-lfs/git-lfs/pulls/$pr 2>/dev/null)" |
| 10 | title="$(echo $prjson | jq -r -e ".title")" |
| 11 | id="$(echo $prjson | jq -r -e ".number")" |
| 12 | author="$(echo $prjson | jq -r -e ".user.login")" |
| 13 | |
| 14 | # If the title begins with "Backport", then strip everything until the actual |
| 15 | # pull-request title. |
| 16 | if grep -q "Backport" <(echo $title); then |
| 17 | title="$(echo $title | sed 's/^[^:]*: //g')" |
| 18 | fi |
| 19 | |
| 20 | echo "* $title #$id (@$author)" |
| 21 | } |
| 22 | |
| 23 | revisions_in () { |
| 24 | if [ "$patch" -eq 1 ]; then |
| 25 | git rev-list --first-parent "$1" |
| 26 | else |
| 27 | git rev-list --merges --first-parent "$1" |
| 28 | fi |
| 29 | } |
| 30 | |
| 31 | noninteractive () { |
| 32 | local range="$1" |
| 33 | |
| 34 | printf '### Uncategorized\n' |
| 35 | for rev in $(revisions_in "$range"); do |
| 36 | commit_summary $rev |
| 37 | done |
| 38 | cat <<-EOF |
| 39 | |
| 40 | ### Features |
| 41 | |
| 42 | ### Bugs |
| 43 | |
| 44 | ### Misc |
| 45 | EOF |
| 46 | } |
| 47 | |
| 48 | if [ "$1" = "--noninteractive" ]; then |
| 49 | noninteractive=1 |
| 50 | shift |
| 51 | fi |
| 52 | |
| 53 | if [ "$1" = "--patch" ]; then |
| 54 | patch=1 |
| 55 | shift |
| 56 | else |
| 57 | patch=0 |
| 58 | fi |
| 59 | |
| 60 | range="$1" |
| 61 | |
| 62 | if [ "$range" = "" ]; then |
| 63 | echo "Usage: $0 [options] base..next" |
| 64 | exit 1 |
| 65 | fi |
| 66 | |
| 67 | if [ -n "$noninteractive" ] |
| 68 | then |
| 69 | noninteractive "$range" |
| 70 | exit |
| 71 | fi |
| 72 | |
| 73 | features="" |
| 74 | bugs="" |
| 75 | misc="" |
| 76 | |
| 77 | for rev in $(revisions_in "$range"); do |
| 78 | git show -s $rev |
| 79 | |
| 80 | processed=0 |
| 81 | while [ $processed -eq 0 ]; do |
| 82 | echo "Categorize this change: [f,b,m,s,?] ?" |
| 83 | read -n 1 opt |
| 84 | echo "" |
| 85 | |
| 86 | case $opt in |
| 87 | [fbms]) |
| 88 | processed=1 |
| 89 | ;; |
| 90 | ?) |
| 91 | echo "f - mark this merge as a feature" |
| 92 | echo "b - mark this merge as a bugfix" |
| 93 | echo "m - make this merge as a misc. change" |
| 94 | echo "s - skip this merge, excluding it from the changelog" |
| 95 | echo "? - display this help message" |
| 96 | ;; |
| 97 | *) |
| 98 | echo "Unknown option: $opt, try again." |
| 99 | ;; |
| 100 | esac |
| 101 | done |
| 102 | |
| 103 | if [ $opt != "s" ]; then |
| 104 | summary="$(commit_summary $rev)" |
| 105 | fi |
| 106 | |
| 107 | case $opt in |
| 108 | f) |
| 109 | features="$(printf "%s\n%s\n" "$features" "$summary")" |
| 110 | ;; |
| 111 | b) |
| 112 | bugs="$(printf "%s\n%s\n" "$bugs" "$summary")" |
| 113 | ;; |
| 114 | m) |
| 115 | misc="$(printf "%s\n%s\n" "$misc" "$summary")" |
| 116 | ;; |
| 117 | esac |
| 118 | done |
| 119 | |
| 120 | echo "" >&2 |
| 121 | |
| 122 | cat <<- EOF |
| 123 | ### Features |
| 124 | $features |
| 125 | |
| 126 | ### Bugs |
| 127 | $bugs |
| 128 | |
| 129 | ### Misc |
| 130 | $misc |
| 131 | EOF |