From 34d1fb3e638fdc37bde7472454214532e0f78a6c Mon Sep 17 00:00:00 2001 From: Kynan Ware <47394200+BagToad@users.noreply.github.com> Date: Wed, 4 Mar 2026 15:53:48 -0700 Subject: [PATCH] Add godoc comments to exported symbols in pkg/cmd/repo Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- pkg/cmd/repo/archive/archive.go | 2 ++ pkg/cmd/repo/autolink/autolink.go | 1 + pkg/cmd/repo/autolink/create/create.go | 2 ++ pkg/cmd/repo/autolink/create/http.go | 3 +++ pkg/cmd/repo/autolink/delete/delete.go | 2 ++ pkg/cmd/repo/autolink/delete/http.go | 2 ++ pkg/cmd/repo/autolink/list/http.go | 2 ++ pkg/cmd/repo/autolink/list/list.go | 2 ++ pkg/cmd/repo/autolink/shared/autolink.go | 3 +++ pkg/cmd/repo/autolink/view/http.go | 2 ++ pkg/cmd/repo/autolink/view/view.go | 2 ++ pkg/cmd/repo/clone/clone.go | 2 ++ pkg/cmd/repo/create/create.go | 2 ++ pkg/cmd/repo/create/http.go | 1 + pkg/cmd/repo/credits/credits.go | 3 +++ pkg/cmd/repo/delete/delete.go | 2 ++ pkg/cmd/repo/deploy-key/add/add.go | 2 ++ pkg/cmd/repo/deploy-key/delete/delete.go | 2 ++ pkg/cmd/repo/deploy-key/deploy-key.go | 1 + pkg/cmd/repo/deploy-key/list/list.go | 2 ++ pkg/cmd/repo/edit/edit.go | 5 +++++ pkg/cmd/repo/fork/fork.go | 2 ++ pkg/cmd/repo/garden/garden.go | 13 +++++++++++++ pkg/cmd/repo/gitignore/gitignore.go | 1 + pkg/cmd/repo/gitignore/list/list.go | 2 ++ pkg/cmd/repo/gitignore/view/view.go | 2 ++ pkg/cmd/repo/license/license.go | 1 + pkg/cmd/repo/license/list/list.go | 2 ++ pkg/cmd/repo/license/view/view.go | 2 ++ pkg/cmd/repo/list/http.go | 2 ++ pkg/cmd/repo/list/list.go | 2 ++ pkg/cmd/repo/rename/rename.go | 2 ++ pkg/cmd/repo/repo.go | 1 + pkg/cmd/repo/setdefault/setdefault.go | 2 ++ pkg/cmd/repo/sync/git.go | 9 +++++++++ pkg/cmd/repo/sync/mocks.go | 9 +++++++++ pkg/cmd/repo/sync/sync.go | 2 ++ pkg/cmd/repo/unarchive/unarchive.go | 2 ++ pkg/cmd/repo/view/http.go | 3 +++ pkg/cmd/repo/view/view.go | 2 ++ 40 files changed, 106 insertions(+) diff --git a/pkg/cmd/repo/archive/archive.go b/pkg/cmd/repo/archive/archive.go index 86e1a6df7..35f429cb0 100644 --- a/pkg/cmd/repo/archive/archive.go +++ b/pkg/cmd/repo/archive/archive.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/cobra" ) +// ArchiveOptions holds the options for the archive command. type ArchiveOptions struct { HttpClient func() (*http.Client, error) Config func() (gh.Config, error) @@ -26,6 +27,7 @@ type ArchiveOptions struct { Prompter prompter.Prompter } +// NewCmdArchive creates a new command to archive a repository. func NewCmdArchive(f *cmdutil.Factory, runF func(*ArchiveOptions) error) *cobra.Command { opts := &ArchiveOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/autolink/autolink.go b/pkg/cmd/repo/autolink/autolink.go index b4f7c6839..c525f0dd7 100644 --- a/pkg/cmd/repo/autolink/autolink.go +++ b/pkg/cmd/repo/autolink/autolink.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" ) +// NewCmdAutolink creates a new command for managing repository autolinks. func NewCmdAutolink(f *cmdutil.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "autolink ", diff --git a/pkg/cmd/repo/autolink/create/create.go b/pkg/cmd/repo/autolink/create/create.go index f06ad5cf9..e7518b3cd 100644 --- a/pkg/cmd/repo/autolink/create/create.go +++ b/pkg/cmd/repo/autolink/create/create.go @@ -24,10 +24,12 @@ type createOptions struct { Numeric bool } +// AutolinkCreateClient defines the interface for creating autolinks. type AutolinkCreateClient interface { Create(repo ghrepo.Interface, request AutolinkCreateRequest) (*shared.Autolink, error) } +// NewCmdCreate creates a new command to create repository autolinks. func NewCmdCreate(f *cmdutil.Factory, runF func(*createOptions) error) *cobra.Command { opts := &createOptions{ Browser: f.Browser, diff --git a/pkg/cmd/repo/autolink/create/http.go b/pkg/cmd/repo/autolink/create/http.go index 5f187319f..716b9a4be 100644 --- a/pkg/cmd/repo/autolink/create/http.go +++ b/pkg/cmd/repo/autolink/create/http.go @@ -13,16 +13,19 @@ import ( "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" ) +// AutolinkCreator is an HTTP client for creating autolinks. type AutolinkCreator struct { HTTPClient *http.Client } +// AutolinkCreateRequest contains the parameters for creating an autolink. type AutolinkCreateRequest struct { IsAlphanumeric bool `json:"is_alphanumeric"` KeyPrefix string `json:"key_prefix"` URLTemplate string `json:"url_template"` } +// Create sends a request to create an autolink for the given repository. func (a *AutolinkCreator) Create(repo ghrepo.Interface, request AutolinkCreateRequest) (*shared.Autolink, error) { path := fmt.Sprintf("repos/%s/%s/autolinks", repo.RepoOwner(), repo.RepoName()) url := ghinstance.RESTPrefix(repo.RepoHost()) + path diff --git a/pkg/cmd/repo/autolink/delete/delete.go b/pkg/cmd/repo/autolink/delete/delete.go index e5cd874fb..3578eb7a5 100644 --- a/pkg/cmd/repo/autolink/delete/delete.go +++ b/pkg/cmd/repo/autolink/delete/delete.go @@ -24,10 +24,12 @@ type deleteOptions struct { Prompter prompter.Prompter } +// AutolinkDeleteClient defines the interface for deleting autolinks. type AutolinkDeleteClient interface { Delete(repo ghrepo.Interface, id string) error } +// NewCmdDelete creates a new command to delete repository autolinks. func NewCmdDelete(f *cmdutil.Factory, runF func(*deleteOptions) error) *cobra.Command { opts := &deleteOptions{ Browser: f.Browser, diff --git a/pkg/cmd/repo/autolink/delete/http.go b/pkg/cmd/repo/autolink/delete/http.go index d6bc53e84..f2bb9a4b1 100644 --- a/pkg/cmd/repo/autolink/delete/http.go +++ b/pkg/cmd/repo/autolink/delete/http.go @@ -9,10 +9,12 @@ import ( "github.com/cli/cli/v2/internal/ghrepo" ) +// AutolinkDeleter is an HTTP client for deleting autolinks. type AutolinkDeleter struct { HTTPClient *http.Client } +// Delete removes an autolink from the given repository by ID. func (a *AutolinkDeleter) Delete(repo ghrepo.Interface, id string) error { path := fmt.Sprintf("repos/%s/%s/autolinks/%s", repo.RepoOwner(), repo.RepoName(), id) url := ghinstance.RESTPrefix(repo.RepoHost()) + path diff --git a/pkg/cmd/repo/autolink/list/http.go b/pkg/cmd/repo/autolink/list/http.go index cdb8e621c..e350034d6 100644 --- a/pkg/cmd/repo/autolink/list/http.go +++ b/pkg/cmd/repo/autolink/list/http.go @@ -11,10 +11,12 @@ import ( "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" ) +// AutolinkLister is an HTTP client for listing autolinks. type AutolinkLister struct { HTTPClient *http.Client } +// List retrieves all autolinks for the given repository. func (a *AutolinkLister) List(repo ghrepo.Interface) ([]shared.Autolink, error) { path := fmt.Sprintf("repos/%s/%s/autolinks", repo.RepoOwner(), repo.RepoName()) url := ghinstance.RESTPrefix(repo.RepoHost()) + path diff --git a/pkg/cmd/repo/autolink/list/list.go b/pkg/cmd/repo/autolink/list/list.go index fb726d369..3eb5af43e 100644 --- a/pkg/cmd/repo/autolink/list/list.go +++ b/pkg/cmd/repo/autolink/list/list.go @@ -25,10 +25,12 @@ type listOptions struct { WebMode bool } +// AutolinkListClient defines the interface for listing autolinks. type AutolinkListClient interface { List(repo ghrepo.Interface) ([]shared.Autolink, error) } +// NewCmdList creates a new command to list repository autolinks. func NewCmdList(f *cmdutil.Factory, runF func(*listOptions) error) *cobra.Command { opts := &listOptions{ Browser: f.Browser, diff --git a/pkg/cmd/repo/autolink/shared/autolink.go b/pkg/cmd/repo/autolink/shared/autolink.go index 28e975e7c..8169e4bad 100644 --- a/pkg/cmd/repo/autolink/shared/autolink.go +++ b/pkg/cmd/repo/autolink/shared/autolink.go @@ -2,6 +2,7 @@ package shared import "github.com/cli/cli/v2/pkg/cmdutil" +// Autolink represents a repository autolink reference. type Autolink struct { ID int `json:"id"` IsAlphanumeric bool `json:"is_alphanumeric"` @@ -9,6 +10,7 @@ type Autolink struct { URLTemplate string `json:"url_template"` } +// AutolinkFields defines the set of fields available for autolink export. var AutolinkFields = []string{ "id", "isAlphanumeric", @@ -16,6 +18,7 @@ var AutolinkFields = []string{ "urlTemplate", } +// ExportData returns a map of the requested fields for JSON export. func (a *Autolink) ExportData(fields []string) map[string]interface{} { return cmdutil.StructExportData(a, fields) } diff --git a/pkg/cmd/repo/autolink/view/http.go b/pkg/cmd/repo/autolink/view/http.go index cc5638613..4d8f40e8f 100644 --- a/pkg/cmd/repo/autolink/view/http.go +++ b/pkg/cmd/repo/autolink/view/http.go @@ -11,10 +11,12 @@ import ( "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" ) +// AutolinkViewer is an HTTP client for viewing autolinks. type AutolinkViewer struct { HTTPClient *http.Client } +// View retrieves a single autolink by ID from the given repository. func (a *AutolinkViewer) View(repo ghrepo.Interface, id string) (*shared.Autolink, error) { path := fmt.Sprintf("repos/%s/%s/autolinks/%s", repo.RepoOwner(), repo.RepoName(), id) url := ghinstance.RESTPrefix(repo.RepoHost()) + path diff --git a/pkg/cmd/repo/autolink/view/view.go b/pkg/cmd/repo/autolink/view/view.go index f146cd25b..f220a4223 100644 --- a/pkg/cmd/repo/autolink/view/view.go +++ b/pkg/cmd/repo/autolink/view/view.go @@ -21,10 +21,12 @@ type viewOptions struct { ID string } +// AutolinkViewClient defines the interface for viewing autolinks. type AutolinkViewClient interface { View(repo ghrepo.Interface, id string) (*shared.Autolink, error) } +// NewCmdView creates a new command to view a repository autolink. func NewCmdView(f *cmdutil.Factory, runF func(*viewOptions) error) *cobra.Command { opts := &viewOptions{ Browser: f.Browser, diff --git a/pkg/cmd/repo/clone/clone.go b/pkg/cmd/repo/clone/clone.go index b29b25038..afa619323 100644 --- a/pkg/cmd/repo/clone/clone.go +++ b/pkg/cmd/repo/clone/clone.go @@ -18,6 +18,7 @@ import ( "github.com/spf13/pflag" ) +// CloneOptions holds the options for the clone command. type CloneOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client @@ -30,6 +31,7 @@ type CloneOptions struct { NoUpstream bool } +// NewCmdClone creates a new command to clone a repository. func NewCmdClone(f *cmdutil.Factory, runF func(*CloneOptions) error) *cobra.Command { opts := &CloneOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/create/create.go b/pkg/cmd/repo/create/create.go index be0be2ddd..a3a8cef34 100644 --- a/pkg/cmd/repo/create/create.go +++ b/pkg/cmd/repo/create/create.go @@ -35,6 +35,7 @@ type iprompter interface { Confirm(string, bool) (bool, error) } +// CreateOptions holds the options for the create command. type CreateOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client @@ -65,6 +66,7 @@ type CreateOptions struct { AddReadme bool } +// NewCmdCreate creates a new command to create a repository. func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command { opts := &CreateOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/create/http.go b/pkg/cmd/repo/create/http.go index 725fc48c5..48d6f8215 100644 --- a/pkg/cmd/repo/create/http.go +++ b/pkg/cmd/repo/create/http.go @@ -248,6 +248,7 @@ type ownerResponse struct { Type string `json:"type"` } +// IsOrganization reports whether the owner is an organization. func (r *ownerResponse) IsOrganization() bool { return r.Type == "Organization" } diff --git a/pkg/cmd/repo/credits/credits.go b/pkg/cmd/repo/credits/credits.go index a26b6a731..83824b6e7 100644 --- a/pkg/cmd/repo/credits/credits.go +++ b/pkg/cmd/repo/credits/credits.go @@ -21,6 +21,7 @@ import ( "github.com/spf13/cobra" ) +// CreditsOptions holds the options for the credits command. type CreditsOptions struct { HttpClient func() (*http.Client, error) BaseRepo func() (ghrepo.Interface, error) @@ -30,6 +31,7 @@ type CreditsOptions struct { Static bool } +// NewCmdCredits creates a new command to view repository credits. func NewCmdCredits(f *cmdutil.Factory, runF func(*CreditsOptions) error) *cobra.Command { opts := &CreditsOptions{ HttpClient: f.HttpClient, @@ -68,6 +70,7 @@ func NewCmdCredits(f *cmdutil.Factory, runF func(*CreditsOptions) error) *cobra. return cmd } +// NewCmdRepoCredits creates a new command to view repository contributor credits. func NewCmdRepoCredits(f *cmdutil.Factory, runF func(*CreditsOptions) error) *cobra.Command { opts := &CreditsOptions{ HttpClient: f.HttpClient, diff --git a/pkg/cmd/repo/delete/delete.go b/pkg/cmd/repo/delete/delete.go index 6724191da..acac43645 100644 --- a/pkg/cmd/repo/delete/delete.go +++ b/pkg/cmd/repo/delete/delete.go @@ -19,6 +19,7 @@ type iprompter interface { ConfirmDeletion(string) error } +// DeleteOptions holds the options for the delete command. type DeleteOptions struct { HttpClient func() (*http.Client, error) BaseRepo func() (ghrepo.Interface, error) @@ -28,6 +29,7 @@ type DeleteOptions struct { Confirmed bool } +// NewCmdDelete creates a new command to delete a repository. func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { opts := &DeleteOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/deploy-key/add/add.go b/pkg/cmd/repo/deploy-key/add/add.go index 2466ec98a..73ec9e5ad 100644 --- a/pkg/cmd/repo/deploy-key/add/add.go +++ b/pkg/cmd/repo/deploy-key/add/add.go @@ -13,6 +13,7 @@ import ( "github.com/spf13/cobra" ) +// AddOptions holds the options for the deploy key add command. type AddOptions struct { IO *iostreams.IOStreams HTTPClient func() (*http.Client, error) @@ -23,6 +24,7 @@ type AddOptions struct { AllowWrite bool } +// NewCmdAdd creates a new command to add a deploy key to a repository. func NewCmdAdd(f *cmdutil.Factory, runF func(*AddOptions) error) *cobra.Command { opts := &AddOptions{ HTTPClient: f.HttpClient, diff --git a/pkg/cmd/repo/deploy-key/delete/delete.go b/pkg/cmd/repo/deploy-key/delete/delete.go index a58b8957c..666a5b00d 100644 --- a/pkg/cmd/repo/deploy-key/delete/delete.go +++ b/pkg/cmd/repo/deploy-key/delete/delete.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" ) +// DeleteOptions holds the options for the deploy key delete command. type DeleteOptions struct { IO *iostreams.IOStreams HTTPClient func() (*http.Client, error) @@ -18,6 +19,7 @@ type DeleteOptions struct { KeyID string } +// NewCmdDelete creates a new command to delete a deploy key from a repository. func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { opts := &DeleteOptions{ HTTPClient: f.HttpClient, diff --git a/pkg/cmd/repo/deploy-key/deploy-key.go b/pkg/cmd/repo/deploy-key/deploy-key.go index 5a2aa8be5..982902e07 100644 --- a/pkg/cmd/repo/deploy-key/deploy-key.go +++ b/pkg/cmd/repo/deploy-key/deploy-key.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" ) +// NewCmdDeployKey creates a new command for managing repository deploy keys. func NewCmdDeployKey(f *cmdutil.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "deploy-key ", diff --git a/pkg/cmd/repo/deploy-key/list/list.go b/pkg/cmd/repo/deploy-key/list/list.go index 79d00c912..400b2e97e 100644 --- a/pkg/cmd/repo/deploy-key/list/list.go +++ b/pkg/cmd/repo/deploy-key/list/list.go @@ -13,6 +13,7 @@ import ( "github.com/spf13/cobra" ) +// ListOptions holds the options for the deploy key list command. type ListOptions struct { IO *iostreams.IOStreams HTTPClient func() (*http.Client, error) @@ -28,6 +29,7 @@ var deployKeyFields = []string{ "readOnly", } +// NewCmdList creates a new command to list deploy keys for a repository. func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { opts := &ListOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/edit/edit.go b/pkg/cmd/repo/edit/edit.go index d94f7a1d4..3b4be9b29 100644 --- a/pkg/cmd/repo/edit/edit.go +++ b/pkg/cmd/repo/edit/edit.go @@ -49,6 +49,7 @@ const ( optionWikis = "Wikis" ) +// EditOptions holds the options for the edit command. type EditOptions struct { HTTPClient *http.Client Repository ghrepo.Interface @@ -65,6 +66,7 @@ type EditOptions struct { topicsCache []string } +// EditRepositoryInput contains the fields that can be edited on a repository. type EditRepositoryInput struct { enableAdvancedSecurity *bool enableSecretScanning *bool @@ -89,6 +91,7 @@ type EditRepositoryInput struct { Visibility *string `json:"visibility,omitempty"` } +// NewCmdEdit creates a new command to edit repository settings. func NewCmdEdit(f *cmdutil.Factory, runF func(options *EditOptions) error) *cobra.Command { opts := &EditOptions{ IO: f.IOStreams, @@ -603,12 +606,14 @@ func hasSecurityEdits(edits EditRepositoryInput) bool { return edits.enableAdvancedSecurity != nil || edits.enableSecretScanning != nil || edits.enableSecretScanningPushProtection != nil } +// SecurityAndAnalysisInput holds settings for repository security and analysis features. type SecurityAndAnalysisInput struct { EnableAdvancedSecurity *SecurityAndAnalysisStatus `json:"advanced_security,omitempty"` EnableSecretScanning *SecurityAndAnalysisStatus `json:"secret_scanning,omitempty"` EnableSecretScanningPushProtection *SecurityAndAnalysisStatus `json:"secret_scanning_push_protection,omitempty"` } +// SecurityAndAnalysisStatus holds the status of a single security and analysis feature. type SecurityAndAnalysisStatus struct { Status *string `json:"status,omitempty"` } diff --git a/pkg/cmd/repo/fork/fork.go b/pkg/cmd/repo/fork/fork.go index 3ebb02413..369020271 100644 --- a/pkg/cmd/repo/fork/fork.go +++ b/pkg/cmd/repo/fork/fork.go @@ -29,6 +29,7 @@ type iprompter interface { Confirm(string, bool) (bool, error) } +// ForkOptions holds the options for the fork command. type ForkOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client @@ -61,6 +62,7 @@ type errWithExitCode interface { // TODO output over STDOUT not STDERR // TODO remote-name has no effect on its own; error that or change behavior +// NewCmdFork creates a new command to fork a repository. func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Command { opts := &ForkOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/garden/garden.go b/pkg/cmd/repo/garden/garden.go index d9342f9cb..e72b8380c 100644 --- a/pkg/cmd/repo/garden/garden.go +++ b/pkg/cmd/repo/garden/garden.go @@ -22,6 +22,7 @@ import ( "golang.org/x/term" ) +// Geometry represents the dimensions of the garden grid. type Geometry struct { Width int Height int @@ -29,6 +30,7 @@ type Geometry struct { Repository ghrepo.Interface } +// Player represents the user's position and trail in the garden. type Player struct { X int Y int @@ -37,6 +39,7 @@ type Player struct { ShoeMoistureContent int } +// Commit represents a git commit with its SHA and associated garden content. type Commit struct { Email string Handle string @@ -44,19 +47,26 @@ type Commit struct { Char string } +// Cell represents a single cell in the garden grid. type Cell struct { Char string StatusLine string } const ( + // DirUp is the upward movement direction. DirUp Direction = iota + // DirDown is the downward movement direction. DirDown + // DirLeft is the leftward movement direction. DirLeft + // DirRight is the rightward movement direction. DirRight + // Quit signals the player wants to exit the garden. Quit ) +// Direction represents a movement direction or quit action in the garden. type Direction = int func (p *Player) move(direction Direction) bool { @@ -86,6 +96,7 @@ func (p *Player) move(direction Direction) bool { return true } +// GardenOptions holds the options for the garden command. type GardenOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams @@ -95,6 +106,7 @@ type GardenOptions struct { RepoArg string } +// NewCmdGarden creates a new command to explore a contribution garden. func NewCmdGarden(f *cmdutil.Factory, runF func(*GardenOptions) error) *cobra.Command { opts := GardenOptions{ IO: f.IOStreams, @@ -503,6 +515,7 @@ func clear(io *iostreams.IOStreams) { _ = cmd.Run() } +// RGB returns the given string wrapped in ANSI escape codes for the specified RGB color. func RGB(r, g, b int, x string) string { return fmt.Sprintf("\033[38;2;%d;%d;%dm%s\033[0m", r, g, b, x) } diff --git a/pkg/cmd/repo/gitignore/gitignore.go b/pkg/cmd/repo/gitignore/gitignore.go index 8a9b8468e..f7cfdd9b7 100644 --- a/pkg/cmd/repo/gitignore/gitignore.go +++ b/pkg/cmd/repo/gitignore/gitignore.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" ) +// NewCmdGitIgnore creates a new command for managing gitignore templates. func NewCmdGitIgnore(f *cmdutil.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "gitignore ", diff --git a/pkg/cmd/repo/gitignore/list/list.go b/pkg/cmd/repo/gitignore/list/list.go index 89dbefaf3..b56a67e72 100644 --- a/pkg/cmd/repo/gitignore/list/list.go +++ b/pkg/cmd/repo/gitignore/list/list.go @@ -12,12 +12,14 @@ import ( "github.com/spf13/cobra" ) +// ListOptions holds the options for the gitignore list command. type ListOptions struct { IO *iostreams.IOStreams HTTPClient func() (*http.Client, error) Config func() (gh.Config, error) } +// NewCmdList creates a new command to list available gitignore templates. func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { opts := &ListOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/gitignore/view/view.go b/pkg/cmd/repo/gitignore/view/view.go index fcf83700a..18847a5ef 100644 --- a/pkg/cmd/repo/gitignore/view/view.go +++ b/pkg/cmd/repo/gitignore/view/view.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/cobra" ) +// ViewOptions holds the options for the gitignore view command. type ViewOptions struct { IO *iostreams.IOStreams HTTPClient func() (*http.Client, error) @@ -21,6 +22,7 @@ type ViewOptions struct { Template string } +// NewCmdView creates a new command to view a gitignore template. func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { opts := &ViewOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/license/license.go b/pkg/cmd/repo/license/license.go index 7d8db35b7..09d1f36d0 100644 --- a/pkg/cmd/repo/license/license.go +++ b/pkg/cmd/repo/license/license.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" ) +// NewCmdLicense creates a new command for managing license templates. func NewCmdLicense(f *cmdutil.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "license ", diff --git a/pkg/cmd/repo/license/list/list.go b/pkg/cmd/repo/license/list/list.go index ec003ad21..ca03e818c 100644 --- a/pkg/cmd/repo/license/list/list.go +++ b/pkg/cmd/repo/license/list/list.go @@ -13,12 +13,14 @@ import ( "github.com/spf13/cobra" ) +// ListOptions holds the options for the license list command. type ListOptions struct { IO *iostreams.IOStreams HTTPClient func() (*http.Client, error) Config func() (gh.Config, error) } +// NewCmdList creates a new command to list available license templates. func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { opts := &ListOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/license/view/view.go b/pkg/cmd/repo/license/view/view.go index 14228ba36..7b765631e 100644 --- a/pkg/cmd/repo/license/view/view.go +++ b/pkg/cmd/repo/license/view/view.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/cobra" ) +// ViewOptions holds the options for the license view command. type ViewOptions struct { IO *iostreams.IOStreams HTTPClient func() (*http.Client, error) @@ -25,6 +26,7 @@ type ViewOptions struct { Browser browser.Browser } +// NewCmdView creates a new command to view a license template. func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { opts := &ViewOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/list/http.go b/pkg/cmd/repo/list/http.go index d896c9224..3eae84222 100644 --- a/pkg/cmd/repo/list/http.go +++ b/pkg/cmd/repo/list/http.go @@ -11,6 +11,7 @@ import ( "github.com/cli/cli/v2/pkg/search" ) +// RepositoryList holds a paginated list of repositories. type RepositoryList struct { Owner string Repositories []api.Repository @@ -18,6 +19,7 @@ type RepositoryList struct { FromSearch bool } +// FilterOptions specifies filters for listing repositories. type FilterOptions struct { Visibility string // private, public, internal Fork bool diff --git a/pkg/cmd/repo/list/list.go b/pkg/cmd/repo/list/list.go index 07eff1d74..eebc75b17 100644 --- a/pkg/cmd/repo/list/list.go +++ b/pkg/cmd/repo/list/list.go @@ -18,6 +18,7 @@ import ( "github.com/cli/cli/v2/pkg/iostreams" ) +// ListOptions holds the options for the repo list command. type ListOptions struct { HttpClient func() (*http.Client, error) Config func() (gh.Config, error) @@ -39,6 +40,7 @@ type ListOptions struct { Now func() time.Time } +// NewCmdList creates a new command to list repositories. func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { opts := ListOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/rename/rename.go b/pkg/cmd/repo/rename/rename.go index 7a0c93da2..dbf506f7c 100644 --- a/pkg/cmd/repo/rename/rename.go +++ b/pkg/cmd/repo/rename/rename.go @@ -22,6 +22,7 @@ type iprompter interface { Confirm(string, bool) (bool, error) } +// RenameOptions holds the options for the rename command. type RenameOptions struct { HttpClient func() (*http.Client, error) GitClient *git.Client @@ -35,6 +36,7 @@ type RenameOptions struct { newRepoSelector string } +// NewCmdRename creates a new command to rename a repository. func NewCmdRename(f *cmdutil.Factory, runf func(*RenameOptions) error) *cobra.Command { opts := &RenameOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/repo.go b/pkg/cmd/repo/repo.go index 687cf5a8a..65dee6a93 100644 --- a/pkg/cmd/repo/repo.go +++ b/pkg/cmd/repo/repo.go @@ -25,6 +25,7 @@ import ( "github.com/spf13/cobra" ) +// NewCmdRepo creates a new command for managing repositories. func NewCmdRepo(f *cmdutil.Factory) *cobra.Command { cmd := &cobra.Command{ Use: "repo ", diff --git a/pkg/cmd/repo/setdefault/setdefault.go b/pkg/cmd/repo/setdefault/setdefault.go index d4abac309..6716f6c25 100644 --- a/pkg/cmd/repo/setdefault/setdefault.go +++ b/pkg/cmd/repo/setdefault/setdefault.go @@ -38,6 +38,7 @@ type iprompter interface { Select(string, string, []string) (int, error) } +// SetDefaultOptions holds the options for the set-default command. type SetDefaultOptions struct { IO *iostreams.IOStreams Remotes func() (context.Remotes, error) @@ -50,6 +51,7 @@ type SetDefaultOptions struct { UnsetMode bool } +// NewCmdSetDefault creates a new command to set the default repository. func NewCmdSetDefault(f *cmdutil.Factory, runF func(*SetDefaultOptions) error) *cobra.Command { opts := &SetDefaultOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/sync/git.go b/pkg/cmd/repo/sync/git.go index 0a0be1ed6..1b5a9183e 100644 --- a/pkg/cmd/repo/sync/git.go +++ b/pkg/cmd/repo/sync/git.go @@ -23,6 +23,7 @@ type gitExecuter struct { client *git.Client } +// UpdateBranch updates the given branch to point to the specified ref. func (g *gitExecuter) UpdateBranch(branch, ref string) error { cmd, err := g.client.Command(context.Background(), "update-ref", fmt.Sprintf("refs/heads/%s", branch), ref) if err != nil { @@ -32,6 +33,7 @@ func (g *gitExecuter) UpdateBranch(branch, ref string) error { return err } +// CreateBranch creates a new branch at the specified ref with the given upstream. func (g *gitExecuter) CreateBranch(branch, ref, upstream string) error { ctx := context.Background() cmd, err := g.client.Command(ctx, "branch", branch, ref) @@ -49,10 +51,12 @@ func (g *gitExecuter) CreateBranch(branch, ref, upstream string) error { return err } +// CurrentBranch returns the name of the currently checked-out branch. func (g *gitExecuter) CurrentBranch() (string, error) { return g.client.CurrentBranch(context.Background()) } +// Fetch fetches the specified ref from the given remote. func (g *gitExecuter) Fetch(remote, ref string) error { args := []string{"fetch", "-q", remote, ref} cmd, err := g.client.AuthenticatedCommand(context.Background(), git.AllMatchingCredentialsPattern, args...) @@ -62,10 +66,12 @@ func (g *gitExecuter) Fetch(remote, ref string) error { return cmd.Run() } +// HasLocalBranch reports whether the given local branch exists. func (g *gitExecuter) HasLocalBranch(branch string) bool { return g.client.HasLocalBranch(context.Background(), branch) } +// IsAncestor reports whether the ancestor commit is an ancestor of the progeny commit. func (g *gitExecuter) IsAncestor(ancestor, progeny string) (bool, error) { args := []string{"merge-base", "--is-ancestor", ancestor, progeny} cmd, err := g.client.Command(context.Background(), args...) @@ -76,6 +82,7 @@ func (g *gitExecuter) IsAncestor(ancestor, progeny string) (bool, error) { return err == nil, nil } +// IsDirty reports whether the working tree has uncommitted changes. func (g *gitExecuter) IsDirty() (bool, error) { changeCount, err := g.client.UncommittedChangeCount(context.Background()) if err != nil { @@ -84,6 +91,7 @@ func (g *gitExecuter) IsDirty() (bool, error) { return changeCount != 0, nil } +// MergeFastForward performs a fast-forward merge to the given ref. func (g *gitExecuter) MergeFastForward(ref string) error { args := []string{"merge", "--ff-only", "--quiet", ref} cmd, err := g.client.Command(context.Background(), args...) @@ -94,6 +102,7 @@ func (g *gitExecuter) MergeFastForward(ref string) error { return err } +// ResetHard performs a hard reset of the current branch to the given ref. func (g *gitExecuter) ResetHard(ref string) error { args := []string{"reset", "--hard", ref} cmd, err := g.client.Command(context.Background(), args...) diff --git a/pkg/cmd/repo/sync/mocks.go b/pkg/cmd/repo/sync/mocks.go index c852e03f2..24477aa1b 100644 --- a/pkg/cmd/repo/sync/mocks.go +++ b/pkg/cmd/repo/sync/mocks.go @@ -8,46 +8,55 @@ type mockGitClient struct { mock.Mock } +// UpdateBranch mocks updating the given branch to point to the specified ref. func (g *mockGitClient) UpdateBranch(b, r string) error { args := g.Called(b, r) return args.Error(0) } +// CreateBranch mocks creating a new branch at the specified ref. func (g *mockGitClient) CreateBranch(b, r, u string) error { args := g.Called(b, r, u) return args.Error(0) } +// CurrentBranch mocks returning the currently checked-out branch name. func (g *mockGitClient) CurrentBranch() (string, error) { args := g.Called() return args.String(0), args.Error(1) } +// Fetch mocks fetching a ref from a remote. func (g *mockGitClient) Fetch(a, b string) error { args := g.Called(a, b) return args.Error(0) } +// HasLocalBranch mocks checking whether a local branch exists. func (g *mockGitClient) HasLocalBranch(a string) bool { args := g.Called(a) return args.Bool(0) } +// IsAncestor mocks checking whether one commit is an ancestor of another. func (g *mockGitClient) IsAncestor(a, b string) (bool, error) { args := g.Called(a, b) return args.Bool(0), args.Error(1) } +// IsDirty mocks checking whether the working tree has uncommitted changes. func (g *mockGitClient) IsDirty() (bool, error) { args := g.Called() return args.Bool(0), args.Error(1) } +// MergeFastForward mocks performing a fast-forward merge. func (g *mockGitClient) MergeFastForward(a string) error { args := g.Called(a) return args.Error(0) } +// ResetHard mocks performing a hard reset to the given ref. func (g *mockGitClient) ResetHard(a string) error { args := g.Called(a) return args.Error(0) diff --git a/pkg/cmd/repo/sync/sync.go b/pkg/cmd/repo/sync/sync.go index b025d9eec..af6560edb 100644 --- a/pkg/cmd/repo/sync/sync.go +++ b/pkg/cmd/repo/sync/sync.go @@ -21,6 +21,7 @@ const ( branchDoesNotExistErrorMessage = "Reference does not exist" ) +// SyncOptions holds the options for the sync command. type SyncOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams @@ -33,6 +34,7 @@ type SyncOptions struct { Force bool } +// NewCmdSync creates a new command to sync a repository branch. func NewCmdSync(f *cmdutil.Factory, runF func(*SyncOptions) error) *cobra.Command { opts := SyncOptions{ HttpClient: f.HttpClient, diff --git a/pkg/cmd/repo/unarchive/unarchive.go b/pkg/cmd/repo/unarchive/unarchive.go index 74d84a779..7c08b458c 100644 --- a/pkg/cmd/repo/unarchive/unarchive.go +++ b/pkg/cmd/repo/unarchive/unarchive.go @@ -15,6 +15,7 @@ import ( "github.com/spf13/cobra" ) +// UnarchiveOptions holds the options for the unarchive command. type UnarchiveOptions struct { HttpClient func() (*http.Client, error) Config func() (gh.Config, error) @@ -25,6 +26,7 @@ type UnarchiveOptions struct { Prompter prompter.Prompter } +// NewCmdUnarchive creates a new command to unarchive a repository. func NewCmdUnarchive(f *cmdutil.Factory, runF func(*UnarchiveOptions) error) *cobra.Command { opts := &UnarchiveOptions{ IO: f.IOStreams, diff --git a/pkg/cmd/repo/view/http.go b/pkg/cmd/repo/view/http.go index 5988580e5..a237447f9 100644 --- a/pkg/cmd/repo/view/http.go +++ b/pkg/cmd/repo/view/http.go @@ -14,14 +14,17 @@ import ( "golang.org/x/text/transform" ) +// NotFoundError is returned when a repository or its readme is not found. var NotFoundError = errors.New("not found") +// RepoReadme holds the content and filename of a repository README. type RepoReadme struct { Filename string Content string BaseURL string } +// RepositoryReadme fetches the README for a repository on a given branch. func RepositoryReadme(client *http.Client, repo ghrepo.Interface, branch string) (*RepoReadme, error) { apiClient := api.NewClientFromHTTP(client) var response struct { diff --git a/pkg/cmd/repo/view/view.go b/pkg/cmd/repo/view/view.go index b13276c80..646e5bbd4 100644 --- a/pkg/cmd/repo/view/view.go +++ b/pkg/cmd/repo/view/view.go @@ -20,6 +20,7 @@ import ( "github.com/spf13/cobra" ) +// ViewOptions holds the options for the view command. type ViewOptions struct { HttpClient func() (*http.Client, error) IO *iostreams.IOStreams @@ -33,6 +34,7 @@ type ViewOptions struct { Branch string } +// NewCmdView creates a new command to view a repository. func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command { opts := ViewOptions{ IO: f.IOStreams,