-
Notifications
You must be signed in to change notification settings - Fork 729
Add Changelog script #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add Changelog script #695
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
472f8ca
Add Changelog script
PatOConnor43 c5cbdb2
Allow specifying token based on arg or env var
PatOConnor43 e88885a
Eval the command. Whoops
PatOConnor43 a96faba
Merge branch 'master' of github.com:sendgrid/sendgrid-python into Cha…
PatOConnor43 a1fc8c7
Change if-statements and catch errors
PatOConnor43 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| # default arguments | ||
| host="https://github.com" | ||
| api_host="https://api.github.com" | ||
| origin="sendgrid" | ||
| repo="sendgrid-python" | ||
| authorization_token="" | ||
|
|
||
| # helpers | ||
| usage() { | ||
| cat << EOF | ||
| Usage: | ||
| generate_changelog [-h] | ||
| generate_changelog [-t] | ||
| generate_changelog [-v] | ||
|
|
||
| Options: | ||
| -h Print usage information | ||
| -t Specify a token to authenticate with the api that gets PR titles | ||
| May also set the AUTHORIZATION_TOKEN environment variable | ||
| -v Specify the new version number | ||
| EOF | ||
| } | ||
|
|
||
| create_changelog() { | ||
|
|
||
| content="" | ||
| # Get merge commits | ||
| merges="$(git log ${latest_release}..HEAD --merges --format="* %s (%h)" --grep="^Merge pull request #" | cut -d "#" -f2 | cut -d " " -f1)" | ||
| for pr in $merges; do | ||
| echo "Getting title of PR #$pr" | ||
| url="$host/$origin/$repo/pull/$pr" | ||
| api_url="$api_host/repos/$origin/$repo/pulls/$pr" | ||
| curl_command="curl -s $api_url" | ||
| if [ -n "$authorization_token" ] | ||
| then | ||
| curl_command="$curl_command -H \"Authorization: token $authorization_token\"" | ||
| fi | ||
| title=$(eval $curl_command | grep '"title": ' | cut -d '"' -f4) | ||
| content="$content- [PR #$pr]($url): $title\n" | ||
| done | ||
|
|
||
| # Output changelog | ||
| echo | awk -v v_header1="## [$version] - $(date +'%Y')-$(date +'%m')-$(date +'%d') ##" \ | ||
| -v v_header2="### Added" \ | ||
| -v v_content="$content" \ | ||
| '/All notable changes to this project will be documented in this file/{print;print v_header1;print v_header2;print v_content;next}1' CHANGELOG.md \ | ||
| > CHANGELOG.md.temp | ||
| mv -f CHANGELOG.md.temp CHANGELOG.md | ||
| } | ||
|
|
||
|
|
||
| # script | ||
|
|
||
| # Exit if not in a Git repository. | ||
| if [ "true" != "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ] | ||
| then | ||
| echo -e "This does not seem to be a Git repository.\n" | ||
| exit | ||
| fi | ||
|
|
||
| # Parse all options | ||
| while [ "$1" != "" ]; do | ||
| case $1 in | ||
| -h | --help ) usage | ||
| exit | ||
| ;; | ||
| -t | --token ) shift | ||
| authorization_token=$1 | ||
| ;; | ||
| -v | --version ) shift | ||
| version=$1 | ||
| ;; | ||
| * ) usage | ||
| exit 1 | ||
| esac | ||
| shift | ||
| done | ||
|
|
||
| # Validate options | ||
| if [ -z "$version" ] | ||
| then | ||
| echo "Must supply a version with -v" | ||
| exit 1 | ||
| fi | ||
| if [ -z "$authorization_token" ] | ||
| then | ||
| authorization_token="$AUTHORIZATION_TOKEN" | ||
| fi | ||
|
|
||
| # Generate changelog from last tag | ||
| latest_release="$(git describe --tags --abbrev=0)" | ||
| create_changelog | ||
| echo "Successfully wrote to CHANGELOG.md" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
create_changelogfails for some reason, it would be nice to display an error message, instead of "success" regardless of the outcome.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a
set -eat the top of the file. I think this should halt the script and print the expected error message. Does that work for you?