-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from iamthen0ise/split-project-fix-errors
Split project. Add tests. Fix Errors
- Loading branch information
Showing
11 changed files
with
317 additions
and
162 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Go Build & Test | ||
|
||
on: | ||
push: | ||
branches: [ stable ] | ||
pull_request: | ||
branches: [ stable ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
|
||
- name: Build | ||
run: make build | ||
|
||
- name: Test | ||
run: make test |
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,4 @@ | ||
build: | ||
go build -v ./... | ||
test: | ||
go test -cover -coverprofile=cover.test -v ./... -coverpkg=./... |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
module github.io/iamthen0ise/bb | ||
|
||
go 1.16 |
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,25 @@ | ||
package git | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func ExecuteGitCommand(branchName string, checkout bool) error { | ||
app := "git" | ||
|
||
var subcommand string | ||
var args []string | ||
|
||
if checkout { | ||
subcommand = "checkout" | ||
args = append(args, "-b") | ||
} else { | ||
subcommand = "branch" | ||
} | ||
|
||
cmd := exec.Command(app, subcommand, strings.Join(args, " "), branchName) | ||
_, err := cmd.Output() | ||
|
||
return err | ||
} |
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,42 @@ | ||
package parsing | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.io/iamthen0ise/bb/src/git" | ||
) | ||
|
||
type GitBranchName struct { | ||
Prefix string | ||
IssueID string | ||
CustomTextParts []string | ||
BranchName string | ||
} | ||
|
||
func (o *GitBranchName) BuildBranchName() { | ||
var sb strings.Builder | ||
if len(o.Prefix) > 0 { | ||
sb.WriteString(o.Prefix) | ||
sb.WriteString("/") | ||
} | ||
|
||
sb.WriteString(o.IssueID) | ||
if len(o.IssueID) > 0 && len(o.CustomTextParts) > 0 { | ||
sb.WriteString("-") | ||
} | ||
sb.WriteString(strings.Join(o.CustomTextParts, "-")) | ||
|
||
o.BranchName = sb.String() | ||
} | ||
|
||
func (o *GitBranchName) UpdateFields(p string, i string, tp []string) { | ||
o.Prefix = p | ||
o.IssueID = i | ||
o.CustomTextParts = tp | ||
o.BuildBranchName() | ||
} | ||
|
||
func (o *GitBranchName) CreateBranch(checkout bool) error { | ||
err := git.ExecuteGitCommand(o.BranchName, checkout) | ||
return err | ||
} |
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,44 @@ | ||
package parsing | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const JiraRe = `([A-Z]+-[\d]+)` | ||
|
||
var ( | ||
RE = regexp.MustCompile(JiraRe) | ||
FlagConstants = []string{"-i", "--i", "-t", "--t", "-c", "--c"} | ||
) | ||
|
||
type InputArgs struct { | ||
Prefix string | ||
IssueID string | ||
CustomTextParts []string | ||
} | ||
|
||
func (a *InputArgs) ParseArg(t *string) { | ||
for _, char := range FlagConstants { | ||
if *t == char { | ||
return | ||
} | ||
} | ||
|
||
var issuerIdMatches = RE.FindAllString(strings.ToUpper(*t), -1) | ||
if len(issuerIdMatches) > 0 { | ||
a.IssueID = issuerIdMatches[0] | ||
} else if strings.Trim(*t, "-") == "f" { | ||
a.Prefix = "feature" | ||
} else if strings.Trim(*t, "-") == "h" { | ||
a.Prefix = "hotfix" | ||
} else { | ||
a.CustomTextParts = append(a.CustomTextParts, *t) | ||
} | ||
} | ||
|
||
func (a *InputArgs) ParseArgs(s []string) { | ||
for _, c := range s { | ||
a.ParseArg(&c) | ||
} | ||
} |
Oops, something went wrong.