-
Notifications
You must be signed in to change notification settings - Fork 6
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
Extend git commands #50
Open
charlesreffett
wants to merge
28
commits into
master
Choose a base branch
from
feature/extend-git-commands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f812dcd
feat: create bin dir
charlesreffett eba8203
feat: symlink git commands
charlesreffett e918e61
feat: git tickets command
charlesreffett 089e44c
feat: git make-release command
charlesreffett 644711e
docs: document the setup scripts and how to use the git scripts
charlesreffett cb17ff4
style: fix markdown formatting
charlesreffett 33126bc
refactor: fix linting errors
charlesreffett 4d605c2
style: readme line length
charlesreffett d75fbdc
style: remove double word
charlesreffett 3164672
refactor: delcare and assign separately
charlesreffett 67ce1e2
style: remove pesky trailing spaces
charlesreffett 25b7536
ci: disable shell check SC1091
charlesreffett 5f61c2f
feat: remove adding bin dir to home
charlesreffett b73539d
feat: remove linking git commands
charlesreffett 8678f49
refactor: move git scripts to hop project bin
charlesreffett 036e8af
docs: remove the install section
charlesreffett aec9c39
docs: add CLI tooling setup section
charlesreffett a4d95d9
fix: correctly get the versioning segments and increment
charlesreffett 5559d58
feat: improve branch processing if a target branch doesn't exist
charlesreffett 1358fc9
style: fix formatting
charlesreffett 6a6a485
style: SC2181 (style): Check exit code directly
charlesreffett 9758b41
Merge branch 'master' into feature/extend-git-commands
charlesreffett 5b28a9d
docs: remove shell command example, decided it's just easier to add b…
charlesreffett 53eaad2
Update README.md
charlesreffett f0058da
Merge branch 'master' into feature/extend-git-commands
charlesreffett 1915151
Merge remote-tracking branch 'origin/feature/extend-git-commands' int…
charlesreffett 02d7051
docs: add simple hop description
charlesreffett d8fb997
Merge branch 'master' into feature/extend-git-commands
charlesreffett 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 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
This file contains 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,92 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Prompt for the version number | ||
prompt_for_version() { | ||
read -rp "Enter the version number (default: $1): " version | ||
echo "${version:-$1}" # Return the entered version number or the default if none was entered | ||
bradtoad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
# Increment version number | ||
increment_version() { | ||
# Split the version string into parts using read -a | ||
IFS='.' | ||
read -ra version_parts <<< "$1" | ||
|
||
# Ensure that we have exactly three parts for major, minor, and patch versions | ||
if [ ${#version_parts[@]} -ne 3 ]; then | ||
echo "Error: Invalid version format '$1'. Expected format 'Major.Minor.Patch'." >&2 | ||
return 1 # Exit the function with an error status | ||
fi | ||
|
||
# Increment the minor version and reset the patch version to 0 | ||
local next_version="${version_parts[0]}.$((version_parts[1] + 1)).0" | ||
|
||
# Call prompt_for_version, using the next version as the default | ||
prompt_for_version "$next_version" | ||
} | ||
|
||
# Get the latest version tag | ||
get_latest_version() { | ||
git describe --tags "$(git rev-list --tags --max-count=1)" 2>/dev/null || echo "v0.0.0" | ||
} | ||
|
||
# Prepend the tickets to the CHANGELOG.md | ||
prepend_to_changelog() { | ||
local version=$1 | ||
local tickets=$2 | ||
local date | ||
|
||
date=$(date +"%b %d, %Y") | ||
local changelog="CHANGELOG.md" | ||
|
||
# Create a backup of the CHANGELOG.md | ||
cp "$changelog" "$changelog.bak" | ||
|
||
# Prepend the new content to the CHANGELOG.md | ||
{ | ||
echo "# v$version ($date)" | ||
for ticket in $tickets; do | ||
echo "* $ticket - " | ||
done | ||
echo "" | ||
cat "$changelog.bak" | ||
} > "$changelog" | ||
|
||
rm "$changelog.bak" | ||
} | ||
|
||
# Check if the --dry flag is set | ||
DRY_RUN=false | ||
if [ "$1" == "--dry" ]; then | ||
DRY_RUN=true | ||
fi | ||
|
||
# Get the latest tag and suggest the next version number | ||
LATEST_TAG=$(get_latest_version) | ||
NEXT_VERSION=$(increment_version "${LATEST_TAG#v}") # Assuming the tag is in the 'v1.2.3' format | ||
|
||
if $DRY_RUN; then | ||
# Perform a dry run | ||
echo "This is a dry run. The release branch will not be created." | ||
echo "The next version number would be: ${NEXT_VERSION}" | ||
git tickets | grep -Eo '(\w+)-([0-9]+)' | ||
else | ||
# Perform the actual release process | ||
# Capture the output of git-tickets | ||
TICKETS_OUTPUT=$(git tickets --update) | ||
|
||
# Use grep to filter the output | ||
TICKET_IDS=$(echo "$TICKETS_OUTPUT" | grep -Eo '(\w+)-([0-9]+)') | ||
|
||
# Prepend the tickets to the CHANGELOG.md | ||
prepend_to_changelog "$NEXT_VERSION" "$TICKET_IDS" | ||
|
||
# Checkout a new branch with the pattern release-### | ||
git checkout -b "release-${NEXT_VERSION}" | ||
|
||
# Add the CHANGELOG.md to the staging area | ||
git add CHANGELOG.md | ||
|
||
echo "Tickets to be included in this release:" | ||
echo "$TICKET_IDS" | ||
fi |
This file contains 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,75 @@ | ||
#!/bin/bash | ||
# Prompt for a branch name with a default | ||
prompt_for_branch() { | ||
read -rp "Enter the name of the $1 branch (default: $2): " branch | ||
echo "${branch:-$2}" # Return the entered branch name or the default if none was entered | ||
} | ||
|
||
# Check for --update flag | ||
UPDATE_BRANCHES=false | ||
for arg in "$@"; do | ||
if [ "$arg" == "--update" ]; then | ||
UPDATE_BRANCHES=true | ||
break | ||
fi | ||
done | ||
|
||
# Prompt for the first branch name if not provided | ||
if [ -z "$1" ] || [ "$1" == "--update" ]; then | ||
BRANCH1=$(prompt_for_branch "first" "master") | ||
else | ||
BRANCH1="$1" | ||
fi | ||
|
||
# Prompt for the second branch name if not provided | ||
if [ -z "$2" ] || [ "$2" == "--update" ]; then | ||
BRANCH2=$(prompt_for_branch "second" "staging") | ||
else | ||
BRANCH2="$2" | ||
fi | ||
# Function to update or create temporary branches | ||
process_branch() { | ||
local branch_name=$1 | ||
local temp_branch="temp_${branch_name}_$$" | ||
if $UPDATE_BRANCHES; then | ||
git checkout "$branch_name" &> /dev/null | ||
if ! git checkout "$branch_name" &> /dev/null; then | ||
echo "Failed to checkout branch $branch_name" >&2 | ||
exit 1 | ||
fi | ||
git pull origin "$branch_name" &> /dev/null | ||
echo "$branch_name" | ||
else | ||
git fetch origin "$branch_name":"$temp_branch" &> /dev/null | ||
if ! git rev-parse --verify "$temp_branch" &> /dev/null; then | ||
echo "Failed to fetch and create temp branch for $branch_name" >&2 | ||
exit 1 | ||
fi | ||
echo "$temp_branch" | ||
fi | ||
} | ||
|
||
|
||
# Process the first branch | ||
BRANCH1=$(process_branch "$BRANCH1") | ||
|
||
# Process the second branch | ||
BRANCH2=$(process_branch "$BRANCH2") | ||
|
||
# If not updating branches, use the temporary branches for log | ||
if ! $UPDATE_BRANCHES; then | ||
# Run the git log command and process the output on temporary branches | ||
git log "$BRANCH2".."$BRANCH1" --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u | ||
|
||
# Delete the temporary branches | ||
git branch -D "$BRANCH1" &> /dev/null | ||
git branch -D "$BRANCH2" &> /dev/null | ||
git status; | ||
else | ||
# Run the git log command and process the output on updated branches | ||
git log "$BRANCH2".."$BRANCH1" --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u | ||
|
||
# Checkout to the first branch (assumed to be 'master') | ||
git checkout "$BRANCH1" &> /dev/null | ||
git status | ||
fi |
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.
Could maybe link to the hop README.md under docs