Skip to content

Commit bbb830e

Browse files
committed
feat: transfer issue mapping to env file
1 parent c605794 commit bbb830e

6 files changed

Lines changed: 40 additions & 86 deletions

File tree

.env

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
BRCHA_HOST=
2-
BRCHA_EMAIL=
3-
BRCHA_TOKEN=
1+
BRCHA_HOST=""
2+
BRCHA_EMAIL=""
3+
BRCHA_TOKEN=""
4+
BRCHA_MAPPING="build:0;chore:0;ci:0;docs:0;feat:0;fix:0;pref:0;refactor:0;revert:0;style:0;test:0"

branch/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
func BuildName(bt Type, jiraIssue network.JiraIssue) string {
1717
log.Info().Println("preparing branch")
1818
branchType := bt.ToString()
19-
log.Debug().Printf("build name: issue %s[%s] with branch type of %s", jiraIssue.Key, jiraIssue.Id, branchType)
19+
log.Debug().Printf("build name: issue %s[%s] with branch type of '%s'", jiraIssue.Key, jiraIssue.Fields.Type.Id, branchType)
2020

2121
var buffer strings.Builder
2222

command/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ func HasBranch(branchName string) bool {
3434
err := exec.Command("git", "branch", "--contains", branchName).Run()
3535

3636
doesExist := err == nil
37-
log.Info().Printf("%s exists locally - %t", branchName, doesExist)
37+
log.Info().Printf("%s exists locally = %t", branchName, doesExist)
3838

3939
return doesExist
4040
}
4141

4242
func Checkout(branchName string, hasBranch bool) (string, error) {
4343
args := []string{"checkout", branchName}
44-
log.Info().Println("executing checkout")
44+
log.Info().Println("executing 'checkout'")
4545
log.Debug().Printf("checkout: args: %s", args)
4646

4747
if !hasBranch {

common/convert.go

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,9 @@ import (
66
"brcha/log"
77
"brcha/network"
88
"fmt"
9-
"strings"
109
)
1110

12-
func ConvertIssueToBranchType(issueType network.IssueType) (branch.Type, error) {
13-
switch issueType.Id {
14-
case issue.Build:
15-
return branch.BUILD, nil
16-
case issue.Chore:
17-
return branch.CHORE, nil
18-
case issue.Ci:
19-
return branch.CI, nil
20-
case issue.Docs:
21-
return branch.DOCS, nil
22-
case issue.Feat:
23-
return branch.FEAT, nil
24-
case issue.Fix:
25-
return branch.FIX, nil
26-
case issue.Perf:
27-
return branch.PERF, nil
28-
case issue.Refactor:
29-
return branch.REFACTOR, nil
30-
case issue.Revert:
31-
return branch.REVERT, nil
32-
case issue.Style:
33-
return branch.STYLE, nil
34-
case issue.Test:
35-
return branch.TEST, nil
36-
default:
37-
return branch.NULL, fmt.Errorf("convert: unsupported issue type %s(%s)", issueType.Name, issueType.Id)
38-
}
39-
}
40-
4111
func ConvertUserInputToBranchType(input string) (branch.Type, error) {
42-
if len(input) == 0 {
43-
return branch.NULL, nil
44-
}
45-
4612
switch input {
4713
case "build", "b":
4814
return branch.BUILD, nil
@@ -71,34 +37,25 @@ func ConvertUserInputToBranchType(input string) (branch.Type, error) {
7137
}
7238
}
7339

74-
func ConvertIssueTypesToMap(issueTypes []network.IssueType) (map[string]branch.Type, error) {
40+
func ConvertIssueTypesToMap(localTypes string, issueTypes []network.IssueType) (map[string]branch.Type, error) {
41+
local := issue.ParseIssueMapping(localTypes)
7542
issueMap := make(map[string]branch.Type)
7643

77-
var buffer strings.Builder
78-
for idx, i := range issueTypes {
79-
_, hasIgnored := issue.Ignored[i.Id]
80-
if hasIgnored {
81-
buffer.WriteString("- ")
82-
buffer.WriteString(i.Name)
83-
buffer.WriteString("[")
84-
buffer.WriteString(i.Id)
85-
buffer.WriteString("]")
86-
if idx != len(issueTypes)-1 {
87-
buffer.WriteString("\n")
88-
}
44+
for _, i := range issueTypes {
45+
id, ok := local[i.Id]
46+
if !ok {
47+
log.Warn().Println(fmt.Errorf("convert: unsupported issue type %s[%s]", i.Name, i.Id))
8948
continue
9049
}
9150

92-
name, err := ConvertIssueToBranchType(i)
51+
name, err := ConvertUserInputToBranchType(id)
9352
if err != nil {
94-
log.Warn().Printf("convert: map network to local: %v", err)
53+
log.Warn().Println(err)
9554
continue
9655
}
9756

9857
issueMap[i.Id] = name
9958
}
10059

101-
log.Warn().Printf("ignored issue types:\n%s", buffer.String())
102-
10360
return issueMap, nil
10461
}

issue/issue.go

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
package issue
22

3-
type Type struct {
4-
Id string
5-
Name string
6-
}
7-
8-
// TODO: replace with your <issue-types>
9-
const (
10-
Build = "1000"
11-
Chore = "2000"
12-
Ci = "3000"
13-
Docs = "4000"
14-
Feat = "5000"
15-
Fix = "6000"
16-
Perf = "7000"
17-
Refactor = "8000"
18-
Revert = "9000"
19-
Style = "1010"
20-
Test = "1100"
3+
import (
4+
"brcha/log"
5+
"strings"
216
)
227

23-
// TODO: replace with your ignored <issue-types>
24-
var Ignored = buildMap()
8+
func ParseIssueMapping(raw string) map[string]string {
9+
result := make(map[string]string)
10+
11+
types := strings.Split(raw, ";")
12+
for _, t := range types {
13+
elements := strings.Split(t, ":")
2514

26-
func buildMap() map[string]bool {
27-
builder := make(map[string]bool)
15+
commitType := elements[0]
16+
values := strings.Split(elements[1], ",")
2817

29-
builder["4444"] = true // Subtask
30-
// builder["3333"] = true // Bug
31-
// etc.
18+
for _, v := range values {
19+
if v == "0" {
20+
continue
21+
}
22+
23+
result[v] = commitType
24+
}
25+
}
3226

33-
return builder
27+
log.Debug().Printf("issue: parsed: %v", result)
28+
return result
3429
}

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"brcha/branch"
55
"brcha/command"
66
"brcha/common"
7-
"brcha/network"
87
"brcha/log"
8+
"brcha/network"
99
"flag"
1010
"fmt"
1111
"net/http"
@@ -125,8 +125,9 @@ func parseBranchType(input *common.Input) (branch.Type, error) {
125125
return branch.NULL, nil
126126
}
127127

128-
func convertIssueTypeToBranchType(jiraIssueType network.IssueType, types []network.IssueType) (branch.Type, error) {
129-
mappedIssueTypes, err := common.ConvertIssueTypesToMap(types)
128+
func convertIssueTypeToBranchType(jiraIssueType network.IssueType, networkTypes []network.IssueType) (branch.Type, error) {
129+
localTypes := os.Getenv("BRCHA_MAPPING")
130+
mappedIssueTypes, err := common.ConvertIssueTypesToMap(localTypes, networkTypes)
130131
if err != nil {
131132
return branch.NULL, fmt.Errorf("get issue type: %w", err)
132133
}

0 commit comments

Comments
 (0)