Add godoc comments to exported symbols in pkg/cmd/variable
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
6b227a5599
commit
cbedf37b84
6 changed files with 52 additions and 4 deletions
|
|
@ -14,6 +14,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// DeleteOptions is documented here.
|
||||
// DeleteOptions holds the options for the variable delete command.
|
||||
type DeleteOptions struct {
|
||||
HttpClient func() (*http.Client, error)
|
||||
IO *iostreams.IOStreams
|
||||
|
|
@ -25,6 +27,9 @@ type DeleteOptions struct {
|
|||
EnvName string
|
||||
}
|
||||
|
||||
// NewCmdDelete is documented here.
|
||||
|
||||
// NewCmdDelete creates a new cobra command for deleting a variable.
|
||||
func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command {
|
||||
opts := &DeleteOptions{
|
||||
IO: f.IOStreams,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GetOptions is documented here.
|
||||
// GetOptions holds the options for the variable get command.
|
||||
type GetOptions struct {
|
||||
HttpClient func() (*http.Client, error)
|
||||
IO *iostreams.IOStreams
|
||||
|
|
@ -28,6 +30,9 @@ type GetOptions struct {
|
|||
EnvName string
|
||||
}
|
||||
|
||||
// NewCmdGet is documented here.
|
||||
|
||||
// NewCmdGet creates a new cobra command for retrieving a variable.
|
||||
func NewCmdGet(f *cmdutil.Factory, runF func(*GetOptions) error) *cobra.Command {
|
||||
opts := &GetOptions{
|
||||
IO: f.IOStreams,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// ListOptions is documented here.
|
||||
// ListOptions holds the options for the variable list command.
|
||||
type ListOptions struct {
|
||||
HttpClient func() (*http.Client, error)
|
||||
IO *iostreams.IOStreams
|
||||
|
|
@ -33,6 +35,9 @@ type ListOptions struct {
|
|||
|
||||
const fieldNumSelectedRepos = "numSelectedRepos"
|
||||
|
||||
// NewCmdList is documented here.
|
||||
|
||||
// NewCmdList creates a new cobra command for listing variables.
|
||||
func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command {
|
||||
opts := &ListOptions{
|
||||
IO: f.IOStreams,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ type iprompter interface {
|
|||
Input(string, string) (string, error)
|
||||
}
|
||||
|
||||
// SetOptions is documented here.
|
||||
// SetOptions holds the options for the variable set command.
|
||||
type SetOptions struct {
|
||||
HttpClient func() (*http.Client, error)
|
||||
IO *iostreams.IOStreams
|
||||
|
|
@ -40,6 +42,9 @@ type SetOptions struct {
|
|||
EnvFile string
|
||||
}
|
||||
|
||||
// NewCmdSet is documented here.
|
||||
|
||||
// NewCmdSet creates a new cobra command for setting a variable.
|
||||
func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command {
|
||||
opts := &SetOptions{
|
||||
IO: f.IOStreams,
|
||||
|
|
|
|||
|
|
@ -9,23 +9,41 @@ import (
|
|||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
)
|
||||
|
||||
// Visibility is documented here.
|
||||
// Visibility represents the visibility level of a variable.
|
||||
type Visibility string
|
||||
|
||||
// All is documented here.
|
||||
const (
|
||||
All = "all"
|
||||
Private = "private"
|
||||
// Private is documented here.
|
||||
// All indicates the variable is visible to all repositories.
|
||||
All = "all"
|
||||
// Private indicates the variable is visible only to private repositories.
|
||||
Private = "private"
|
||||
// VariableEntity is documented here.
|
||||
// Selected indicates the variable is visible to selected repositories.
|
||||
Selected = "selected"
|
||||
)
|
||||
|
||||
// Repository is documented here.
|
||||
|
||||
// Organization is documented here.
|
||||
// VariableEntity represents the scope of a variable (repository, organization, or environment).
|
||||
type VariableEntity string
|
||||
|
||||
const (
|
||||
Repository = "repository"
|
||||
// Variable is documented here.
|
||||
// Repository indicates a repository-level variable.
|
||||
Repository = "repository"
|
||||
// Organization indicates an organization-level variable.
|
||||
Organization = "organization"
|
||||
Environment = "environment"
|
||||
// Environment indicates an environment-level variable.
|
||||
Environment = "environment"
|
||||
)
|
||||
|
||||
// Variable represents a GitHub Actions variable and its metadata.
|
||||
type Variable struct {
|
||||
// VariableJSONFields is documented here.
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
|
@ -35,25 +53,30 @@ type Variable struct {
|
|||
NumSelectedRepos int `json:"num_selected_repos"`
|
||||
}
|
||||
|
||||
// VariableJSONFields lists the field names available for JSON export of a Variable.
|
||||
var VariableJSONFields = []string{
|
||||
"name",
|
||||
"value",
|
||||
"visibility",
|
||||
// GetVariableEntity is documented here.
|
||||
"updatedAt",
|
||||
"createdAt",
|
||||
"numSelectedRepos",
|
||||
"selectedReposURL",
|
||||
}
|
||||
|
||||
// ExportData returns the variable's fields as a map for structured output.
|
||||
func (v *Variable) ExportData(fields []string) map[string]interface{} {
|
||||
return cmdutil.StructExportData(v, fields)
|
||||
}
|
||||
|
||||
// GetVariableEntity determines the variable entity type based on the provided org and env names.
|
||||
func GetVariableEntity(orgName, envName string) (VariableEntity, error) {
|
||||
orgSet := orgName != ""
|
||||
envSet := envName != ""
|
||||
|
||||
if orgSet && envSet {
|
||||
// PopulateMultipleSelectedRepositoryInformation is documented here.
|
||||
return "", errors.New("cannot specify multiple variable entities")
|
||||
}
|
||||
|
||||
|
|
@ -64,8 +87,10 @@ func GetVariableEntity(orgName, envName string) (VariableEntity, error) {
|
|||
return Environment, nil
|
||||
}
|
||||
return Repository, nil
|
||||
// PopulateSelectedRepositoryInformation is documented here.
|
||||
}
|
||||
|
||||
// PopulateMultipleSelectedRepositoryInformation fills in selected repository counts for a slice of variables.
|
||||
func PopulateMultipleSelectedRepositoryInformation(apiClient *api.Client, host string, variables []Variable) error {
|
||||
for i, variable := range variables {
|
||||
if err := PopulateSelectedRepositoryInformation(apiClient, host, &variable); err != nil {
|
||||
|
|
@ -76,6 +101,7 @@ func PopulateMultipleSelectedRepositoryInformation(apiClient *api.Client, host s
|
|||
return nil
|
||||
}
|
||||
|
||||
// PopulateSelectedRepositoryInformation fills in the selected repository count for a single variable.
|
||||
func PopulateSelectedRepositoryInformation(apiClient *api.Client, host string, variable *Variable) error {
|
||||
if variable.SelectedReposURL == "" {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewCmdVariable is documented here.
|
||||
// NewCmdVariable creates a new cobra command for managing GitHub Actions variables.
|
||||
func NewCmdVariable(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "variable <command>",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue