api

package
v0.1.15384 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 19 Imported by: 12

Documentation

Overview

Go functions that expose the Context-related calls in the GraphQL API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOrRemoveOrbCategorization added in v0.1.9399

func AddOrRemoveOrbCategorization(cl *graphql.Client, namespace string, orb string, categoryName string, updateType UpdateOrbCategorizationRequestType) error

AddOrRemoveOrbCategorization adds or removes an orb categorization

func DeleteNamespaceAlias added in v0.1.11278

func DeleteNamespaceAlias(cl *graphql.Client, name string) error

func NamespaceExists added in v0.1.11062

func NamespaceExists(cl *graphql.Client, namespace string) (bool, error)

NamespaceExists returns a boolean indicating if the provided namespace exists.

func OrbExists added in v0.1.11062

func OrbExists(cl *graphql.Client, namespace string, orb string) (bool, error)

OrbExists checks whether an orb exists within the provided namespace.

func OrbLatestVersion added in v0.1.1813

func OrbLatestVersion(cl *graphql.Client, namespace string, orb string) (string, error)

OrbLatestVersion finds the latest published version of an orb and returns it. If it doesn't find a version, it will return 0.0.0 for the orb's version

func OrbSetOrbListStatus added in v0.1.5879

func OrbSetOrbListStatus(cl *graphql.Client, namespace string, orb string, list bool) (*bool, error)

OrbSetOrbListStatus sets whether an orb can be listed in the registry or not.

func OrbSource

func OrbSource(cl *graphql.Client, orbRef string) (string, error)

OrbSource gets the source of an orb

Types

type AddOrRemoveOrbCategorizationData added in v0.1.9399

type AddOrRemoveOrbCategorizationData struct {
	CategoryId string
	OrbId      string
	Errors     GQLErrorsCollection
}

type AddOrRemoveOrbCategorizationResponse added in v0.1.9399

type AddOrRemoveOrbCategorizationResponse map[string]AddOrRemoveOrbCategorizationData

AddOrRemoveOrbCategorizationResponse type matches the data shape of the GQL response for adding or removing an orb categorization

type BuildConfigResponse added in v0.1.2969

type BuildConfigResponse struct {
	BuildConfig struct {
		ConfigResponse
	}
}

BuildConfigResponse wraps the GQL result of the ConfigQuery

type ConfigResponse

type ConfigResponse struct {
	Valid      bool
	SourceYaml string
	OutputYaml string

	Errors GQLErrorsCollection
}

ConfigResponse is a structure that matches the result of the GQL query, so that we can use mapstructure to convert from nested maps to a strongly typed struct.

func ConfigQuery

func ConfigQuery(cl *graphql.Client, configPath string, orgSlug string, pipelineValues pipeline.Values) (*ConfigResponse, error)

ConfigQuery calls the GQL API to validate and process config

func OrbQuery

func OrbQuery(cl *graphql.Client, configPath string) (*ConfigResponse, error)

OrbQuery validated and processes an orb.

type Context added in v0.1.9321

type Context struct {
	CreatedAt time.Time `json:"created_at"`
	ID        string    `json:"id"`
	Name      string    `json:"name"`
}

A Context is the owner of EnvironmentVariables.

type ContextInterface added in v0.1.9321

type ContextInterface interface {
	Contexts(vcs, org string) (*[]Context, error)
	ContextByName(vcs, org, name string) (*Context, error)
	DeleteContext(contextID string) error
	CreateContext(vcs, org, name string) error

	EnvironmentVariables(contextID string) (*[]EnvironmentVariable, error)
	CreateEnvironmentVariable(contextID, variable, value string) error
	DeleteEnvironmentVariable(contextID, variable string) error
}

ContextInterface is the interface to interact with contexts and environment variables.

type ContextRestClient added in v0.1.9321

type ContextRestClient struct {
	// contains filtered or unexported fields
}

ContextRestClient communicates with the CircleCI REST API to ask questions about contexts. It satisfies api.ContextInterface.

func NewContextRestClient added in v0.1.9321

func NewContextRestClient(config settings.Config) (*ContextRestClient, error)

NewContextRestClient returns a new client satisfying the api.ContextInterface interface via the REST API.

func (*ContextRestClient) ContextByName added in v0.1.9321

func (c *ContextRestClient) ContextByName(vcs, org, name string) (*Context, error)

ContextByName finds a single context by its name and returns it.

func (*ContextRestClient) Contexts added in v0.1.9321

func (c *ContextRestClient) Contexts(vcs, org string) (*[]Context, error)

Contexts returns all of the contexts owned by the given org. Note that pagination is not currently supported - we get all pages of contexts and return them all.

func (*ContextRestClient) CreateContext added in v0.1.9321

func (c *ContextRestClient) CreateContext(vcs, org, name string) error

CreateContext creates a new context in the supplied organization.

func (*ContextRestClient) CreateEnvironmentVariable added in v0.1.9321

func (c *ContextRestClient) CreateEnvironmentVariable(contextID, variable, value string) error

CreateEnvironmentVariable creates OR UPDATES an environment variable.

func (*ContextRestClient) DeleteContext added in v0.1.9321

func (c *ContextRestClient) DeleteContext(contextID string) error

DeleteContext deletes the context with the given ID.

func (*ContextRestClient) DeleteEnvironmentVariable added in v0.1.9321

func (c *ContextRestClient) DeleteEnvironmentVariable(contextID, variable string) error

DeleteEnvironmentVariable deletes the environment variable in the context. It does not return an error if the environment variable did not exist.

func (*ContextRestClient) EnsureExists added in v0.1.9321

func (c *ContextRestClient) EnsureExists() error

EnsureExists verifies that the REST API exists and has the necessary endpoints to interact with contexts and env vars.

func (*ContextRestClient) EnvironmentVariables added in v0.1.9321

func (c *ContextRestClient) EnvironmentVariables(contextID string) (*[]EnvironmentVariable, error)

EnvironmentVariables returns all of the environment variables owned by the given context. Note that pagination is not currently supported - we get all pages of env vars and return them all.

type CreateNamespaceResponse

type CreateNamespaceResponse struct {
	CreateNamespace struct {
		Namespace struct {
			CreatedAt string
			ID        string
		}

		Errors GQLErrorsCollection
	}
}

CreateNamespaceResponse type matches the data shape of the GQL response for creating a namespace

func CreateNamespace

func CreateNamespace(cl *graphql.Client, name string, organizationName string, organizationVcs string) (*CreateNamespaceResponse, error)

CreateNamespace creates (reserves) a namespace for an organization

type CreateOrbResponse

type CreateOrbResponse struct {
	CreateOrb struct {
		Orb    Orb
		Errors GQLErrorsCollection
	}
}

CreateOrbResponse type matches the data shape of the GQL response for creating an orb

func CreateOrb

func CreateOrb(cl *graphql.Client, namespace string, name string, isPrivate bool) (*CreateOrbResponse, error)

CreateOrb creates (reserves) an orb within a namespace

type EnvironmentVariable added in v0.1.9321

type EnvironmentVariable struct {
	Variable  string
	ContextID string
	CreatedAt time.Time
}

An EnvironmentVariable has a Variable, a ContextID (its owner), and a CreatedAt date.

type ErrOrbVersionNotExists added in v0.1.11062

type ErrOrbVersionNotExists struct {
	OrbRef string
}

ErrOrbVersionNotExists is a custom error type that communicates that an orb version was not found.

func (*ErrOrbVersionNotExists) Error added in v0.1.11062

func (e *ErrOrbVersionNotExists) Error() string

Error implements the standard error interface.

type FollowedProject added in v0.1.9988

type FollowedProject struct {
	Followed bool   `json:"followed"`
	Message  string `json:"message"`
}

func FollowProject added in v0.1.9988

func FollowProject(config settings.Config, vcs string, owner string, projectName string) (FollowedProject, error)

FollowProject initiates an API request to follow a specific project on CircleCI. Project slugs are case-sensitive.

type GQLErrorsCollection added in v0.1.2969

type GQLErrorsCollection []GQLResponseError

GQLErrorsCollection is a slice of errors returned by the GraphQL server. Each error is made up of a GQLResponseError type.

func (GQLErrorsCollection) Error added in v0.1.2969

func (errs GQLErrorsCollection) Error() string

Error turns a GQLErrorsCollection into an acceptable error string that can be printed to the user.

type GQLResponseError added in v0.1.2969

type GQLResponseError struct {
	Message       string
	Value         string
	AllowedValues []string
	EnumType      string
	Type          string
}

GQLResponseError is a mapping of the data returned by the GraphQL server of key-value pairs. Typically used with the structure "Message: string", but other response errors provide additional fields.

type GetNamespaceResponse added in v0.1.2969

type GetNamespaceResponse struct {
	RegistryNamespace struct {
		ID string
	}
}

GetNamespaceResponse type wraps the GQL response for fetching a namespace

func GetNamespace added in v0.1.9988

func GetNamespace(cl *graphql.Client, name string) (*GetNamespaceResponse, error)

type GetOrganizationResponse added in v0.1.2969

type GetOrganizationResponse struct {
	Organization struct {
		ID string
	}
}

GetOrganizationResponse type wraps the GQL response for fetching an organization and ID.

type GraphQLContextClient added in v0.1.9321

type GraphQLContextClient struct {
	Client *graphql.Client
}

func NewContextGraphqlClient added in v0.1.9321

func NewContextGraphqlClient(httpClient *http.Client, host, endpoint, token string, debug bool) *GraphQLContextClient

NewContextGraphqlClient returns a new client satisfying the api.ContextInterface interface via the GraphQL API.

func (*GraphQLContextClient) ContextByName added in v0.1.9321

func (c *GraphQLContextClient) ContextByName(vcs, org, name string) (*Context, error)

ContextByName returns the Context in the given organization with the given name.

func (*GraphQLContextClient) Contexts added in v0.1.9321

func (c *GraphQLContextClient) Contexts(vcsType, orgName string) (*[]Context, error)

Contexts returns all of the Contexts owned by this organization.

func (*GraphQLContextClient) CreateContext added in v0.1.9321

func (c *GraphQLContextClient) CreateContext(vcsType, orgName, contextName string) error

CreateContext creates a new Context in the supplied organization.

func (*GraphQLContextClient) CreateEnvironmentVariable added in v0.1.9321

func (c *GraphQLContextClient) CreateEnvironmentVariable(contextId, variableName, secretValue string) error

CreateEnvironmentVariable creates a new environment variable in the given context. Note that the GraphQL API does not support upsert, so an error will be returned if the env var already exists.

func (*GraphQLContextClient) DeleteContext added in v0.1.9321

func (c *GraphQLContextClient) DeleteContext(contextId string) error

DeleteContext will delete the context with the given ID.

func (*GraphQLContextClient) DeleteEnvironmentVariable added in v0.1.9321

func (c *GraphQLContextClient) DeleteEnvironmentVariable(contextId, variableName string) error

DeleteEnvironmentVariable deletes the environment variable from the context. It returns an error if one occurred. It does not return an error if the environment variable did not exist.

func (*GraphQLContextClient) EnvironmentVariables added in v0.1.9321

func (c *GraphQLContextClient) EnvironmentVariables(contextID string) (*[]EnvironmentVariable, error)

EnvironmentVariables returns all of the environment variables in this context.

type ImportNamespaceResponse added in v0.1.11062

type ImportNamespaceResponse struct {
	ImportNamespace struct {
		Namespace struct {
			CreatedAt string
			ID        string
		}

		Errors GQLErrorsCollection
	}
}

ImportNamespaceResponse type matches the data shape of the GQL response for importing a namespace

func CreateImportedNamespace added in v0.1.11062

func CreateImportedNamespace(cl *graphql.Client, name string) (*ImportNamespaceResponse, error)

CreateImportedNamespace creates an imported namespace with the provided name. An imported namespace does not require organization-level details.

type ImportOrbResponse added in v0.1.11458

type ImportOrbResponse struct {
	ImportOrb struct {
		Orb    Orb
		Errors GQLErrorsCollection
	}
}

ImportOrbResponse type matches the data shape of the GQL response for creating an orb

func CreateImportedOrb added in v0.1.11062

func CreateImportedOrb(cl *graphql.Client, namespace string, name string) (*ImportOrbResponse, error)

CreateImportedOrb creates (reserves) an imported orb within the provided namespace.

type IntrospectionResponse added in v0.1.2001

type IntrospectionResponse struct {
	Schema struct {
		MutationType struct {
			Name string
		}
		QueryType struct {
			Name string
		}
		Types []struct {
			Description string
			Fields      []struct {
				Name string
			}
			Kind string
			Name string
		}
	} `json:"__schema"`
}

IntrospectionResponse matches the result from making an introspection query

func IntrospectionQuery added in v0.1.2001

func IntrospectionQuery(cl *graphql.Client) (*IntrospectionResponse, error)

IntrospectionQuery makes a query on the API asking for bits of the schema This query isn't intended to get the entire schema, there are better tools for that.

type Namespace added in v0.1.11062

type Namespace struct {
	Name string
}

Namespace represents the contents of a single namespace.

type NamespaceOrbResponse added in v0.1.2969

type NamespaceOrbResponse struct {
	RegistryNamespace struct {
		Name string
		ID   string
		Orbs struct {
			Edges []struct {
				Cursor string
				Node   OrbWithData
			}
			TotalCount int
			PageInfo   struct {
				HasNextPage bool
			}
		}
	}
}

NamespaceOrbResponse type matches the result from GQL. So that we can use mapstructure to convert from nested maps to a strongly typed struct.

type NamespaceOrbVersionResponse added in v0.1.11062

type NamespaceOrbVersionResponse struct {
	RegistryNamespace struct {
		Name string
		ID   string
		Orbs struct {
			Edges []struct {
				Cursor string
				Node   Orb
			}
			PageInfo struct {
				HasNextPage bool
			}
		}
	}
}

NamespaceOrbVersionResponse type mat

type Orb added in v0.1.1845

type Orb struct {
	ID        string
	Name      string
	Namespace Namespace
	CreatedAt string

	Source         string
	HighestVersion string `json:"version"`

	Statistics struct {
		Last30DaysBuildCount        int
		Last30DaysProjectCount      int
		Last30DaysOrganizationCount int
	}

	Commands  map[string]OrbElement
	Jobs      map[string]OrbElement
	Executors map[string]OrbElement
	Versions  []OrbVersion

	Categories []OrbCategory
}

Orb is a struct for containing the yaml-unmarshaled contents of an orb

func OrbImportVersion added in v0.1.11062

func OrbImportVersion(cl *graphql.Client, orbSrc string, orbID string, orbVersion string) (*Orb, error)

OrbImportVersion publishes a new version of an orb using the provided source and id.

func OrbIncrementVersion added in v0.1.1813

func OrbIncrementVersion(cl *graphql.Client, configPath string, namespace string, orb string, segment string) (*Orb, error)

OrbIncrementVersion accepts an orb and segment to increment the orb.

func OrbPromoteByName added in v0.1.12119

func OrbPromoteByName(cl *graphql.Client, namespaceName, orbName, label, segment string) (*Orb, error)

OrbPromoteByName utilizes the given orb's name, namespace, development version, and segment to increment a semantic release.

func OrbPublishByName added in v0.1.12119

func OrbPublishByName(cl *graphql.Client, configPath, orbName, namespaceName, orbVersion string) (*Orb, error)

OrbPublishByName publishes a new version of an orb using the provided orb's name and namespace, returning any error encountered.

func (*Orb) Shortname added in v0.1.11062

func (o *Orb) Shortname() string

Shortname returns the orb's name without its associated namespace.

type OrbBase added in v0.1.4555

type OrbBase struct {
	Name           string        `json:"name"`
	HighestVersion string        `json:"version"`
	Statistics     OrbStatistics `json:"statistics"`
	Versions       []struct {
		Version string `json:"version"`
		Source  string `json:"source"`
	} `json:"versions"`
}

OrbBase represents the minimum fields we wish to serialize for orbs. This type can be embedded for extending orbs with more data. e.g. OrbWithData

type OrbCategoriesForListing added in v0.1.9399

type OrbCategoriesForListing struct {
	OrbCategories []OrbCategory `json:"orbCategories"`
}

OrbCategoriesForListing is a container type for multiple orb categories for deserializing back into JSON.

func ListOrbCategories added in v0.1.9399

func ListOrbCategories(cl *graphql.Client) (*OrbCategoriesForListing, error)

ListOrbCategories queries the API to find all categories. Returns a collection of OrbCategory objects containing their relevant data.

type OrbCategory added in v0.1.9399

type OrbCategory struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type OrbCategoryIDResponse added in v0.1.9399

type OrbCategoryIDResponse struct {
	OrbCategoryByName struct {
		ID string
	}
}

OrbCategoryIDResponse matches the GQL response for fetching an Orb category's id

func OrbCategoryID added in v0.1.9399

func OrbCategoryID(cl *graphql.Client, name string) (*OrbCategoryIDResponse, error)

OrbCategoryID fetches an orb returning the ID

type OrbCategoryListResponse added in v0.1.9399

type OrbCategoryListResponse struct {
	OrbCategories struct {
		TotalCount int
		Edges      []struct {
			Cursor string
			Node   OrbCategory
		}
		PageInfo struct {
			HasNextPage bool
		}
	}
}

OrbCategoryListResponse type matches the result from GQL. So that we can use mapstructure to convert from nested maps to a strongly typed struct.

type OrbConfigResponse added in v0.1.2969

type OrbConfigResponse struct {
	OrbConfig struct {
		ConfigResponse
	}
}

OrbConfigResponse wraps the GQL result for OrbQuery.

type OrbElement added in v0.1.3541

type OrbElement RealOrbElement

OrbElement implements RealOrbElement interface and allows us to deserialize by hand.

func (*OrbElement) UnmarshalYAML added in v0.1.4180

func (orbElement *OrbElement) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML method allows OrbElement to be a string or a map. For now, don't even try to dereference the string, just return what is essentially an empty OrbElement (no description or parameters)

type OrbElementParameter added in v0.1.3541

type OrbElementParameter struct {
	Description string      `json:"-"`
	Type        string      `json:"-"`
	Default     interface{} `json:"-"`
}

OrbElementParameter represents the yaml-unmarshled contents of a parameter for a command/job/executor

type OrbIDResponse added in v0.1.2969

type OrbIDResponse struct {
	Orb struct {
		ID string
	}
	RegistryNamespace struct {
		ID string
	}
}

OrbIDResponse matches the GQL response for fetching an Orb and ID

func OrbID added in v0.1.1813

func OrbID(cl *graphql.Client, namespace string, orb string) (*OrbIDResponse, error)

OrbID fetches an orb returning the ID

type OrbImportVersionResponse added in v0.1.11715

type OrbImportVersionResponse struct {
	ImportOrbVersion struct {
		Orb Orb

		Errors GQLErrorsCollection
	}
}

The OrbImportVersionResponse type matches the data shape of the GQL response for importing an orb version.

type OrbLatestVersionResponse added in v0.1.2969

type OrbLatestVersionResponse struct {
	Orb struct {
		Versions []OrbVersion
	}
}

OrbLatestVersionResponse wraps the GQL result of fetching an Orb and latest version

type OrbListResponse added in v0.1.2969

type OrbListResponse struct {
	Orbs struct {
		TotalCount int
		Edges      []struct {
			Cursor string
			Node   OrbWithData
		}
		PageInfo struct {
			HasNextPage bool
		}
	}
}

OrbListResponse type matches the result from GQL. So that we can use mapstructure to convert from nested maps to a strongly typed struct.

type OrbPromoteResponse added in v0.1.1813

type OrbPromoteResponse struct {
	PromoteOrb struct {
		Orb Orb

		Errors GQLErrorsCollection
	}
}

The OrbPromoteResponse type matches the data shape of the GQL response for promoting an orb.

type OrbPublishResponse added in v0.1.1813

type OrbPublishResponse struct {
	PublishOrb struct {
		Orb Orb

		Errors GQLErrorsCollection
	}
}

The OrbPublishResponse type matches the data shape of the GQL response for publishing an orb.

type OrbSetOrbListStatusResponse added in v0.1.5879

type OrbSetOrbListStatusResponse struct {
	SetOrbListStatus struct {
		Listed bool

		Errors GQLErrorsCollection
	}
}

The OrbSetOrbListStatusResponse type matches the data shape of the GQL response for setting the list status of an orb.

type OrbStatistics added in v0.1.4766

type OrbStatistics struct {
	Last30DaysBuildCount        int `json:"last30DaysBuildCount"`
	Last30DaysProjectCount      int `json:"last30DaysProjectCount"`
	Last30DaysOrganizationCount int `json:"last30DaysOrganizationCount"`
}

OrbStatistics represents the data we retrieve for orb usage in the last thirty days.

type OrbVersion added in v0.1.2331

type OrbVersion struct {
	ID        string
	Version   string
	Orb       Orb
	Source    string
	CreatedAt string
}

OrbVersion wraps the GQL result used by OrbSource and OrbInfo

func ListNamespaceOrbVersions added in v0.1.11062

func ListNamespaceOrbVersions(cl *graphql.Client, namespace string) ([]OrbVersion, error)

ListNamespaceOrbVersions queries the API to retrieve the orbs belonging to the given namespace. By default, this call fetches the latest version of each orb.

func OrbInfo added in v0.1.3807

func OrbInfo(cl *graphql.Client, orbRef string) (*OrbVersion, error)

OrbInfo gets the meta-data of an orb

type OrbWithData added in v0.1.3923

type OrbWithData struct {
	OrbBase

	Commands  map[string]OrbElement
	Jobs      map[string]OrbElement
	Executors map[string]OrbElement
}

OrbWithData extends the OrbBase type with additional data used for printing.

func (OrbWithData) MarshalJSON added in v0.1.4555

func (orb OrbWithData) MarshalJSON() ([]byte, error)

MarshalJSON allows us to leave out excess fields we don't want to serialize. As is the case with commands/jobs/executors and now statistics.

type OrbsForListing added in v0.1.3923

type OrbsForListing struct {
	Orbs      []OrbWithData `json:"orbs"`
	Namespace string        `json:"namespace,omitempty"`
}

OrbsForListing is a container type for multiple orbs that includes the namespace and orbs for deserializing back into JSON.

func ListNamespaceOrbs added in v0.1.1845

func ListNamespaceOrbs(cl *graphql.Client, namespace string, isPrivate bool) (*OrbsForListing, error)

ListNamespaceOrbs queries the API to find all orbs belonging to the given namespace. Returns a collection of Orb objects containing their relevant data.

func ListOrbs added in v0.1.2113

func ListOrbs(cl *graphql.Client, uncertified bool) (*OrbsForListing, error)

ListOrbs queries the API to find all orbs. Returns a collection of Orb objects containing their relevant data.

func (*OrbsForListing) SortBy added in v0.1.4555

func (orbs *OrbsForListing) SortBy(sortBy string)

SortBy allows us to sort a collection of orbs by builds, projects, or orgs from the last 30 days of data.

type RealOrbElement added in v0.1.4180

type RealOrbElement struct {
	Description string                         `json:"-"`
	Parameters  map[string]OrbElementParameter `json:"-"`
}

RealOrbElement represents the yaml-unmarshled contents of a named element under a command/job/executor

type RenameNamespaceResponse added in v0.1.11255

type RenameNamespaceResponse struct {
	RenameNamespace struct {
		Namespace struct {
			CreatedAt string
			ID        string
		}

		Errors GQLErrorsCollection
	}
}

func RenameNamespace added in v0.1.11255

func RenameNamespace(cl *graphql.Client, oldName, newName string) (*RenameNamespaceResponse, error)

type UpdateOrbCategorizationRequestType added in v0.1.9399

type UpdateOrbCategorizationRequestType int
const (
	Add UpdateOrbCategorizationRequestType = iota
	Remove
)

type WhoamiResponse added in v0.1.2295

type WhoamiResponse struct {
	Me struct {
		Name string
	}
}

WhoamiResponse type matches the data shape of the GQL response for the current user

func WhoamiQuery added in v0.1.2295

func WhoamiQuery(cl *graphql.Client) (*WhoamiResponse, error)

WhoamiQuery returns the result of querying the `/me` endpoint of the API

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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