Skip to content

Commit 1834071

Browse files
committed
close #191 separate repo and issue configuration
1 parent e7b2fb8 commit 1834071

File tree

5 files changed

+173
-18
lines changed

5 files changed

+173
-18
lines changed

.phlow

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
integration_branch = master
33
remote = origin
44
service = github
5+
issue_url = https://api.github.com
6+
pipeline_url = http://concourse.bosh.praqma.cloud/teams/main/pipelines/git-phlow
57
delivery_branch_prefix = ready
68
[jira]
9+
service = sd
710
integration_branch = gh_pages
811
remote = fork
9-
service = jira
10-
delivery_branch_prefix = integrateme
11-
12-
[gitlab]
13-
integration_branch = gh_pages
14-
remote = fork
15-
service = jira
12+
repo_url = jira
13+
issue_url = jira
1614
delivery_branch_prefix = integrateme

docs/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
### Configuration
2+
git phlow is configured via `.phlow`, or `.gitignore` files., in your local workspace or in the home folder of your computer. The configuration is standard INI files, just like gitconfig.
3+
4+
#### Config Block
5+
Each configuration is has it's own block which can be used either by setting the block name to `[default]` or by specifying which configuration you want to use by setting it in the git phlow command.
6+
7+
A block consists of following fields.
8+
9+
- `integration_branch` The name of your default integration branch. normally it's `master`
10+
- `remote` The name of your remote. By default git sets this to `origin`
11+
- `service` The service you use for issues.
12+
- `issue_url` The url to your service where issues are hosted and managed
13+
- `delivery_branch_prefix` The prefix you want your pretested integration system to look for
14+
15+
#### Supported services
16+
- `github`
17+
- ~~`jira`~~ - coming soon
18+
19+
20+
#### Example Configuration
21+
```ini
22+
[name]
23+
integration_branch = master
24+
remote = origin
25+
service = github
26+
issue_url = https://api.github.com
27+
pipeline_url = http://concourse.bosh.praqma.cloud/teams/main/pipelines/git-phlow #optional
28+
delivery_branch_prefix = ready
29+
```
30+
31+
#### Internal Default
32+
If no `.phlow` or `.gitconfig` files are located, git phlow will use an interal default configuration. The internal configuration is the last resort, and it is strongly recommended to use `.phlow` to keep your projects configuration, even though it mimiks the default.
33+
34+
```ini
35+
[default]
36+
integration_branch = master
37+
remote = origin
38+
service = github
39+
issue_url = https://api.github.com
40+
delivery_branch_prefix = ready
41+
```

main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
package main
22

3-
import "github.com/praqma/git-phlow/cmd"
3+
import (
4+
"github.com/praqma/git-phlow/setting"
5+
"fmt"
6+
)
47

58
func main() {
6-
cmd.Execute()
9+
//cmd.Execute()
10+
11+
proj := setting.NewProjectStg("default")
12+
13+
err := setting.ValidateLoadedSetting(proj)
14+
fmt.Println(err)
715

816
}

setting/setting.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/praqma/git-phlow/executor"
77
"github.com/go-ini/ini"
88
"fmt"
9+
"reflect"
10+
"github.com/go-errors/errors"
911
)
1012

1113
//Load internals
@@ -17,12 +19,14 @@ const (
1719

1820
//Default configuration
1921
const (
22+
internal_default_service = "github"
2023
internal_default_integration_branch = "master"
2124
internal_default_remote = "origin"
22-
internal_default_service = "github"
25+
internal_default_issue_url = "https://api.github.com"
2326
internal_default_delivery_branch_prefix = "ready"
2427
internal_default_scope = "internal"
2528
internal_default_file = "none"
29+
internal_pipeline_url = "none"
2630
)
2731

2832
//Uses git config commandline interface
@@ -35,12 +39,15 @@ type ToolsSetting struct {
3539

3640
//ProjectSetting ...
3741
type ProjectSetting struct {
42+
Service string `ini:"service"`
3843
IntegrationBranch string `ini:"integration_branch"`
3944
Remote string `ini:"remote"`
40-
Service string `ini:"service"`
45+
IssueURL string `ini:"issue_url"`
46+
PipelineUrl string `ini:"pipeline"`
4147
DeliveryBranchPrefix string `ini:"delivery_branch_prefix"`
4248
Scope string
4349
File string
50+
INIBlock string
4451
}
4552

4653
//NewProjectStg ...
@@ -102,10 +109,12 @@ func LoadProjectSettings(local, global string, INIBlock string) *ProjectSetting
102109
}
103110
//return internal default because no other configuration exist and no other is specified by params
104111
return &ProjectSetting{
112+
Service: internal_default_service,
105113
IntegrationBranch: internal_default_integration_branch,
106114
Remote: internal_default_remote,
107-
Service: internal_default_service,
115+
IssueURL: internal_default_issue_url,
108116
DeliveryBranchPrefix: internal_default_delivery_branch_prefix,
117+
PipelineUrl: internal_pipeline_url,
109118
Scope: internal_default_scope,
110119
File: internal_default_file,
111120
}
@@ -118,10 +127,50 @@ func LoadProjectSettings(local, global string, INIBlock string) *ProjectSetting
118127
//Add configuration origin
119128
conf.File = configFile
120129
conf.Scope = configScope
130+
conf.INIBlock = INIBlock
121131

132+
if err := ValidateLoadedSetting(conf); err != nil {
133+
fmt.Println(err)
134+
os.Exit(1)
135+
}
122136
return conf
123137
}
124138

139+
//ValidateLoadedSetting ...
140+
func ValidateLoadedSetting(setting *ProjectSetting) (error) {
141+
r := reflect.ValueOf(setting).Elem()
142+
t := r.Type()
143+
144+
//Non Optional Field checks..
145+
for i := 0; i < t.NumField(); i++ {
146+
if t.Field(i).Name == "Service" && (r.Field(i).String() == "") {
147+
return errors.New(fmt.Sprintf("Error in configuration file: %s \n"+
148+
"Non-optional field missing: %s \n In configuration block: %s \n ", setting.Scope+"/"+setting.File, "service", setting.INIBlock))
149+
}
150+
151+
if t.Field(i).Name == "IssueURL" && r.Field(i).String() == "" {
152+
return errors.New(fmt.Sprintf("Error in configuration file: %s \n"+
153+
"Non-optional field missing: %s \n In configuration block: %s \n ", setting.Scope+"/"+setting.File, "issue_url", setting.INIBlock))
154+
}
155+
156+
if t.Field(i).Name == "IntegrationBranch" && r.Field(i).String() == "" {
157+
return errors.New(fmt.Sprintf("Error in configuration file: %s \n"+
158+
"Non-optional field missing: %s \n In configuration block: %s \n ", setting.Scope+"/"+setting.File, "integration_branch", setting.INIBlock))
159+
}
160+
161+
if t.Field(i).Name == "Remote" && r.Field(i).String() == "" {
162+
return errors.New(fmt.Sprintf("Error in configuration file: %s \n"+
163+
"Non-optional field missing: %s \n In configuration block: %s \n ", setting.Scope+"/"+setting.File, "remote", setting.INIBlock))
164+
}
165+
166+
if t.Field(i).Name == "DeliveryBranchPrefix" && r.Field(i).String() == "" {
167+
return errors.New(fmt.Sprintf("Error in configuration file: %s \n"+
168+
"Non-optional field missing: %s \n In configuration block: %s \n ", setting.Scope+"/"+setting.File, "delivery_branch_prefix", setting.INIBlock))
169+
}
170+
}
171+
return nil
172+
}
173+
125174
//LoadToolSettings ...
126175
func LoadToolSettings(run executor.Runner) *ToolsSetting {
127176
var set = ToolsSetting{}

setting/setting_test.go

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,90 @@ var _ = Describe("Setting", func() {
5252
Describe("LoadProjectSetting", func() {
5353

5454
It("should return find local default", func() {
55-
5655
conf := setting.LoadProjectSettings(setting.GetLocal(), "", "default")
5756
Ω(conf.File).Should(Equal(".phlow"))
58-
Ω(conf.Service).Should(Equal("github"))
59-
57+
Ω(conf.IssueURL).Should(Equal("https://api.github.com"))
6058
})
6159

6260
It("should find local jira", func() {
6361
conf := setting.LoadProjectSettings(setting.GetLocal(), "", "jira")
6462
Ω(conf.File).Should(Equal(".phlow"))
65-
Ω(conf.Service).Should(Equal("jira"))
63+
Ω(conf.IssueURL).Should(Equal("jira"))
6664
})
6765

6866
It("no params should set default", func() {
6967
conf := setting.LoadProjectSettings(setting.GetLocal(), "", "")
7068
Ω(conf.File).Should(Equal(".phlow"))
71-
Ω(conf.Service).Should(Equal("github"))
69+
Ω(conf.IssueURL).Should(Equal("https://api.github.com"))
7270
})
7371

74-
7572
It("no config files should use internal default", func() {
7673
conf := setting.LoadProjectSettings("", "", "")
7774
Ω(conf.File).Should(Equal("none"))
7875
Ω(conf.Scope).Should(Equal("internal"))
7976
})
8077
})
8178

79+
Describe("Test Validation for non-optional params", func() {
80+
var set = setting.ProjectSetting{}
81+
82+
BeforeEach(func() {
83+
set = setting.ProjectSetting{
84+
Service: "not empty",
85+
IntegrationBranch: "not empty",
86+
DeliveryBranchPrefix: "not empty",
87+
Remote: "not empty",
88+
IssueURL: "not empty",
89+
PipelineUrl: "not empty"}
90+
91+
})
92+
93+
Context("With missing IssueUrl", func() {
94+
It("Should return error", func() {
95+
set.IssueURL = ""
96+
err := setting.ValidateLoadedSetting(&set)
97+
Ω(err).ShouldNot(BeNil())
98+
99+
})
100+
101+
})
102+
103+
Context("With missing remote", func() {
104+
It("Should return error", func() {
105+
set.Remote = ""
106+
err := setting.ValidateLoadedSetting(&set)
107+
Ω(err).ShouldNot(BeNil())
108+
109+
})
110+
111+
})
112+
113+
Context("With missing branch prefix", func() {
114+
It("Should return error", func() {
115+
set.DeliveryBranchPrefix = ""
116+
err := setting.ValidateLoadedSetting(&set)
117+
Ω(err).ShouldNot(BeNil())
118+
119+
})
120+
121+
})
122+
123+
Context("With missing integration branch", func() {
124+
It("Should return error", func() {
125+
set.IntegrationBranch = ""
126+
err := setting.ValidateLoadedSetting(&set)
127+
Ω(err).ShouldNot(BeNil())
128+
})
129+
})
130+
131+
Context("With missing service", func() {
132+
It("Should return error", func() {
133+
set.Service = ""
134+
err := setting.ValidateLoadedSetting(&set)
135+
Ω(err).ShouldNot(BeNil())
136+
})
137+
})
138+
139+
})
140+
82141
})

0 commit comments

Comments
 (0)