Debian Codegraph @

gen-changelog.sh

raw symbols SCIP
1 # Requires Github CLI and `jq`
2 # Usage: `./gen-changelog.sh YYYY-mm-dd`
3 # Generates changelog entries for all PRs merged on or after the given date.
4 set -e
5
6 PULLS='[]'
7 CURSOR='null'
8
9 MIN_MERGED_AT=$(date --date="$1" +%s)
10
11 while true
12 do
13 # Use the GraphQL API to paginate merged pull requests.
14 # The REST API doesn't allow filtering only merged pull requests.
15 # We scan all merged pull requests from the beginning because it's not unheard of to have a very old PR finally get
16 # merged; e.g. #1081, merged a year and a half after it was opened.
17 if [ "$CURSOR" != "null" ];
18 then
19 PAGE=$(gh api graphql -f after="$CURSOR" -f query='query($after: String) {
20 repository(owner: "launchbadge", name: "sqlx") {
21 pullRequests(first:100,orderBy: {field:CREATED_AT, direction:ASC},states:MERGED, after: $after) {
22 nodes {
23 number
24 author { login }
25 title
26 url
27 mergedAt
28 }
29 pageInfo {
30 hasNextPage
31 endCursor
32 }
33 }
34 }
35 }');
36 else
37 PAGE=$(gh api graphql -f query='query {
38 repository(owner: "launchbadge", name: "sqlx") {
39 pullRequests(first:100,orderBy: {field:CREATED_AT, direction:ASC},states:MERGED) {
40 nodes {
41 number
42 author { login }
43 title
44 url
45 mergedAt
46 }
47 pageInfo {
48 hasNextPage
49 endCursor
50 }
51 }
52 }
53 }');
54 fi
55
56 CURSOR=$(echo "$PAGE" | jq -r '.data.repository.pullRequests.pageInfo.endCursor');
57
58 HAS_NEXT_PAGE=$(echo "$PAGE" | jq '.data.repository.pullRequests.pageInfo.hasNextPage');
59
60 PULLS=$(echo "$PAGE" | jq "$PULLS + (.data.repository.pullRequests.nodes | map(select(.mergedAt | fromdate >= $MIN_MERGED_AT)))");
61
62 # can't use `"$CURSOR" == 'null'` because the last page still gives a valid cursor
63 if ! $HAS_NEXT_PAGE; then break; fi;
64 done
65
66 COUNT=$(echo "$PULLS" | jq "length");
67
68 echo "Found $COUNT pull requests merged on or after $1\n"
69
70 if [ -z $COUNT ]; then exit 0; fi;
71
72 echo "Entries:"
73 echo "$PULLS" | jq -r 'map("* [[#\(.number)]]: \(.title) [[@\(.author.login)]]") | join("\n")'
74
75 echo "\nLinks:"
76 echo "$PULLS" | jq -r 'map("[#\(.number)]: \(.url)") | join("\n")'
77
78 echo "\nNew Authors:"
79 DUPE_AUTHORS=''
80
81 # Generate link entries for new authors at the end of the changelog.
82 echo "$PULLS" | jq -r '.[].author.login' | while read author; do
83 author_url="https://github.com/$author"
84 author_entry="[@$author]: $author_url"
85
86 # Check if the entry already exists in the changelog or in our list of new authors.
87 if grep -qF "$author_entry" CHANGELOG.md || echo "$DUPE_AUTHORS" | grep -qF "$author_entry";
88 then continue;
89 fi;
90
91 DUPE_AUTHORS="$DUPE_AUTHORS$author_entry\n"
92 echo $author_entry
93 done