Skip to content

Commit

Permalink
Improve suffix handling
Browse files Browse the repository at this point in the history
* chore: improve repo layout

* test: add "&" to symbols test

* feat: change suffix handling

* fix: use separate commit for `change all`

* style: move function

* docs: update changelog
  • Loading branch information
adamtabrams authored Jan 27, 2021
1 parent 7ed5be3 commit 0273c21
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ideas.txt
ideas.md

**/actual/**
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.11.0] - 2021-01-27
### Added
- Suffixes are now shown in changelog versions.
- Automated version tags won't use suffixes.

### Fixed
- Use separate commit for `change all` instead of appending to previous commit.

### Changed
- Move function.
- Add "&" to symbols test.
- Improve repo layout.

## [0.10.0] - 2021-01-21
### Added
- Add --dry-run flag to `change post` to see the release without making it.
Expand Down Expand Up @@ -119,7 +132,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Created a proof of concept for a changelog updater.

[Unreleased]: https://github.com/adamtabrams/change/compare/0.10.0...HEAD
[Unreleased]: https://github.com/adamtabrams/change/compare/0.11.0...HEAD
[0.11.0]: https://github.com/adamtabrams/change/compare/0.10.0...0.11.0
[0.10.0]: https://github.com/adamtabrams/change/compare/0.9.0...0.10.0
[0.9.0]: https://github.com/adamtabrams/change/compare/0.8.0...0.9.0
[0.8.0]: https://github.com/adamtabrams/change/compare/0.7.1...0.8.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ creating the release: `change post --dry-run`
#### Combine multiple commands with `change all`
* First it runs the `change` command.
* Then it opens your changelog with $EDITOR (or vi if that isn't set).
* As long as you updated the changelog, it amends it to your last commit and pushes to origin.
* As long as you updated the changelog, it commits and pushes it to origin.
* Lastly, it runs `change tag -p` and `change post`.
* I use this command most often.

Expand Down
79 changes: 41 additions & 38 deletions change
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ usage() {
echo
echo "change all"
echo " runs change, then opens $change_file in \$EDITOR"
echo " amends $change_file to your last commit"
echo " pushes the last commit to origin"
echo " commits and pushes the $change_file to origin"
echo " runs change tag -p and then runs change post"
}

Expand All @@ -41,7 +40,11 @@ get_versions() {
}

rm_ver_prefix() {
echo "$1" | sed "s|^[^0-9]*\([0-9.]*\).*|\1|"
echo "$1" | sed "s|^[^0-9]*\([0-9.]*.*\)|\1|"
}

rm_ver_suffix() {
sed "s|\(^[^0-9]*[0-9.]*\).*|\1|"
}

get_ver_name_date() {
Expand All @@ -50,6 +53,17 @@ get_ver_name_date() {
date +%F
}

fmt_subject() {
rm_prefix=$(echo "$1" | sed -e "s|^[^ ]*(\(.*\))!*: \(.*$\)|\2 for \1|" -e "s|^[^ ]*: \(.*$\)|\1|")

IFS="$nl"
for subject in $rm_prefix; do
first_char=$(echo "$subject" | cut -c 1 | tr "[:lower:]" "[:upper:]")

echo "$subject" | sed -e "s|^.\(.*$\)|$first_char\1|" -e "s|\(.*\)|- \1.|"
done
}

format_commits() {
list="$1"

Expand All @@ -68,30 +82,21 @@ format_commits() {
[ "$list" ] && echo "### Changed" && fmt_subject "$list" && echo ""
}

fmt_subject() {
rm_prefix=$(echo "$1" | sed -e "s|^[^ ]*(\(.*\))!*: \(.*$\)|\2 for \1|" -e "s|^[^ ]*: \(.*$\)|\1|")

IFS="$nl"
for subject in $rm_prefix; do
first_char=$(echo "$subject" | cut -c 1 | tr "[:lower:]" "[:upper:]")

echo "$subject" | sed -e "s|^.\(.*$\)|$first_char\1|" -e "s|\(.*\)|- \1.|"
done
increment_major() {
cur_major=$(echo "$1" | sed "s|^[^0-9]*\([0-9]*\)\..*$|\1|")
echo "$1" | sed "s|\.[0-9]*|.0|g" |
sed "s|\(^[^0-9]*\)[0-9]*\(\..*$\)|\1$(( cur_major + 1 ))\2|"
}

get_needed_log_ver_names() {
latest_git_ver_name=$1
latest_log_ver_name=$2

tags=$(get_versions -v)

! echo "$tags" | grep -q "$latest_log_ver_name" && return 0
echo "$tags" | sed -n "/$latest_log_ver_name/!p;//q" | sed '1!G;h;$!d'

latest_changes=$(git log --pretty=format:"%B" "$latest_git_ver_name..")
[ ! "$latest_changes" ] && return
increment_minor() {
cur_minor=$(echo "$1" | sed "s|^.*\.\([0-9]*\)\..*$|\1|")
echo "$1" | sed "s|\.[0-9]*|.0|g" |
sed "s|\(^.*\.\)[0-9]*\(\..*$\)|\1$(( cur_minor + 1 ))\2|"
}

get_new_version_name "$latest_changes" "$latest_git_ver_name"
increment_patch() {
cur_patch=$(echo "$1" | sed "s|^.*\.\([0-9]*\).*$|\1|")
echo "$1" | sed "s|\(^.*\.\)[0-9]*\(.*$\)|\1$(( cur_patch + 1 ))\2|"
}

get_new_version_name() {
Expand All @@ -108,21 +113,19 @@ get_new_version_name() {
increment_patch "$latest_git_ver_name" && return
}

increment_major() {
cur_major=$(echo "$1" | sed "s|^[^0-9]*\([0-9]*\)\..*$|\1|")
echo "$1" | sed "s|\.[0-9]*|.0|g" |
sed "s|\(^[^0-9]*\)[0-9]*\(\..*$\)|\1$(( cur_major + 1 ))\2|"
}
get_needed_log_ver_names() {
latest_git_ver_name=$1
latest_log_ver_name=$2

increment_minor() {
cur_minor=$(echo "$1" | sed "s|^.*\.\([0-9]*\)\..*$|\1|")
echo "$1" | sed "s|\.[0-9]*|.0|g" |
sed "s|\(^.*\.\)[0-9]*\(\..*$\)|\1$(( cur_minor + 1 ))\2|"
}
tags=$(get_versions -v)

increment_patch() {
cur_patch=$(echo "$1" | sed "s|^.*\.\([0-9]*\).*$|\1|")
echo "$1" | sed "s|\(^.*\.\)[0-9]*\(.*$\)|\1$(( cur_patch + 1 ))\2|"
! echo "$tags" | grep -q "$latest_log_ver_name" && return 0
echo "$tags" | sed -n "/$latest_log_ver_name/!p;//q" | sed '1!G;h;$!d'

latest_changes=$(git log --pretty=format:"%B" "$latest_git_ver_name..")
[ ! "$latest_changes" ] && return

get_new_version_name "$latest_changes" "$latest_git_ver_name" | rm_ver_suffix
}

update_diffs() {
Expand Down Expand Up @@ -282,7 +285,7 @@ run_all() {
echo "$save_file" > $change_file &&
return 1
git add $change_file &&
git commit --quiet --amend --no-edit &&
git commit --quiet -m "docs: update changelog" &&
git push --quiet origin &&
make_and_push_tag -p && post_release
}
Expand Down
5 changes: 3 additions & 2 deletions tests/test → run-test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
all_tests=$*
num_fails=0
num_tests=0
[ $# = 0 ] && all_tests="./*"

[ $# = 0 ] && all_tests="./tests/*"
[ $# != 1 ] && echo "Running tests"

for test in $all_tests; do
Expand All @@ -18,7 +19,7 @@ for test in $all_tests; do
# Run
cd actual || exit 1
[ $# != 1 ] && echo
echo "$test:"
basename "$test:"
./run-test

# Results
Expand Down
12 changes: 6 additions & 6 deletions tests/change-suffix/setup/CHANGELOG-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Add fourth file.

## [0.1.1] - ~~SUB-DATE~~
## [0.1.1-beta+002] - ~~SUB-DATE~~
### Fixed
- Add third file.

## [0.1.0] - 2021-01-19
## [0.1.0-alpha+001] - 2021-01-19
### Added
- Add first file.

### Fixed
- Add second file.

[Unreleased]: https://github.com/adamtabrams/change/compare/v0.2.0-beta+002...HEAD
[0.2.0]: https://github.com/adamtabrams/change/compare/v0.1.1-beta+002...v0.2.0-beta+002
[0.1.1]: https://github.com/adamtabrams/change/compare/v0.1.0-alpha+001...v0.1.1-beta+002
[0.1.0]: https://github.com/adamtabrams/change/releases/tag/v0.1.0-alpha+001
[Unreleased]: https://github.com/adamtabrams/change/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/adamtabrams/change/compare/v0.1.1-beta+002...v0.2.0
[0.1.1-beta+002]: https://github.com/adamtabrams/change/compare/v0.1.0-alpha+001...v0.1.1-beta+002
[0.1.0-alpha+001]: https://github.com/adamtabrams/change/releases/tag/v0.1.0-alpha+001
4 changes: 2 additions & 2 deletions tests/change-suffix/setup/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.0] - 2021-01-19
## [0.1.0-alpha+001] - 2021-01-19
### Added
- Add first file.

### Fixed
- Add second file.

[Unreleased]: https://github.com/adamtabrams/change/compare/v0.1.0-alpha+001...HEAD
[0.1.0]: https://github.com/adamtabrams/change/releases/tag/v0.1.0-alpha+001
[0.1.0-alpha+001]: https://github.com/adamtabrams/change/releases/tag/v0.1.0-alpha+001
2 changes: 1 addition & 1 deletion tests/change-suffix/setup/exp-stdout
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
added v0.1.1-beta+002 to CHANGELOG.md
added v0.2.0-beta+002 to CHANGELOG.md
added v0.2.0 to CHANGELOG.md
2 changes: 1 addition & 1 deletion tests/change-symbols/setup/CHANGELOG-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Asterisk * escaped asterisk \*.
- Four backslashes \ exclamation !.
- 'apostrophe pair' `escaped tick pair`.
- Tilda ~ escaped tick `.
- Tilda ~ escaped tick ` ampersand &.

### Changed
- [file link](./run-test).
Expand Down
2 changes: 1 addition & 1 deletion tests/change-symbols/setup/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git commit --quiet -am "fix: add second file"
git tag 0.1.0

git add exp-stderr
git commit --quiet -am "fix: tilda ~ escaped tick \`"
git commit --quiet -am "fix: tilda ~ escaped tick \` ampersand &"
git rm --quiet --cached exp-stderr
git commit --quiet -am "chore: escaped apostrophe \' escaped quote \""

Expand Down
4 changes: 2 additions & 2 deletions tests/init-suffix/setup/CHANGELOG-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.1] - ~~SUB-DATE~~
## [0.0.1-alpha+001] - ~~SUB-DATE~~
### Added
- Add first file.

### Fixed
- Add second file.

[Unreleased]: https://github.com/adamtabrams/change/compare/v0.0.1-alpha+001...HEAD
[0.0.1]: https://github.com/adamtabrams/change/releases/tag/v0.0.1-alpha+001
[0.0.1-alpha+001]: https://github.com/adamtabrams/change/releases/tag/v0.0.1-alpha+001
2 changes: 1 addition & 1 deletion tests/post-symbols/setup/CHANGELOG-exp.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Asterisk * escaped asterisk \*.
- Four backslashes \ exclamation !.
- 'apostrophe pair' `escaped tick pair`.
- Tilda ~ escaped tick `.
- Tilda ~ escaped tick ` ampersand &.

### Changed
- [file link](./run-test).
Expand Down
2 changes: 1 addition & 1 deletion tests/post-symbols/setup/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Asterisk * escaped asterisk \*.
- Four backslashes \ exclamation !.
- 'apostrophe pair' `escaped tick pair`.
- Tilda ~ escaped tick `.
- Tilda ~ escaped tick ` ampersand &.

### Changed
- [file link](./run-test).
Expand Down
2 changes: 1 addition & 1 deletion tests/post-symbols/setup/exp-stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://api.github.com/repos/adamtabrams/change
0.1.1
## [0.1.1] - 2021-01-21\n### Fixed\n- (paren pair) {curly pair} [square pair].\n- Website https://github.com/adamtabrams.\n- Asterisk * escaped asterisk \\*.\n- Four backslashes \\ exclamation !.\n- 'apostrophe pair' `escaped tick pair`.\n- Tilda ~ escaped tick `.\n\n### Changed\n- [file link](./run-test).\n- Fix: parse(this): one.\n- Emoji :+1: pr #2 user @adamtabrams.\n- Colon exclamation :! \"quote pair\".\n- Single backslash \\ escaped backslash \\.\n- Escaped apostrophe \\' escaped quote \".\n\n[0.1.1]: https://github.com/adamtabrams/change/compare/0.1.0...0.1.1\n
## [0.1.1] - 2021-01-21\n### Fixed\n- (paren pair) {curly pair} [square pair].\n- Website https://github.com/adamtabrams.\n- Asterisk * escaped asterisk \\*.\n- Four backslashes \\ exclamation !.\n- 'apostrophe pair' `escaped tick pair`.\n- Tilda ~ escaped tick ` ampersand &.\n\n### Changed\n- [file link](./run-test).\n- Fix: parse(this): one.\n- Emoji :+1: pr #2 user @adamtabrams.\n- Colon exclamation :! \"quote pair\".\n- Single backslash \\ escaped backslash \\.\n- Escaped apostrophe \\' escaped quote \".\n\n[0.1.1]: https://github.com/adamtabrams/change/compare/0.1.0...0.1.1\n

0 comments on commit 0273c21

Please sign in to comment.