finish

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

cmd/factory/finish/finish.go

Index

Constants

This section is empty.

Variables

View Source
var FinishCmd = &cobra.Command{
	Use: "finish",
	RunE: func(cmd *cobra.Command, _ []string) error {
		presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr())
		ctx := cmd.Context()

		presenter.Summary("Finishing work on the current branch.")

		gitClient, err := git.NewClient(
			ctx,
			".",
			git.GitClientConfig{
				Logger:   globals.AppLogger,
				Executor: globals.ExecClient.UnderlyingExecutor(),
			},
		)
		if err != nil {
			return err
		}

		currentBranch, err := gitClient.GetCurrentBranchName(ctx)
		if err != nil {
			return err
		}
		if currentBranch == gitClient.MainBranchName() {
			return errors.New("cannot create a pull request from the main branch")
		}

		if err := gitClient.Push(ctx, currentBranch); err != nil {
			return err
		}

		if !globals.ExecClient.CommandExists("gh") {
			presenter.Warning("GitHub CLI ('gh') not found. Cannot create PR automatically.")

			return nil
		}

		confirmed, err := presenter.PromptForConfirmation("Create a GitHub Pull Request now?")
		if err != nil {
			return err
		}
		if !confirmed {
			presenter.Info("Aborted. You can create the PR later by running 'gh pr create'.")

			return nil
		}

		presenter.Step("Running 'gh pr create'...")
		if err := globals.ExecClient.Execute(ctx, ".", "gh", "pr", "create", "--fill", "--web"); err != nil {
			return err
		}

		presenter.Success("Pull Request created.")

		return nil
	},
}

FinishCmd represents the finish command.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL