finish

package
v0.6.0 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package finish provides the command to finish a feature branch.

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 fmt.Errorf("failed to initialize git client: %w", err)
		}

		currentBranch, err := gitClient.GetCurrentBranchName(ctx)
		if err != nil {
			return fmt.Errorf("failed to get current branch: %w", 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 fmt.Errorf("failed to push branch: %w", 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 fmt.Errorf("confirmation failed: %w", 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 fmt.Errorf("gh pr create failed: %w", 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