Skip to content

Commit

Permalink
[#674] Remote commit failure option and all related code
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdaming committed Oct 1, 2024
1 parent 72bd257 commit f406fc2
Show file tree
Hide file tree
Showing 17 changed files with 5 additions and 250 deletions.
12 changes: 0 additions & 12 deletions .run/go build github.com_murex_tcr.run.xml

This file was deleted.

14 changes: 4 additions & 10 deletions src/checker/check_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var checkWorkflowRunners []checkPointRunner

func init() {
checkWorkflowRunners = []checkPointRunner{
checkCommitFailures,
checkVariant,
}
}

Expand All @@ -43,14 +43,8 @@ func checkWorkflowConfiguration(p params.Params) (cg *model.CheckGroup) {
return cg
}

func checkCommitFailures(p params.Params) (cp []model.CheckPoint) {
switch p.CommitFailures {
case true:
cp = append(cp, model.OkCheckPoint(
"commit-failures is turned on: test-breaking changes will be committed"))
case false:
cp = append(cp, model.OkCheckPoint(
"commit-failures is turned off: test-breaking changes will not be committed"))
}
func checkVariant(_ params.Params) (cp []model.CheckPoint) {
cp = append(cp, model.WarningCheckPoint(
"variant checker TODO"))
return cp
}
29 changes: 0 additions & 29 deletions src/checker/check_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ SOFTWARE.
package checker

import (
"github.com/murex/tcr/checker/model"
"github.com/murex/tcr/params"
"github.com/stretchr/testify/assert"
"testing"
)

Expand All @@ -36,30 +34,3 @@ func Test_check_workflow_configuration(t *testing.T) {
*params.AParamSet(),
"TCR workflow configuration")
}

func Test_check_commit_failures(t *testing.T) {
tests := []struct {
desc string
value bool
expected []model.CheckPoint
}{
{
"turned off", false,
[]model.CheckPoint{
model.OkCheckPoint("commit-failures is turned off: test-breaking changes will not be committed"),
},
},
{
"turned on", true,
[]model.CheckPoint{
model.OkCheckPoint("commit-failures is turned on: test-breaking changes will be committed"),
},
},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
p := *params.AParamSet(params.WithCommitFailures(test.value))
assert.Equal(t, test.expected, checkCommitFailures(p))
})
}
}
52 changes: 0 additions & 52 deletions src/config/param_commit_failures.go

This file was deleted.

4 changes: 0 additions & 4 deletions src/config/tcr_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type TcrConfig struct {
MobTimerDuration *DurationParam
AutoPush *BoolParam
Variant *StringParam
CommitFailures *BoolParam
VCS *StringParam
MessageSuffix *StringParam
Trace *StringParam
Expand All @@ -61,7 +60,6 @@ func (c TcrConfig) reset() {
c.MobTimerDuration.reset()
c.AutoPush.reset()
c.Variant.reset()
c.CommitFailures.reset()
c.VCS.reset()
c.MessageSuffix.reset()
c.Trace.reset()
Expand Down Expand Up @@ -203,7 +201,6 @@ func AddParameters(cmd *cobra.Command, defaultDir string) {
Config.MobTimerDuration = AddMobTimerDurationParam(cmd)
Config.AutoPush = AddAutoPushParam(cmd)
Config.Variant = AddVariantParam(cmd)
Config.CommitFailures = AddCommitFailuresParam(cmd)
Config.VCS = AddVCSParam(cmd)
Config.MessageSuffix = AddMessageSuffixParam(cmd)
Config.Trace = AddTraceParam(cmd)
Expand All @@ -221,7 +218,6 @@ func UpdateEngineParams(p *params.Params) {
p.PollingPeriod = Config.PollingPeriod.GetValue()
p.AutoPush = Config.AutoPush.GetValue()
p.Variant = Config.Variant.GetValue()
p.CommitFailures = Config.CommitFailures.GetValue()
p.VCS = Config.VCS.GetValue()
p.MessageSuffix = Config.MessageSuffix.GetValue()
p.Trace = Config.Trace.GetValue()
Expand Down
1 change: 0 additions & 1 deletion src/config/tcr_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func Test_show_tcr_config_with_default_values(t *testing.T) {
expected := []string{
"TCR configuration:",
fmt.Sprintf("%v.git.auto-push: %v", prefix, false),
fmt.Sprintf("%v.git.commit-failures: %v", prefix, false),
fmt.Sprintf("%v.git.polling-period: %v", prefix, 2*time.Second),
fmt.Sprintf("%v.mob-timer.duration: %v", prefix, 5*time.Minute),
fmt.Sprintf("%v.tcr.language: %v", prefix, ""),
Expand Down
1 change: 0 additions & 1 deletion src/engine/session_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type SessionInfo struct {
ToolchainName string
VCSName string
VCSSessionSummary string
CommitOnFail bool
Variant string
GitAutoPush bool
MessageSuffix string
Expand Down
60 changes: 1 addition & 59 deletions src/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type (
setVCS(vcsInterface vcs.Interface)
ToggleAutoPush()
SetAutoPush(flag bool)
SetCommitOnFail(flag bool)
SetVariant(name string)
GetCurrentRole() role.Role
RunAsDriver()
Expand Down Expand Up @@ -93,7 +92,6 @@ type (
// roles simultaneously: we wait for it to leave the previous role
// before starting a new one
roleMutex sync.Mutex
commitOnFail bool
variant *variant.Variant
messageSuffix string
// shoot channel is used for handling interruptions coming from the UI
Expand Down Expand Up @@ -177,7 +175,6 @@ func (tcr *TCREngine) Init(p params.Params) {
tcr.setMessageSuffix(p.MessageSuffix)
tcr.vcs.EnableAutoPush(p.AutoPush)

tcr.SetCommitOnFail(p.CommitFailures)
tcr.SetVariant(p.Variant)
tcr.setMobTimerDuration(p.MobTurnDuration)

Expand All @@ -186,16 +183,6 @@ func (tcr *TCREngine) Init(p params.Params) {
tcr.warnIfOnRootBranch(tcr.mode.IsInteractive())
}

// SetCommitOnFail sets VCS commit-on-fail option to the provided value
func (tcr *TCREngine) SetCommitOnFail(flag bool) {
tcr.commitOnFail = flag
if tcr.commitOnFail {
report.PostInfo("Test-breaking changes will be committed")
} else {
report.PostInfo("Test-breaking changes will not be committed")
}
}

// SetVariant sets the TCR variant that will be used by TCR engine
func (tcr *TCREngine) SetVariant(name string) {
var err error
Expand Down Expand Up @@ -608,16 +595,7 @@ func (tcr *TCREngine) commit(event events.TCREvent) {
tcr.handleError(tcr.vcsPushAuto(), false, status.VCSError)
}

func (tcr *TCREngine) revert(event events.TCREvent) {
if tcr.commitOnFail {
err := tcr.commitTestBreakingChanges(event)
tcr.handleError(err, false, status.VCSError)
if err != nil {
return
}
tcr.handleError(tcr.vcsPushAuto(), false, status.VCSError)
}

func (tcr *TCREngine) revert(_ events.TCREvent) {
diffs, err := tcr.vcs.Diff()
tcr.handleError(err, false, status.VCSError)
if err != nil {
Expand Down Expand Up @@ -651,41 +629,6 @@ func (tcr *TCREngine) shouldRevertFile(path string) bool {
return *tcr.variant == variant.BTCR || tcr.language.IsSrcFile(path)
}

func (tcr *TCREngine) commitTestBreakingChanges(event events.TCREvent) (err error) {
// Create stash with the changes
err = tcr.vcs.Stash(commitMessageFail)
if err != nil {
return err
}
// Apply changes back in the working tree
err = tcr.vcs.UnStash(true)
if err != nil {
return err
}
// Commit changes with failure message into VCS index
err = tcr.vcs.Add()
if err != nil {
return err
}
err = tcr.vcs.Commit(false, tcr.wrapCommitMessages(commitMessageFail, &event)...)
if err != nil {
return err
}
// Revert changes (both in VCS index and working tree)
err = tcr.vcs.Revert()
if err != nil {
return err
}
// Amend commit message on revert operation in VCS index
err = tcr.vcs.Commit(false, tcr.wrapCommitMessages(commitMessageRevert, nil)...)
if err != nil {
return err
}
// Re-apply changes in the working tree and get rid of stash
err = tcr.vcs.UnStash(false)
return err
}

func (tcr *TCREngine) revertFile(file string) error {
return tcr.vcs.Restore(file)
}
Expand All @@ -701,7 +644,6 @@ func (tcr *TCREngine) GetSessionInfo() SessionInfo {
VCSName: tcr.vcs.Name(),
VCSSessionSummary: tcr.vcs.SessionSummary(),
GitAutoPush: tcr.vcs.IsAutoPushEnabled(),
CommitOnFail: tcr.commitOnFail,
Variant: tcr.variant.Name(),
MessageSuffix: tcr.messageSuffix,
}
Expand Down
68 changes: 0 additions & 68 deletions src/engine/tcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,55 +232,6 @@ func Test_tcr_operation_end_state(t *testing.T) {
}
}

func Test_tcr_revert_end_state_with_commit_on_fail_enabled(t *testing.T) {
testFlags := []struct {
desc string
vcsFailures fake.Commands
expectedStatus status.Status
}{
{
"no failure",
nil,
status.Ok,
},
{
"VCS stash failure",
fake.Commands{fake.StashCommand},
status.VCSError,
},
{
"VCS un-stash failure",
fake.Commands{fake.UnStashCommand},
status.VCSError,
},
{
"VCS add failure",
fake.Commands{fake.AddCommand},
status.VCSError,
},
{
"VCS commit failure",
fake.Commands{fake.CommitCommand},
status.VCSError,
},
{
"VCS revert failure",
fake.Commands{fake.RevertCommand},
status.VCSError,
},
}

for _, tt := range testFlags {
t.Run(tt.desc, func(t *testing.T) {
status.RecordState(status.Ok)
tcr, _ := initTCREngineWithFakes(nil, nil, tt.vcsFailures, nil)
tcr.SetCommitOnFail(true)
tcr.revert(*events.ATcrEvent())
assert.Equal(t, tt.expectedStatus, status.GetCurrentState())
})
}
}

func Test_relaxed_source_revert(t *testing.T) {
tcr, vcsFake := initTCREngineWithFakes(nil, nil, nil, nil)
tcr.revert(*events.ATcrEvent())
Expand Down Expand Up @@ -459,7 +410,6 @@ func initTCREngineWithFakesWithFileDiffs(
params.WithToolchain(tchn),
params.WithMobTimerDuration(p.MobTurnDuration),
params.WithAutoPush(p.AutoPush),
params.WithCommitFailures(p.CommitFailures),
params.WithVariant(p.Variant),
params.WithPollingPeriod(p.PollingPeriod),
params.WithRunMode(p.Mode),
Expand Down Expand Up @@ -556,24 +506,6 @@ func Test_set_auto_push(t *testing.T) {
}
}

func Test_set_commit_on_fail(t *testing.T) {
var tcr TCRInterface
testFlags := []struct {
desc string
state bool
}{
{"Turn on", true},
{"Turn off", false},
}
for _, tt := range testFlags {
t.Run(tt.desc, func(t *testing.T) {
tcr, _ = initTCREngineWithFakes(nil, nil, nil, nil)
tcr.SetCommitOnFail(tt.state)
assert.Equal(t, tt.state, tcr.GetSessionInfo().CommitOnFail)
})
}
}

func Test_set_variant(t *testing.T) {
var tcr TCRInterface
testFlags := []struct {
Expand Down
1 change: 0 additions & 1 deletion src/engine/tcr_test_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func NewFakeTCREngine() *FakeTCREngine {
VCSName: "fake",
VCSSessionSummary: "VCS session \"fake\"",
GitAutoPush: false,
CommitOnFail: false,
Variant: variant.Relaxed.Name(),
},
}
Expand Down
1 change: 0 additions & 1 deletion src/http/api/session_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func SessionInfoGetHandler(c *gin.Context) {
ToolchainName: info.ToolchainName,
VCSName: info.VCSName,
VCSSessionSummary: info.VCSSessionSummary,
CommitOnFail: info.CommitOnFail,
Variant: info.Variant,
GitAutoPush: info.GitAutoPush,
MessageSuffix: info.MessageSuffix,
Expand Down
Loading

0 comments on commit f406fc2

Please sign in to comment.