Skip to content

Commit 20b96c7

Browse files
committed
add config to README.md
1 parent acc3cfc commit 20b96c7

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

README.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# go-git-commands
22

33
## checkout
4+
45
Creates a new branch from the current branch using naming strategy `<type>/<ticket-id>/<branch-name>`.
56
Supported types are `FEAT`, `FIX`, `IMPR`, `OPS`.
67

7-
88
### Install
99

1010
```bash
@@ -32,9 +32,44 @@ brew install mrados7/main/commit
3232
go install github.com/mrados7/go-git-commands/commit@latest
3333
```
3434

35-
3635
### Usage
3736

3837
```bash
3938
commit
4039
```
40+
41+
## Config file
42+
43+
You can add a config file to project directory `.git-commands.json` to override the default values.
44+
45+
```json
46+
{
47+
"branchTypes": [
48+
{
49+
"type": "FEAT",
50+
"description": "A new feature"
51+
},
52+
{
53+
"type": "FIX",
54+
"description": "A bug fix"
55+
},
56+
{
57+
"type": "DOCS",
58+
"description": "Documentation only changes"
59+
},
60+
...
61+
],
62+
"boards": [
63+
{
64+
"name": "PLF",
65+
"description": "Platform Team Board"
66+
},
67+
{
68+
"name": "SD",
69+
"description": "Support Desk Board"
70+
}
71+
...
72+
]
73+
}
74+
75+
```

cmd/checkout/config.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ type branchType struct {
1313
D string `json:"description"`
1414
}
1515

16-
type jiraBoard struct {
16+
type board struct {
1717
Name string `json:"name"`
1818
D string `json:"description"`
1919
}
2020

2121
type config struct {
2222
BranchTypes []branchType `json:"branchTypes"`
23-
JiraBoards []jiraBoard `json:"jiraBoards"`
23+
boards []board `json:"boards"`
2424
}
2525

2626
const configFile = ".git-commands.json"
@@ -34,8 +34,8 @@ var defaultBranchTypes = []list.Item{
3434
}
3535

3636
var defaultJiraBoards = []list.Item{
37-
jiraBoard{"EPD", "CPO team board"},
38-
jiraBoard{"IB", "Interim billing board"},
37+
board{"EPD", "CPO team board"},
38+
board{"IB", "Interim billing board"},
3939
}
4040

4141
func convertBranchTypes(branchTypes []branchType) []list.Item {
@@ -49,7 +49,7 @@ func convertBranchTypes(branchTypes []branchType) []list.Item {
4949
return items
5050
}
5151

52-
func convertBoards(boards []jiraBoard) []list.Item {
52+
func convertBoards(boards []board) []list.Item {
5353
items := []list.Item{}
5454
for _, board := range boards {
5555
items = append(items, board)
@@ -69,7 +69,7 @@ func loadConfigFile(path string) ([]list.Item, []list.Item, error) {
6969
if err := json.Unmarshal(data, &c); err != nil {
7070
return nil, nil, fmt.Errorf("error parsing config file: %w", err)
7171
}
72-
return convertBranchTypes(c.BranchTypes), convertBoards(c.JiraBoards), nil
72+
return convertBranchTypes(c.BranchTypes), convertBoards(c.boards), nil
7373
}
7474

7575
func loadConfig() ([]list.Item, []list.Item, error) {

cmd/checkout/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const (
1515
listHeight = 35
1616
)
1717

18-
func (b jiraBoard) Title() string { return b.Name }
19-
func (b jiraBoard) Description() string { return b.D }
20-
func (b jiraBoard) FilterValue() string { return b.Name }
18+
func (b board) Title() string { return b.Name }
19+
func (b board) Description() string { return b.D }
20+
func (b board) FilterValue() string { return b.Name }
2121

2222
func (p branchType) Title() string { return p.T }
2323
func (p branchType) Description() string { return p.D }
@@ -199,8 +199,8 @@ func (m model) UpdateJiraBoardList(msg tea.Msg) (tea.Model, tea.Cmd) {
199199
case tea.KeyCtrlC, tea.KeyEsc:
200200
return m, tea.Quit
201201
case tea.KeyEnter, tea.KeySpace:
202-
m.selectedJiraBoard = m.jiraBoardList.SelectedItem().(jiraBoard).Title()
203-
m.ticketIdInput.SetValue(m.jiraBoardList.SelectedItem().(jiraBoard).Title() + "-")
202+
m.selectedJiraBoard = m.jiraBoardList.SelectedItem().(board).Title()
203+
m.ticketIdInput.SetValue(m.jiraBoardList.SelectedItem().(board).Title() + "-")
204204
m.shouldEnterTicketId = true
205205
}
206206
}

0 commit comments

Comments
 (0)