Skip to content

Commit cd66cc4

Browse files
authored
Ensure returns after handling errors; edit docs; make Version Bump Check more resilient (#48)
1 parent 3de168f commit cd66cc4

File tree

8 files changed

+50
-11
lines changed

8 files changed

+50
-11
lines changed

.github/workflows/version-bump-check.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
env:
77
description: version update
88
file: main.go
9-
regex: packageVersion\s+=\s+"\S+"
9+
regex: \s+packageVersion\s+=\s+"\S+"
1010

1111
jobs:
1212
main:
@@ -21,16 +21,27 @@ jobs:
2121
name: Check for Changes
2222
run: |
2323
changed_file="$(git diff ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} ${{ env.file }})"
24+
2425
if [ -z "$changed_file" ]; then
2526
exit 1
2627
else
27-
added_match=$(echo "$changed_file" | grep -E '^\+\s+${{ env.regex }}')
28-
removed_match=$(echo "$changed_file" | grep -E '^\-\s+${{ env.regex }}')
29-
if [[ -n "$added_match" ]] && [[ -n "$removed_match" ]]; then
28+
added_match=$(echo "$changed_file" | grep -E '^\+${{ env.regex }}' || true)
29+
removed_match=$(echo "$changed_file" | grep -E '^\-${{ env.regex }}' || true)
30+
31+
if [[ -z "$added_match" ]] && [[ -z "$removed_match" ]]; then
32+
exit 1
33+
fi
34+
35+
if [[ -n "$added_match" ]]; then
3036
echo "added_match=$added_match" >> $GITHUB_OUTPUT
37+
else
38+
echo "added_match=" >> $GITHUB_OUTPUT
39+
fi
40+
41+
if [[ -n "$removed_match" ]]; then
3142
echo "removed_match=$removed_match" >> $GITHUB_OUTPUT
3243
else
33-
exit 1
44+
echo "removed_match=" >> $GITHUB_OUTPUT
3445
fi
3546
fi
3647

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sudo mv git-helper_darwin_arm64 /usr/local/bin/git-helper
2222

2323
### Downloading from GitHub Releases
2424

25-
Alternatively, you can download pre-built binaries straight from [GitHub Releases](https://github.com/emmahsax/go-git-helper/releases). After downloading, move them into `/usr/local/bin` and change the permissions. The examples below assume the binaries downloaded to `~/Downlaods`:
25+
Alternatively, you can download pre-built binaries straight from [GitHub Releases](https://github.com/emmahsax/go-git-helper/releases). After downloading, move them into `/usr/local/bin` and change the permissions. The examples below assume the binaries downloaded to `~/Downloads`:
2626

2727
```bash
2828
sudo mv ~/Downloads/git-helper_darwin_arm64 /usr/local/bin/git-helper
@@ -48,7 +48,7 @@ git-helper update
4848

4949
Your `sudo` password may be required, and you may need to verify the package is runable as following the instructions above.
5050

51-
## Setup
51+
## Config Setup
5252

5353
Some of the commands can be used without any additional configuration. However, others utilize special GitHub or GitLab configuration. To set up access with GitHub/GitLab, run:
5454

@@ -83,6 +83,8 @@ Please run with `help` to see more:
8383
git-helper --help
8484
```
8585

86+
In addition, hopefully all these options below make working with git and Go's Git Helper more seamless.
87+
8688
### With Plugins
8789

8890
As an additional enhancement, you can set each of the following commands to be a git plugin, meaning you can call them in a way that feels more git-native:
@@ -119,7 +121,23 @@ And then, running `gnb` maps to `git new-branch`, which again routes to `git-hel
119121

120122
For a full list of the git aliases I prefer to use, check out my [Git Aliases gist](https://gist.github.com/emmahsax/e8744fe253fba1f00a621c01a2bf68f5).
121123

122-
Hopefully all these options makes working with git more seamless.
124+
### With Completion
125+
126+
To set up completion (auto-filling commands as you type), run:
127+
128+
```bash
129+
mkdir -p ~/.git-helper/completions
130+
git-helper completion bash >> ~/.git-helper/completions/completion.bash
131+
git-helper completion fish >> ~/.git-helper/completions/completion.fish
132+
git-helper completion powershell >> ~/.git-helper/completions/completion.powershell
133+
git-helper completion zsh >> ~/.git-helper/completions/completion.zsh
134+
```
135+
136+
Then load the appropriate completion file for your scripting language to this to your shell file (e.g. load the following into your `~/.zshrc`):
137+
138+
```bash
139+
source ~/.git-helper/completions/completion.zsh
140+
```
123141

124142
## Commands
125143

cmd/codeRequest/codeRequest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (cr *CodeRequest) execute() {
5858
} else {
5959
err := errors.New("could not locate GitHub or GitLab remote URLs")
6060
utils.HandleError(err, cr.Debug, nil)
61+
return
6162
}
6263
}
6364

cmd/update/update.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,21 @@ func (u *Update) downloadAndSaveBinary(downloadURL, binaryName string) {
108108
resp, err := http.Get(downloadURL)
109109
if err != nil {
110110
utils.HandleError(err, u.Debug, nil)
111+
return
111112
}
112113
defer resp.Body.Close()
113114

114115
out, err := os.Create(binaryName)
115116
if err != nil {
116117
utils.HandleError(err, u.Debug, nil)
118+
return
117119
}
118120
defer out.Close()
119121

120122
_, err = io.Copy(out, resp.Body)
121123
if err != nil {
122124
utils.HandleError(err, u.Debug, nil)
125+
return
123126
}
124127
}
125128

internal/configfile/configfile.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,19 @@ func (cf *ConfigFile) GitLabToken() string {
9898
}
9999

100100
func (cf *ConfigFile) configFileContents() map[string]string {
101+
var result map[string]string
101102
data, err := os.ReadFile(cf.ConfigFile())
102103
if err != nil {
103104
customErr := errors.New("error reading file: " + err.Error())
104105
utils.HandleError(customErr, cf.Debug, nil)
106+
return result
105107
}
106108

107-
var result map[string]string
108109
err = yaml.Unmarshal(data, &result)
109110
if err != nil {
110111
customErr := errors.New("error unmarshaling YAML: " + err.Error())
111112
utils.HandleError(customErr, cf.Debug, nil)
113+
return result
112114
}
113115

114116
return result

internal/githubPullRequest/githubPullRequest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (pr *GitHubPullRequest) Create() {
5454
if err != nil {
5555
customErr := errors.New("could not create pull request: " + err.Error())
5656
utils.HandleError(customErr, pr.Debug, nil)
57+
return
5758
}
5859

5960
fmt.Println("Pull request successfully created:", *resp.HTMLURL)
@@ -65,6 +66,7 @@ func (pr *GitHubPullRequest) newPrBody() string {
6566
content, err := os.ReadFile(templateName)
6667
if err != nil {
6768
utils.HandleError(err, pr.Debug, nil)
69+
return ""
6870
}
6971

7072
return string(content)

internal/gitlabMergeRequest/gitlabMergeRequest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (mr *GitLabMergeRequest) Create() {
5353
if err != nil {
5454
customErr := errors.New("could not create merge request: " + err.Error())
5555
utils.HandleError(customErr, mr.Debug, nil)
56+
return
5657
}
5758

5859
fmt.Println("Merge request successfully created:", resp.WebURL)
@@ -75,6 +76,7 @@ func (mr *GitLabMergeRequest) newMrBody() string {
7576
content, err := os.ReadFile(templateName)
7677
if err != nil {
7778
utils.HandleError(err, mr.Debug, nil)
79+
return ""
7880
}
7981

8082
return string(content)

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121

2222
var (
2323
packageOwner = "emmahsax"
24-
packageVersion = "0.0.6"
2524
packageRepository = "go-git-helper"
25+
packageVersion = "0.0.7"
2626
)
2727

2828
func main() {
@@ -48,8 +48,8 @@ func newCommand() *cobra.Command {
4848
cmd.AddCommand(forgetLocalChanges.NewCommand())
4949
cmd.AddCommand(forgetLocalCommits.NewCommand())
5050
cmd.AddCommand(newBranch.NewCommand())
51-
cmd.AddCommand(setup.NewCommand(packageOwner, packageRepository))
5251
cmd.AddCommand(setHeadRef.NewCommand())
52+
cmd.AddCommand(setup.NewCommand(packageOwner, packageRepository))
5353
cmd.AddCommand(update.NewCommand(packageOwner, packageRepository))
5454
cmd.AddCommand(version.NewCommand(packageVersion))
5555

0 commit comments

Comments
 (0)