Skip to content

Commit

Permalink
Merge pull request #19 from iamthen0ise/feature/kaiten
Browse files Browse the repository at this point in the history
Support Kaiten
  • Loading branch information
iamthen0ise authored Aug 18, 2022
2 parents 59e226f + abf4a0b commit 5d34275
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func main() {
flag.Bool("h", false, "Set `hotfix` prefix")
flag.Bool("m", false, "Rename current branch instead of creating new")
flag.Bool("y", false, "Create and checkout without confirmation")
flag.Bool("commit", false, "Commit changes with prefixed message from branch name (default `false`")
flag.Bool("c", true, "Checkout to new branch (default `true`")
flag.Parse()

Expand Down Expand Up @@ -65,6 +66,7 @@ func main() {
}
} else {
fmt.Println("Your new branch name is:", s.Colorize(&gitBranchName.BranchName, s.Magenta))

if inputArgs.Strategy == "Rename" {
fmt.Println("Do you want to continue and rename current branch ? [Enter to continue]")
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ func RenameCurrentBranch(newBranchName string) error {

return err
}

func CommitChanges(messagePrefix string, messageText string) error {
cmd := exec.Command("git", "commit", "-m", strings.Join([]string{messagePrefix, messageText}, "."))
_, err := cmd.Output()

return err
}
25 changes: 20 additions & 5 deletions src/parsing/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
)

const JiraRe = `([A-Z]+-[\d]+)`
const KaitenRe = `(KAITEN.(RU|COM)\/[\d]+)`

var (
RE = regexp.MustCompile(JiraRe)
FlagConstants = []string{"-i", "--i", "-t", "--t", "-c", "--c"}
JiraReCompiled = regexp.MustCompile(JiraRe)
KaitenReCompiled = regexp.MustCompile(KaitenRe)
FlagConstants = []string{"-i", "--i", "-t", "--t", "-c", "--c"}
)

type InputArgs struct {
Expand All @@ -27,10 +29,23 @@ func (a *InputArgs) ParseArg(t *string) {
}
}

var issuerIdMatches = RE.FindAllString(strings.ToUpper(*t), -1)
var jiraMatches = JiraReCompiled.FindAllString(strings.ToUpper(*t), -1)
var kaitenMatches = KaitenReCompiled.FindAllString(strings.ToUpper(*t), -1)

if len(issuerIdMatches) > 0 {
a.IssueID = issuerIdMatches[0]
var issueIdMatches string

if len(jiraMatches) > 0 {
issueIdMatches = jiraMatches[0]
} else if len(kaitenMatches) > 0 {
issueIdMatches = strings.Replace(kaitenMatches[0], "/", "-", -1)
issueIdMatches = strings.Replace(issueIdMatches, ".RU", "", -1)
issueIdMatches = strings.Replace(issueIdMatches, ".COM", "", -1)
} else {
issueIdMatches = ""
}

if len(issueIdMatches) > 0 {
a.IssueID = issueIdMatches
} else if strings.Trim(*t, "-") == "f" {
a.Prefix = "feature"
} else if strings.Trim(*t, "-") == "h" {
Expand Down
1 change: 0 additions & 1 deletion src/screen/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const (

Magenta = "\u001b[36m"
Yellow = "\u001b[33m"
//BRIGHT_BLACK = "\u001b[30;1m"
)

func Colorize(text *string, color string) string {
Expand Down
22 changes: 16 additions & 6 deletions tests/input_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
)

var (
rawParams = []string{"f", "https://jira.atlassian.com/browse/JIRA-123", "fix", "this", "m"}
flaggedParams = []string{"-f", "--i", "https://jira.atlassian.com/browse/JIRA-123", "--t", "-m", "fix", "this", "-y"}
jiraRawParams = []string{"f", "https://jira.atlassian.com/browse/JIRA-123", "fix", "this", "m"}
kaitenRawParams = []string{"f", "https://example.kaiten.ru/123456", "add", "more", "code"}
flaggedParams = []string{"-f", "--i", "https://jira.atlassian.com/browse/JIRA-123", "--t", "-m", "fix", "this", "-y"}
)

func TestInputRawPrefix(t *testing.T) {
Expand Down Expand Up @@ -40,18 +41,27 @@ func TestInputRawPrefix(t *testing.T) {
t.Errorf("want %v got %v", want, inputArgs.Prefix)
}
}
func TestInputRawIssueID(t *testing.T) {
func TestInputRawJira(t *testing.T) {
var inputArgs = p.InputArgs{}
inputArgs.ParseArgs(rawParams)
inputArgs.ParseArgs(jiraRawParams)
want := "JIRA-123"
if inputArgs.IssueID != want {
t.Errorf("want %v got %v", want, inputArgs.IssueID)
}
}

func TestInputRawKaiten(t *testing.T) {
var inputArgs = p.InputArgs{}
inputArgs.ParseArgs(kaitenRawParams)
want := "KAITEN-123456"
if inputArgs.IssueID != want {
t.Errorf("want %v got %v", want, inputArgs.IssueID)
}
}

func TestInputRawRenameStrategy(t *testing.T) {
var inputArgs = p.InputArgs{}
inputArgs.ParseArgs(rawParams)
inputArgs.ParseArgs(jiraRawParams)
want := "Rename"
if inputArgs.Strategy != want {
t.Errorf("want %v got %v", want, inputArgs.IssueID)
Expand All @@ -60,7 +70,7 @@ func TestInputRawRenameStrategy(t *testing.T) {

func TestInputRawCustomTextParts(t *testing.T) {
var inputArgs = p.InputArgs{}
inputArgs.ParseArgs(rawParams)
inputArgs.ParseArgs(jiraRawParams)
if len(inputArgs.CustomTextParts) < 1 {
t.Error("customTextParts is empty")
}
Expand Down

0 comments on commit 5d34275

Please sign in to comment.