Skip to content

Commit 35ee6f9

Browse files
committed
Factor out commandBuilder
1 parent 0c8bbda commit 35ee6f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+8387
-739
lines changed

command/autoRebase.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ import (
1414
"sync"
1515
"syscall"
1616

17+
"github.com/guywithnose/commandBuilder"
1718
"github.com/guywithnose/pull-request-parser/config"
18-
"github.com/guywithnose/pull-request-parser/execWrapper"
1919
"github.com/urfave/cli"
2020
)
2121

2222
// CmdAutoRebase parses the pull requests
23-
func CmdAutoRebase(cmdWrapper execWrapper.CommandBuilder) func(*cli.Context) error {
23+
func CmdAutoRebase(cmdWrapper commandBuilder.Builder) func(*cli.Context) error {
2424
return func(c *cli.Context) error {
2525
return cmdAutoRebaseHelper(c, cmdWrapper)
2626
}
2727
}
2828

2929
// CmdAutoRebase parses the pull requests
30-
func cmdAutoRebaseHelper(c *cli.Context, cmdWrapper execWrapper.CommandBuilder) error {
30+
func cmdAutoRebaseHelper(c *cli.Context, cmdWrapper commandBuilder.Builder) error {
3131
configData, profileName, err := loadProfile(c)
3232
if err != nil {
3333
return err
@@ -152,7 +152,7 @@ func handleCompletion(c *cli.Context) {
152152
fmt.Fprintln(c.App.Writer, strings.Join(completions, "\n"))
153153
}
154154

155-
func rebasePullRequest(output *prInfo, errorWriter, verboseWriter io.Writer, cmdWrapper execWrapper.CommandBuilder) error {
155+
func rebasePullRequest(output *prInfo, errorWriter, verboseWriter io.Writer, cmdWrapper commandBuilder.Builder) error {
156156
path, ownedRemote, upstreamRemote, localChanges, err := getRepoData(output, verboseWriter, cmdWrapper)
157157
if err != nil {
158158
return err
@@ -178,7 +178,7 @@ func rebasePullRequest(output *prInfo, errorWriter, verboseWriter io.Writer, cmd
178178
return handleRebase(path, ownedRemote, upstreamRemote, tempBranch, output, verboseWriter, cmdWrapper)
179179
}
180180

181-
func handleRebase(path, ownedRemote, upstreamRemote, tempBranch string, output *prInfo, verboseWriter io.Writer, cmdWrapper execWrapper.CommandBuilder) error {
181+
func handleRebase(path, ownedRemote, upstreamRemote, tempBranch string, output *prInfo, verboseWriter io.Writer, cmdWrapper commandBuilder.Builder) error {
182182
myRemoteBranch := fmt.Sprintf("%s/%s", ownedRemote, output.Branch)
183183
fmt.Fprintf(verboseWriter, "Resetting code to %s\n", myRemoteBranch)
184184
err := runCommand(path, cmdWrapper, "git", "reset", "--hard", myRemoteBranch)
@@ -202,7 +202,7 @@ func handleRebase(path, ownedRemote, upstreamRemote, tempBranch string, output *
202202
return nil
203203
}
204204

205-
func fetchRemote(path, remoteName string, verboseWriter io.Writer, cmdWrapper execWrapper.CommandBuilder) error {
205+
func fetchRemote(path, remoteName string, verboseWriter io.Writer, cmdWrapper commandBuilder.Builder) error {
206206
fmt.Fprintf(verboseWriter, "Fetching from remote: %s\n", remoteName)
207207
err := runCommand(path, cmdWrapper, "git", "fetch", remoteName)
208208
if err != nil {
@@ -220,7 +220,7 @@ func wrapExitError(err error, extra string) error {
220220
return errors.New(extra)
221221
}
222222

223-
func checkoutTempBranch(path, branch string, verboseWriter io.Writer, cmdWrapper execWrapper.CommandBuilder) (string, string, error) {
223+
func checkoutTempBranch(path, branch string, verboseWriter io.Writer, cmdWrapper commandBuilder.Builder) (string, string, error) {
224224
fmt.Fprintln(verboseWriter, "Saving current branch name")
225225
currentBranchName, err := getCurrentBranch(path, cmdWrapper)
226226
if err != nil {
@@ -244,7 +244,7 @@ func checkoutTempBranch(path, branch string, verboseWriter io.Writer, cmdWrapper
244244
return currentBranchName, tempBranch, nil
245245
}
246246

247-
func getRepoData(output *prInfo, verboseWriter io.Writer, cmdWrapper execWrapper.CommandBuilder) (string, string, string, bool, error) {
247+
func getRepoData(output *prInfo, verboseWriter io.Writer, cmdWrapper commandBuilder.Builder) (string, string, string, bool, error) {
248248
fmt.Fprintln(verboseWriter, "Requesting repo data from config")
249249
if output.Repo.LocalPath == "" {
250250
return "", "", "", false, errors.New("Path was not set for this repo")
@@ -283,7 +283,7 @@ func getRepoData(output *prInfo, verboseWriter io.Writer, cmdWrapper execWrapper
283283
return output.Repo.LocalPath, ownedRemote, upstreamRemote, localChanges, nil
284284
}
285285

286-
func cleanUp(currentBranchName, tempBranch, path string, errorWriter, verboseWriter io.Writer, cmdWrapper execWrapper.CommandBuilder) {
286+
func cleanUp(currentBranchName, tempBranch, path string, errorWriter, verboseWriter io.Writer, cmdWrapper commandBuilder.Builder) {
287287
fmt.Fprintf(verboseWriter, "Going back to branch %s\n", currentBranchName)
288288
err := runCommand(path, cmdWrapper, "git", "checkout", currentBranchName)
289289
if err != nil {
@@ -298,15 +298,15 @@ func cleanUp(currentBranchName, tempBranch, path string, errorWriter, verboseWri
298298
}
299299
}
300300

301-
func popStash(path string, errorWriter, verboseWriter io.Writer, cmdWrapper execWrapper.CommandBuilder) {
301+
func popStash(path string, errorWriter, verboseWriter io.Writer, cmdWrapper commandBuilder.Builder) {
302302
fmt.Fprintln(verboseWriter, "Popping the stash")
303303
err := runCommand(path, cmdWrapper, "git", "stash", "pop")
304304
if err != nil {
305305
fmt.Fprintf(errorWriter, "%v\nWarning: Could not pop stash in %s\n", wrapExitError(err, ""), path)
306306
}
307307
}
308308

309-
func detectLocalChanges(path string, cmdWrapper execWrapper.CommandBuilder) (bool, error) {
309+
func detectLocalChanges(path string, cmdWrapper commandBuilder.Builder) (bool, error) {
310310
localChangesCommand := cmdWrapper.CreateCommand(path, "git", "diff-index", "--quiet", "HEAD")
311311
_, err := localChangesCommand.Output()
312312
if err != nil {
@@ -321,13 +321,13 @@ func detectLocalChanges(path string, cmdWrapper execWrapper.CommandBuilder) (boo
321321
return false, nil
322322
}
323323

324-
func runCommand(path string, cmdWrapper execWrapper.CommandBuilder, command ...string) error {
324+
func runCommand(path string, cmdWrapper commandBuilder.Builder, command ...string) error {
325325
cmd := cmdWrapper.CreateCommand(path, command...)
326326
_, err := cmd.Output()
327327
return err
328328
}
329329

330-
func getCurrentBranch(path string, cmdWrapper execWrapper.CommandBuilder) (string, error) {
330+
func getCurrentBranch(path string, cmdWrapper commandBuilder.Builder) (string, error) {
331331
getCurrentBranch := cmdWrapper.CreateCommand(path, "git", "symbolic-ref", "HEAD")
332332
currentBranchOutput, err := getCurrentBranch.CombinedOutput()
333333
if err != nil {
@@ -352,7 +352,7 @@ func getErrorCode(err error) int {
352352
return -1
353353
}
354354

355-
func getRemotes(path string, cmdWrapper execWrapper.CommandBuilder, output *prInfo) (string, string, error) {
355+
func getRemotes(path string, cmdWrapper commandBuilder.Builder, output *prInfo) (string, string, error) {
356356
getRemotes := cmdWrapper.CreateCommand(path, "git", "remote", "-v")
357357
remotesOutput, err := getRemotes.CombinedOutput()
358358
if err != nil {

0 commit comments

Comments
 (0)