add

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: 15 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 add provides the command to add issues to a project board.

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "Interactively add issues to a project board.",
	RunE: func(cmd *cobra.Command, _ []string) error {
		presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr())
		ctx := cmd.Context()

		ghClient, err := newGHClient(ctx, globals.AppLogger, globals.LoadedAppConfig)
		if err != nil {
			presenter.Error("Failed to initialize GitHub client: %v", err)

			return err
		}

		presenter.Summary("Step 1: Select a Project Board")
		projects, err := ghClient.ListProjects(ctx)
		if err != nil {
			presenter.Error("Failed to fetch project boards: %v", err)
			presenter.Advice(
				"Please ensure your GITHUB_TOKEN has the 'read:project' and 'write:project' scopes.",
			)

			return fmt.Errorf("failed to list projects: %w", err)
		}
		if len(projects) == 0 {
			presenter.Info("No project boards found.")

			return nil
		}
		projectOptions := make([]string, len(projects))
		for i, p := range projects {
			projectOptions[i] = fmt.Sprintf("#%d: %s", p.Number, p.Title)
		}
		selectedProjectStr, err := presenter.PromptForSelect(
			"Which project board do you want to add issues to?",
			projectOptions,
		)
		if err != nil {
			return fmt.Errorf("project selection failed: %w", err)
		}
		projectNumberStr := strings.Split(selectedProjectStr, ":")[0][1:]
		projectNumber, _ := strconv.Atoi(projectNumberStr)
		project, err := ghClient.GetProjectByNumber(ctx, projectNumber)
		if err != nil {
			presenter.Error("Failed to get details for project #%d: %v", projectNumber, err)

			return fmt.Errorf("failed to get project details: %w", err)
		}
		presenter.Success("✓ Selected board '%s'", project.Title)
		presenter.Newline()

		presenter.Summary("Step 2: Select Issues to Add")
		provider, err := newProvider(ctx, globals.AppLogger, globals.LoadedAppConfig)
		if err != nil {
			presenter.Error("Failed to initialize work item provider: %v", err)

			return err
		}

		listOpts := workitem.ListOptions{State: workitem.StateOpen, Limit: 100}
		issues, err := provider.ListItems(ctx, listOpts)
		if err != nil {
			presenter.Error("Failed to list open issues: %v", err)

			return fmt.Errorf("failed to list items: %w", err)
		}
		if len(issues) == 0 {
			presenter.Info("No open issues found to add.")

			return nil
		}
		issueOptions := make([]string, len(issues))
		for i, issue := range issues {
			issueOptions[i] = fmt.Sprintf("#%d: %s", issue.Number, issue.Title)
		}
		selectedIssueStrs, err := presenter.PromptForMultiSelect(
			"Which issues would you like to add?",
			issueOptions,
		)
		if err != nil {
			return fmt.Errorf("issue selection failed: %w", err)
		}
		if len(selectedIssueStrs) == 0 {
			presenter.Info("No issues selected. Aborting.")

			return nil
		}
		presenter.Newline()

		presenter.Summary(
			"Step 3: Adding %d Issue(s) to '%s'",
			len(selectedIssueStrs),
			project.Title,
		)
		for _, issueStr := range selectedIssueStrs {
			issueNumberStr := strings.Split(issueStr, ":")[0][1:]
			issueNumber, _ := strconv.Atoi(issueNumberStr)

			presenter.Step("Adding issue #%d...", issueNumber)
			item, err := provider.GetItem(ctx, issueNumber, false)
			if err != nil {
				presenter.Error("  ! Failed to get details for issue #%d: %v", issueNumber, err)

				continue
			}
			if item.ID == "" {
				presenter.Error("  ! Could not find GraphQL Node ID for issue #%d.", issueNumber)

				continue
			}

			err = ghClient.AddIssueToProject(ctx, project.ID, item.ID)
			if err != nil {
				presenter.Error("  ! Failed to add issue #%d to project: %v", issueNumber, err)
			} else {
				presenter.Success("  ✓ Successfully added issue #%d.", issueNumber)
			}
		}

		presenter.Newline()
		presenter.Success("Finished adding issues. View the board at: %s", project.URL)

		return nil
	},
}

AddCmd represents the project board add 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