Skip to content

Commit 36ec8b2

Browse files
committed
[#200] Move git auto-push checking under git environment checker
1 parent 138ba9c commit 36ec8b2

9 files changed

+67
-106
lines changed

src/checker/check.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ var checkEnv struct {
6969
langErr error
7070
tchn toolchain.TchnInterface
7171
tchnErr error
72-
git vcs.Interface
73-
gitErr error
72+
vcs vcs.Interface
73+
vcsErr error
7474
}
7575

7676
// Run goes through all configuration, parameters and local environment to check
@@ -85,7 +85,6 @@ func Run(p params.Params) {
8585
checkLanguage,
8686
checkToolchain,
8787
checkVCSEnvironment,
88-
checkAutoPush,
8988
checkCommitFailures,
9089
checkPollingPeriod,
9190
checkMobTimer,
@@ -131,7 +130,8 @@ func initCheckEnv(p params.Params) {
131130
checkEnv.workDir = toolchain.GetWorkDir()
132131

133132
if checkEnv.sourceTreeErr == nil {
134-
checkEnv.git, checkEnv.gitErr = git.New(checkEnv.sourceTree.GetBaseDir())
133+
// TODO init with the right VCS instance
134+
checkEnv.vcs, checkEnv.vcsErr = git.New(checkEnv.sourceTree.GetBaseDir())
135135
}
136136
}
137137

@@ -159,15 +159,15 @@ func checkpointsForList(headerMsg string, emptyMsg string, values []string) (cp
159159
return cp
160160
}
161161

162-
func okCheckPoint(a ...interface{}) CheckPoint {
162+
func okCheckPoint(a ...any) CheckPoint {
163163
return CheckPoint{rc: CheckStatusOk, description: fmt.Sprint(a...)}
164164
}
165165

166-
func warningCheckPoint(a ...interface{}) CheckPoint {
166+
func warningCheckPoint(a ...any) CheckPoint {
167167
return CheckPoint{rc: CheckStatusWarning, description: fmt.Sprint(a...)}
168168
}
169169

170-
func errorCheckPoint(a ...interface{}) CheckPoint {
170+
func errorCheckPoint(a ...any) CheckPoint {
171171
return CheckPoint{rc: CheckStatusError, description: fmt.Sprint(a...)}
172172
}
173173

@@ -187,15 +187,15 @@ func (cr *CheckResults) add(checkPoints []CheckPoint) {
187187
cr.checkPoints = append(cr.checkPoints, checkPoints...)
188188
}
189189

190-
func (cr *CheckResults) ok(a ...interface{}) {
190+
func (cr *CheckResults) ok(a ...any) {
191191
cr.addCheckPoint(okCheckPoint(a...))
192192
}
193193

194-
func (cr *CheckResults) warning(a ...interface{}) {
194+
func (cr *CheckResults) warning(a ...any) {
195195
cr.addCheckPoint(warningCheckPoint(a...))
196196
}
197197

198-
//func (cr *CheckResults) error(a ...interface{}) {
198+
//func (cr *CheckResults) error(a ...any) {
199199
// cr.addCheckPoint(errorCheckPoint(a...))
200200
//}
201201

src/checker/check_auto_push.go

-37
This file was deleted.

src/checker/check_auto_push_test.go

-36
This file was deleted.

src/checker/check_commit_failures.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import (
2727
)
2828

2929
func checkCommitFailures(p params.Params) (cr *CheckResults) {
30-
cr = NewCheckResults("VCS commit-failures")
30+
cr = NewCheckResults("commit-failures")
3131
if p.CommitFailures {
32-
cr.ok("VCS commit-failures is turned on: test-breaking changes will be committed")
32+
cr.ok("commit-failures is turned on: test-breaking changes will be committed")
3333
} else {
34-
cr.ok("VCS commit-failures is turned off: test-breaking changes will not be committed")
34+
cr.ok("commit-failures is turned off: test-breaking changes will not be committed")
3535
}
3636
return cr
3737
}

src/checker/check_git.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ import (
2727
"github.com/murex/tcr/vcs/git"
2828
)
2929

30-
func checkGitEnvironment(_ params.Params) (cr *CheckResults) {
30+
func checkGitEnvironment(p params.Params) (cr *CheckResults) {
3131
cr = NewCheckResults("git environment")
3232
cr.add(checkGitCommand())
3333
cr.add(checkGitConfig())
3434
cr.add(checkGitRepository())
3535
cr.add(checkGitRemote())
36+
cr.add(checkGitAutoPush(p))
3637
return cr
3738
}
3839

@@ -57,37 +58,46 @@ func checkGitRepository() (cp []CheckPoint) {
5758
cp = append(cp, errorCheckPoint("cannot retrieve git repository information from base directory name"))
5859
return cp
5960
}
60-
if checkEnv.gitErr != nil {
61-
cp = append(cp, errorCheckPoint(checkEnv.gitErr))
61+
if checkEnv.vcsErr != nil {
62+
cp = append(cp, errorCheckPoint(checkEnv.vcsErr))
6263
return cp
6364
}
6465

65-
cp = append(cp, okCheckPoint("git repository root is ", checkEnv.git.GetRootDir()))
66+
cp = append(cp, okCheckPoint("git repository root is ", checkEnv.vcs.GetRootDir()))
6667

67-
cp = append(cp, okCheckPoint("git working branch is ", checkEnv.git.GetWorkingBranch()))
68-
if checkEnv.git.IsOnRootBranch() {
68+
cp = append(cp, okCheckPoint("git working branch is ", checkEnv.vcs.GetWorkingBranch()))
69+
if checkEnv.vcs.IsOnRootBranch() {
6970
cp = append(cp, warningCheckPoint("running TCR from a root branch is not recommended"))
7071
}
7172
return cp
7273
}
7374

7475
func checkGitRemote() (cp []CheckPoint) {
75-
if checkEnv.git == nil {
76+
if checkEnv.vcs == nil {
7677
// If git is not properly initialized, no point in trying to go further
7778
return cp
7879
}
7980

80-
if !checkEnv.git.IsRemoteEnabled() {
81+
if !checkEnv.vcs.IsRemoteEnabled() {
8182
cp = append(cp, okCheckPoint("git remote is disabled: all operations will be done locally"))
8283
return cp
8384
}
8485

85-
cp = append(cp, okCheckPoint("git remote name is ", checkEnv.git.GetRemoteName()))
86+
cp = append(cp, okCheckPoint("git remote name is ", checkEnv.vcs.GetRemoteName()))
8687

87-
if checkEnv.git.CheckRemoteAccess() {
88+
if checkEnv.vcs.CheckRemoteAccess() {
8889
cp = append(cp, okCheckPoint("git remote access seems to be working"))
8990
} else {
9091
cp = append(cp, errorCheckPoint("git remote access does not seem to be working"))
9192
}
9293
return cp
9394
}
95+
96+
func checkGitAutoPush(p params.Params) (cp []CheckPoint) {
97+
if p.AutoPush {
98+
cp = append(cp, okCheckPoint("git auto-push is turned on: every commit will be pushed to origin"))
99+
} else {
100+
cp = append(cp, okCheckPoint("git auto-push is turned off: commits will only be applied locally"))
101+
}
102+
return cp
103+
}

src/checker/check_git_test.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ import (
2828
)
2929

3030
func Test_check_git_returns_warning_with_brand_new_repo(t *testing.T) {
31-
// Warning is triggered by default branch (master) being a root branch
31+
// Warning is triggered by default if branch (master) being a root branch
3232
assertWarning(t, checkGitEnvironment, *params.AParamSet())
3333
}
34+
35+
func Test_check_git_auto_push(t *testing.T) {
36+
tests := []struct {
37+
desc string
38+
value bool
39+
expected CheckStatus
40+
}{
41+
{"enabled", true, CheckStatusOk},
42+
{"disabled", false, CheckStatusOk},
43+
}
44+
for _, test := range tests {
45+
t.Run(test.desc, func(t *testing.T) {
46+
assertStatus(t, test.expected,
47+
func(p params.Params) (cr *CheckResults) {
48+
cr = NewCheckResults("git auto-push parameter")
49+
cr.add(checkGitAutoPush(p))
50+
return cr
51+
},
52+
*params.AParamSet(params.WithAutoPush(test.value)))
53+
})
54+
}
55+
}

src/checker/check_polling_period.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ const (
3333
)
3434

3535
func checkPollingPeriod(p params.Params) (cr *CheckResults) {
36-
cr = NewCheckResults("VCS polling period")
37-
cr.ok("VCS polling period is ", p.PollingPeriod.String())
36+
cr = NewCheckResults("polling period")
37+
cr.ok("polling period is ", p.PollingPeriod.String())
3838
if p.PollingPeriod == 0 {
39-
cr.warning("VCS code refresh for navigator is turned off")
39+
cr.warning("code refresh (for navigator role) is turned off")
4040
} else if p.PollingPeriod > pollingPeriodHighThreshold {
41-
cr.warning("VCS polling period is very slow (above ", pollingPeriodHighThreshold, ")")
41+
cr.warning("polling period is very slow (above ", pollingPeriodHighThreshold, ")")
4242
} else if p.PollingPeriod < pollingPeriodLowThreshold {
43-
cr.warning("VCS polling period is very fast (below ", pollingPeriodLowThreshold, ")")
43+
cr.warning("polling period is very fast (below ", pollingPeriodLowThreshold, ")")
4444
} else {
45-
cr.ok("VCS polling period is in the recommended range")
45+
cr.ok("polling period is in the recommended range")
4646
}
4747
return cr
4848
}

src/checker/check_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func slowTestTag(t *testing.T) {
5151
func initTestCheckEnv(params params.Params) {
5252
initCheckEnv(params)
5353
// We replace git implementation with a fake so that we bypass real git access
54-
checkEnv.git, checkEnv.gitErr = git.NewFake(git.FakeSettings{})
54+
checkEnv.vcs, checkEnv.vcsErr = git.NewFake(git.FakeSettings{})
5555
}
5656

5757
func assertStatus(t *testing.T, expected CheckStatus, checker func(params params.Params) (cr *CheckResults), params params.Params) {

src/checker/check_vcs.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ package checker
2424

2525
import (
2626
"github.com/murex/tcr/params"
27+
"github.com/murex/tcr/vcs/git"
28+
"github.com/murex/tcr/vcs/p4"
2729
"strings"
2830
)
2931

3032
func checkVCSEnvironment(p params.Params) (cr *CheckResults) {
3133
switch strings.ToLower(p.VCS) {
32-
case "git":
34+
case git.Name:
3335
return checkGitEnvironment(p)
34-
case "p4":
36+
case p4.Name:
3537
return checkP4Environment(p)
3638
default:
3739
return nil

0 commit comments

Comments
 (0)