Skip to content

Commit

Permalink
add git push option ci.skip
Browse files Browse the repository at this point in the history
  • Loading branch information
hollesse committed Apr 17, 2024
1 parent 8fba914 commit cb27110
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 9 deletions.
9 changes: 9 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Configuration struct {
RemoteName string // override with MOB_REMOTE_NAME
WipCommitMessage string // override with MOB_WIP_COMMIT_MESSAGE
StartCommitMessage string // override with MOB_START_COMMIT_MESSAGE
SkipCiPushOptionEnabled bool // override with MOB_SKIP_CI_PUSH_OPTION_ENABLED
GitHooksEnabled bool // override with MOB_GIT_HOOKS_ENABLED
RequireCommitMessage bool // override with MOB_REQUIRE_COMMIT_MESSAGE
VoiceCommand string // override with MOB_VOICE_COMMAND
Expand Down Expand Up @@ -75,6 +76,7 @@ func Config(c Configuration) {
say.Say("MOB_REMOTE_NAME" + "=" + quote(c.RemoteName))
say.Say("MOB_WIP_COMMIT_MESSAGE" + "=" + quote(c.WipCommitMessage))
say.Say("MOB_START_COMMIT_MESSAGE" + "=" + quote(c.StartCommitMessage))
say.Say("MOB_SKIP_CI_PUSH_OPTION_ENABLED" + "=" + strconv.FormatBool(c.SkipCiPushOptionEnabled))
say.Say("MOB_GIT_HOOKS_ENABLED" + "=" + strconv.FormatBool(c.GitHooksEnabled))
say.Say("MOB_REQUIRE_COMMIT_MESSAGE" + "=" + strconv.FormatBool(c.RequireCommitMessage))
say.Say("MOB_VOICE_COMMAND" + "=" + quote(c.VoiceCommand))
Expand Down Expand Up @@ -181,6 +183,7 @@ func GetDefaultConfiguration() Configuration {
RemoteName: "origin",
WipCommitMessage: "mob next [ci-skip] [ci skip] [skip ci]",
StartCommitMessage: "mob start [ci-skip] [ci skip] [skip ci]",
SkipCiPushOptionEnabled: true,
GitHooksEnabled: false,
VoiceCommand: voiceCommand,
VoiceMessage: "mob next",
Expand Down Expand Up @@ -237,6 +240,8 @@ func parseUserConfiguration(configuration Configuration, path string) Configurat
setUnquotedString(&configuration.WipCommitMessage, key, value)
case "MOB_START_COMMIT_MESSAGE":
setUnquotedString(&configuration.StartCommitMessage, key, value)
case "MOB_SKIP_CI_PUSH_OPTION_ENABLED":
setBoolean(&configuration.SkipCiPushOptionEnabled, key, value)
case "MOB_GIT_HOOKS_ENABLED":
setBoolean(&configuration.GitHooksEnabled, key, value)
case "MOB_REQUIRE_COMMIT_MESSAGE":
Expand Down Expand Up @@ -328,6 +333,8 @@ func parseProjectConfiguration(configuration Configuration, path string) Configu
setUnquotedString(&configuration.WipCommitMessage, key, value)
case "MOB_START_COMMIT_MESSAGE":
setUnquotedString(&configuration.StartCommitMessage, key, value)
case "MOB_SKIP_CI_PUSH_OPTION_ENABLED":
setBoolean(&configuration.SkipCiPushOptionEnabled, key, value)
case "MOB_GIT_HOOKS_ENABLED":
setBoolean(&configuration.GitHooksEnabled, key, value)
case "MOB_REQUIRE_COMMIT_MESSAGE":
Expand Down Expand Up @@ -420,10 +427,12 @@ func parseEnvironmentVariables(configuration Configuration) Configuration {
removed("MOB_WIP_BRANCH", "Use '"+configuration.Mob("start --branch <branch>")+"' instead.")
removed("MOB_START_INCLUDE_UNCOMMITTED_CHANGES", "Use the parameter --include-uncommitted-changes instead.")
experimental("MOB_WIP_BRANCH_PREFIX")
deprecated("MOB_START_COMMIT_MESSAGE", "Please check that everybody you work with uses version 5.0.0 or higher. Then this environment variable can be unset, as it will not have an impact anymore.")

setStringFromEnvVariable(&configuration.RemoteName, "MOB_REMOTE_NAME")
setStringFromEnvVariable(&configuration.WipCommitMessage, "MOB_WIP_COMMIT_MESSAGE")
setStringFromEnvVariable(&configuration.StartCommitMessage, "MOB_START_COMMIT_MESSAGE")
setBoolFromEnvVariable(&configuration.SkipCiPushOptionEnabled, "MOB_SKIP_CI_PUSH_OPTION_ENABLED")
setBoolFromEnvVariable(&configuration.GitHooksEnabled, "MOB_GIT_HOOKS_ENABLED")
setBoolFromEnvVariable(&configuration.RequireCommitMessage, "MOB_REQUIRE_COMMIT_MESSAGE")
setOptionalStringFromEnvVariable(&configuration.VoiceCommand, "MOB_VOICE_COMMAND")
Expand Down
72 changes: 70 additions & 2 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ func TestParseRequireCommitMessageEnvVariables(t *testing.T) {
test.Equals(t, true, configuration.RequireCommitMessage)
}

func TestReadConfigurationFromFileOverrideEverything(t *testing.T) {
say.TurnOnDebugging()
func TestReadUserConfigurationFromFileOverrideEverything(t *testing.T) {
tempDir = t.TempDir()
test.SetWorkingDir(tempDir)

Expand All @@ -210,6 +209,7 @@ func TestReadConfigurationFromFileOverrideEverything(t *testing.T) {
MOB_REMOTE_NAME="gitlab"
MOB_WIP_COMMIT_MESSAGE="team next"
MOB_START_COMMIT_MESSAGE="mob: start"
MOB_SKIP_CI_PUSH_OPTION_ENABLED=false
MOB_REQUIRE_COMMIT_MESSAGE=true
MOB_VOICE_COMMAND="whisper \"%s\""
MOB_VOICE_MESSAGE="team next"
Expand All @@ -235,6 +235,7 @@ func TestReadConfigurationFromFileOverrideEverything(t *testing.T) {
test.Equals(t, "gitlab", actualConfiguration.RemoteName)
test.Equals(t, "team next", actualConfiguration.WipCommitMessage)
test.Equals(t, "mob: start", actualConfiguration.StartCommitMessage)
test.Equals(t, false, actualConfiguration.SkipCiPushOptionEnabled)
test.Equals(t, true, actualConfiguration.RequireCommitMessage)
test.Equals(t, "whisper \"%s\"", actualConfiguration.VoiceCommand)
test.Equals(t, "team next", actualConfiguration.VoiceMessage)
Expand All @@ -260,6 +261,73 @@ func TestReadConfigurationFromFileOverrideEverything(t *testing.T) {
test.Equals(t, "Room\"\"_42", actualConfiguration1.TimerRoom)
}

func TestReadProjectConfigurationFromFileOverrideEverything(t *testing.T) {
output := test.CaptureOutput(t)
tempDir = t.TempDir()
test.SetWorkingDir(tempDir)

test.CreateFile(t, ".mob", `
MOB_CLI_NAME="team"
MOB_REMOTE_NAME="gitlab"
MOB_WIP_COMMIT_MESSAGE="team next"
MOB_START_COMMIT_MESSAGE="mob: start"
MOB_SKIP_CI_PUSH_OPTION_ENABLED=false
MOB_REQUIRE_COMMIT_MESSAGE=true
MOB_VOICE_COMMAND="whisper \"%s\""
MOB_VOICE_MESSAGE="team next"
MOB_NOTIFY_COMMAND="/usr/bin/osascript -e 'display notification \"%s!!!\"'"
MOB_NOTIFY_MESSAGE="team next"
MOB_NEXT_STAY=false
MOB_START_CREATE=true
MOB_WIP_BRANCH_QUALIFIER="green"
MOB_WIP_BRANCH_QUALIFIER_SEPARATOR="---"
MOB_WIP_BRANCH_PREFIX="ensemble/"
MOB_DONE_SQUASH=no-squash
MOB_OPEN_COMMAND="idea %s"
MOB_TIMER="123"
MOB_TIMER_ROOM="Room_42"
MOB_TIMER_ROOM_USE_WIP_BRANCH_QUALIFIER=true
MOB_TIMER_LOCAL=false
MOB_TIMER_USER="Mona"
MOB_TIMER_URL="https://timer.innoq.io/"
MOB_STASH_NAME="team-stash-name"
`)
actualConfiguration := parseProjectConfiguration(GetDefaultConfiguration(), tempDir+"/.mob")
test.Equals(t, "team", actualConfiguration.CliName)
test.Equals(t, "gitlab", actualConfiguration.RemoteName)
test.Equals(t, "team next", actualConfiguration.WipCommitMessage)
test.Equals(t, "mob: start", actualConfiguration.StartCommitMessage)
test.Equals(t, false, actualConfiguration.SkipCiPushOptionEnabled)
test.Equals(t, true, actualConfiguration.RequireCommitMessage)
test.NotEquals(t, "whisper \"%s\"", actualConfiguration.VoiceCommand)
test.NotEquals(t, "team next", actualConfiguration.VoiceMessage)
test.NotEquals(t, "/usr/bin/osascript -e 'display notification \"%s!!!\"'", actualConfiguration.NotifyCommand)
test.NotEquals(t, "team next", actualConfiguration.NotifyMessage)
test.Equals(t, false, actualConfiguration.NextStay)
test.Equals(t, true, actualConfiguration.StartCreate)
test.Equals(t, "green", actualConfiguration.WipBranchQualifier)
test.Equals(t, "---", actualConfiguration.WipBranchQualifierSeparator)
test.Equals(t, "ensemble/", actualConfiguration.WipBranchPrefix)
test.Equals(t, NoSquash, actualConfiguration.DoneSquash)
test.NotEquals(t, "idea %s", actualConfiguration.OpenCommand)
test.Equals(t, "123", actualConfiguration.Timer)
test.Equals(t, "Room_42", actualConfiguration.TimerRoom)
test.Equals(t, true, actualConfiguration.TimerRoomUseWipBranchQualifier)
test.Equals(t, false, actualConfiguration.TimerLocal)
test.Equals(t, "Mona", actualConfiguration.TimerUser)
test.Equals(t, "https://timer.innoq.io/", actualConfiguration.TimerUrl)
test.Equals(t, "team-stash-name", actualConfiguration.StashName)

test.CreateFile(t, ".mob", "\nMOB_TIMER_ROOM=\"Room\\\"\\\"_42\"\n")
actualConfiguration1 := parseUserConfiguration(GetDefaultConfiguration(), tempDir+"/.mob")
test.Equals(t, "Room\"\"_42", actualConfiguration1.TimerRoom)
test.AssertOutputContains(t, output, "Skipped overwriting key MOB_VOICE_COMMAND from project/.mob file out of security reasons!")
test.AssertOutputContains(t, output, "Skipped overwriting key MOB_VOICE_MESSAGE from project/.mob file out of security reasons!")
test.AssertOutputContains(t, output, "Skipped overwriting key MOB_NOTIFY_COMMAND from project/.mob file out of security reasons!")
test.AssertOutputContains(t, output, "Skipped overwriting key MOB_NOTIFY_MESSAGE from project/.mob file out of security reasons!")
test.AssertOutputContains(t, output, "Skipped overwriting key MOB_OPEN_COMMAND from project/.mob file out of security reasons!")
}

func TestReadConfigurationFromFileWithNonBooleanQuotedDoneSquashValue(t *testing.T) {
say.TurnOnDebugging()
tempDir = t.TempDir()
Expand Down
15 changes: 8 additions & 7 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,15 +735,16 @@ func startNewMobSession(configuration config.Configuration) {

say.Info("starting new session from " + currentBaseBranch.remote(configuration).String())
git("checkout", "-B", currentWipBranch.Name, currentBaseBranch.remote(configuration).Name)
gitPush(gitHooksOption(configuration), "--set-upstream", configuration.RemoteName, currentWipBranch.Name+":"+currentWipBranch.Name)
gitWithoutEmptyStrings(append(gitPushArgs(configuration), gitHooksOption(configuration), "--set-upstream", configuration.RemoteName, currentWipBranch.Name+":"+currentWipBranch.Name)...)
}

func gitPush(args ...string) {
gitWithoutEmptyStrings(pushArgs(args)...)
}

func pushArgs(args []string) []string {
return append([]string{"push"}, deleteEmptyStrings(args)...)
func gitPushArgs(c config.Configuration) []string {
pushArgs := []string{"push"}
if c.SkipCiPushOptionEnabled {
return pushArgs
} else {
return append(pushArgs, "--push-option", "ci.skip")
}
}

func getUntrackedFiles() string {
Expand Down
7 changes: 7 additions & 0 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func Equals(t *testing.T, exp, act interface{}) {
}
}

func NotEquals(t *testing.T, exp, act interface{}) {
if reflect.DeepEqual(exp, act) {
t.Log(string(debug.Stack()))
failWithFailure(t, exp, act)
}
}

func failWithFailure(t *testing.T, exp interface{}, act interface{}) {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
Expand Down

0 comments on commit cb27110

Please sign in to comment.