Skip to content
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

fix: improve error handling #30

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions change
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ semver_git_tags() {

tag_exists() {
tag=$1
semver_git_tags | grep -q "^$tag$" && return
return 1
semver_git_tags | grep -q "^$tag$"
}

latest_inc_major() {
Expand Down Expand Up @@ -86,7 +85,7 @@ rm_tag_prefix() {

tag_date_or_today() {
tag=$1
date=$(git log -1 --pretty=format:'%ci' "$tag" -- 2>/dev/null | cut -d' ' -f1)
date=$(git log -1 --pretty=format:'%ci' "$tag" -- 2>/dev/null | cut -d' ' -f1) || date=''
[ "$date" ] && echo "$date" && return
date +%F
}
Expand All @@ -95,25 +94,6 @@ top_log_tag() {
sed -En 's,^\[Unreleased\]:.*/(.*)\.\.\.HEAD$,\1,p' $log_file
}

calc_new_tag() {
latest_changes=$1

echo "$latest_changes" | grep_commits_major -q && latest_inc_major && return
echo "$latest_changes" | grep_commits_minor -q && latest_inc_minor && return
echo "$latest_changes" | grep_commits_patch -q && latest_inc_patch && return
}

unlogged_tags() {
top_tag=$(top_log_tag)
tag_exists "$top_tag" || return 0
semver_git_tags | sed -n "/^$top_tag$/q;p" | sort -V

latest_tag=$(semver_git_tags | head -1)
unlogged_commits=$(git log --pretty=format:'%B' "$latest_tag..")
[ ! "$unlogged_commits" ] && return
calc_new_tag "$unlogged_commits"
}

#### URLs ####

remote_url() {
Expand Down Expand Up @@ -229,6 +209,25 @@ format_commits() {

#### Utils ####

calc_new_tag() {
latest_changes=$1

echo "$latest_changes" | grep_commits_major -q && latest_inc_major && return
echo "$latest_changes" | grep_commits_minor -q && latest_inc_minor && return
echo "$latest_changes" | grep_commits_patch -q && latest_inc_patch && return
}

unlogged_tags() {
top_tag=$(top_log_tag)
tag_exists "$top_tag" || return 0
semver_git_tags | sed -n "/^$top_tag$/q;p" | sort -V

latest_tag=$(semver_git_tags | head -1)
unlogged_commits=$(git log --pretty=format:'%B' "$latest_tag..")
[ ! "$unlogged_commits" ] && return
calc_new_tag "$unlogged_commits"
}

initial_log() {
oldest_tag=$1

Expand Down Expand Up @@ -299,11 +298,13 @@ tag_command() {
git tag "$top_tag" || return 1
echo "tagged latest commit as $top_tag"

[ "$push_tag" ] &&
git push --quiet "$repo_url" "$top_tag" && echo "pushed $top_tag to $repo_url" && return
[ ! "$push_tag" ] &&
printf 'to push the latest tag use:\n\tgit push %s %s\n' "$repo_url" "$top_tag" &&
printf 'to push all local tags use:\n\tgit push %s --tags\n' "$repo_url" &&
return

printf 'to push the latest tag use:\n\tgit push %s %s\n' "$repo_url" "$top_tag"
printf 'to push all local tags use:\n\tgit push %s --tags\n' "$repo_url"
git push --quiet "$repo_url" "$top_tag" || return 1
echo "pushed $top_tag to $repo_url"
}

auth_command() {
Expand Down Expand Up @@ -359,11 +360,14 @@ update_command() {
[ ! "$tags" ] && echo 'no new versions to add' && return 1

echo "$tags" | while read -r next_tag; do
new_log=$(add_to_log "$next_tag")
echo "$new_log" >$log_file
new_log=$(add_to_log "$next_tag") || new_log=''

[ ! "$new_log" ] && echo "something went wrong processing $next_tag" && return 1

echo "$new_log" >$log_file
echo "added $next_tag to $log_file"
done
[ $? = 1 ] && return 1

[ "$command" ] && return 0
bump_version
Expand Down
Loading