UNPKG

1.76 kBapplication/x-shView Raw
1#!/bin/bash
2#
3# Generate a Markdown-formatted changelog from merge commits.
4#
5
6set -o errexit
7
8#
9# Regex to match the standard pull request commit message. Creates capture
10# groups for pull request number, GitHub username, and commit message body.
11#
12MERGE_RE=Merge\ pull\ request\ #\([0-9]+\)\ from\ \([^/]+\)\/[^\ ]+\ \(.*\)
13
14#
15# Regex to match the squash commit message. Creates capture groups for git
16# author, commit subject and pull request number.
17#
18SQUASH_RE='([^\|]+)\|([^\(]+) \(#([0-9]+)\)'
19
20GITHUB_URL=https://github.com
21PULLS_URL=${GITHUB_URL}/openlayers/openlayers/pull
22
23display_usage() {
24 cat <<-EOF
25
26 Usage: ${1} <revision range>
27
28 Creates a Markdown-formatted changelog given a revision range.
29
30 E.g.
31 ${1} v3.0.0.. > changelog/v3.1.0.md
32
33 See git-log(1) for details on the revision range syntax.
34
35EOF
36}
37
38#
39# Scan the git log for merge commit messages and output Markdown. This only
40# follows the first parent of merge commits to avoid merges within a topic
41# branch (instead only showing merges to master).
42#
43main() {
44 git log --first-parent --format='%aN|%s %b' ${1} |
45 {
46 while read l; do
47 if [[ ${l} =~ ${MERGE_RE} ]] ; then
48 number="${BASH_REMATCH[1]}"
49 author="${BASH_REMATCH[2]}"
50 summary="${BASH_REMATCH[3]}"
51 echo " * [#${number}](${PULLS_URL}/${number}) - ${summary} ([@${author}](${GITHUB_URL}/${author}))"
52 elif [[ ${l} =~ ${SQUASH_RE} ]] ; then
53 number="${BASH_REMATCH[3]}"
54 author="${BASH_REMATCH[1]}"
55 summary="${BASH_REMATCH[2]}"
56 echo " * [#${number}](${PULLS_URL}/${number}) - ${summary} ([${author}](${GITHUB_URL}/search?q=${author}&type=Users))"
57 fi
58 done
59 }
60}
61
62if test ${#} -ne 1; then
63 display_usage ${0}
64 exit 1
65else
66 main ${1}
67fi