circleci

package module
v0.0.0-...-2c35c3c Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: GPL-3.0 Imports: 16 Imported by: 1

README

circleci

The CircleCI API may be used to make API calls to retrieve detailed information about users, jobs, workflows and pipelines. There are currently two supported API versions:

CircleCI API v1.1 and v2 are supported and generally available.

go get -u github.com/bldmgr/circleci

package main

import (
	"fmt"
	"github.com/bldmgr/circleci"
	setting "github.com/bldmgr/circleci/pkg/config"
)

func main() {

	loadedConfig := setting.SetConfigYaml()

	ci, err := circleci.New(loadedConfig.Host, loadedConfig.Token, loadedConfig.Project)
	if err != nil {
		panic(err)
	}

	status := circleci.Me(ci)
	fmt.Printf("Connection to %s was successful -> %t \n", "host", status)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigWithWorkflow

func GetConfigWithWorkflow(ci CI, jobs []WorkflowItem, workflows []PipelineWorkflows, j int, w int, output string) (returnData []JobDataSteps, returnEnvConfig []JobDataEnvironment, orbs []ViperSub, parameters []ViperSub)

func GetJobData

func GetJobData(ci CI, jobId string, vsc string, namespace string, project string, step string, output string) (t []byte)

func GetPipelineConfig

func GetPipelineConfig(ci CI, pipelineId string, output string) (prametersItems []Prameters, jobItems []Job, jsonItems string)

func Me

func Me(ci CI) (_ bool)

Types

type Actor

type Actor struct {
	Login     string `json:"login"`
	AvatarURL string `json:"avatar_url"`
}

type AllData

type AllData struct {
	PipelineID       string             `json:"pipeline_id"`
	ID               string             `json:"id"`
	Name             string             `json:"name"`
	ProjectSlug      string             `json:"project_slug"`
	Status           string             `json:"status"`
	StartedBy        string             `json:"started_by"`
	PipelineNumber   int                `json:"pipeline_number"`
	CreatedAt        time.Time          `json:"created_at"`
	StoppedAt        time.Time          `json:"stopped_at"`
	Tag              string             `json:"tag,omitempty"`
	WorkflowPipeline []WorkflowPipeline `json:"workflow_pipeline"`
}

type Artifacts

type Artifacts struct {
	Items             []ArtifactsItem `json:"items"`
	ContinuationToken string          `json:"next_page_token"`
}

type ArtifactsItem

type ArtifactsItem struct {
	NodeIndex int    `json:"node_index"`
	Path      string `json:"path"`
	URL       string `json:"url"`
}

func GetJobsArtifacts

func GetJobsArtifacts(ci CI, jobId string, project string, output string) (items []ArtifactsItem)

type CI

type CI interface {
	Client
}

func New

func New(host, token, project string) (CI, error)

type Cache

type Cache struct {
	Key   string
	Value map[string]any
}

func NewCache

func NewCache(v *viper.Viper, key string) *Cache

type Client

type Client interface {
	CurlRequest(method, endpoint string) (*http.Request, error)
	NewRequest(method, endpoint string, payload io.Reader) (*http.Request, error)
	Get(endpoint string) ([]byte, *http.Response, error)
	Post(endpoint string, payload io.Reader) ([]byte, *http.Response, error)
	Info() ServerInfo
}

Client is the interface which allows interacting with an IQ server

type CommitInfo

type CommitInfo struct {
	Body    string `json:"body"`
	Subject string `json:"subject"`
}

type DefaultClient

type DefaultClient struct {
	ServerInfo
	Debug bool
}

DefaultClient provides an HTTP wrapper with optimized for communicating with a Circle server

func (*DefaultClient) CurlRequest

func (s *DefaultClient) CurlRequest(method, endpoint string) (request *http.Request, err error)

func (*DefaultClient) Do

func (s *DefaultClient) Do(request *http.Request) (body []byte, resp *http.Response, err error)

Do performs an http.Request and reads the body if StatusOK

func (*DefaultClient) Get

func (s *DefaultClient) Get(endpoint string) ([]byte, *http.Response, error)

Get performs an HTTP GET against the indicated endpoint

func (*DefaultClient) Info

func (s *DefaultClient) Info() ServerInfo

Info return information about the Nexus server

func (*DefaultClient) NewRequest

func (s *DefaultClient) NewRequest(method, endpoint string, payload io.Reader) (request *http.Request, err error)

NewRequest created an http.Request object based on an endpoint and fills in basic auth

func (*DefaultClient) Post

func (s *DefaultClient) Post(endpoint string, payload io.Reader) ([]byte, *http.Response, error)

Post performs an HTTP POST against the indicated endpoint

type Errors

type Errors struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

type Job

type Job struct {
	Machine       string `json:"machine"`
	Image         string `json:"image"`
	ResourceClass string `json:"resource_class"`
}

type JobDataEnvironment

type JobDataEnvironment struct {
	Sha            string   `json:"sha"`
	HostType       string   `json:"host_type"`
	HostClass      string   `json:"host_class"`
	HostImage      string   `json:"host_image"`
	HostVM         string   `json:"host_vm"`
	HostVolume     string   `json:"host_volume"`
	HostAgent      string   `json:"host_agent"`
	HostRunner     string   `json:"host_runner"`
	ExternalInputs []string `json:"external_inputs"`
	Orbs           []string `json:"orbs"`
	Parameters     []string `json:"parameters"`
}

type JobDataSteps

type JobDataSteps struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Command string `json:"command"`
	Key     string `json:"key"`
	Path    string `json:"path"`
	When    string `json:"when"`
	Output  string `json:"output"`
}

type JobDetails

type JobDetails struct {
	WebURL  string `json:"web_url"`
	Project struct {
		ExternalURL string `json:"external_url"`
		Slug        string `json:"slug"`
		Name        string `json:"name"`
		ID          string `json:"id"`
	} `json:"project"`
	ParallelRuns []struct {
		Index  int    `json:"index"`
		Status string `json:"status"`
	} `json:"parallel_runs"`
	StartedAt      time.Time `json:"started_at"`
	LatestWorkflow struct {
		Name string `json:"name"`
		ID   string `json:"id"`
	} `json:"latest_workflow"`
	Name     string `json:"name"`
	Executor struct {
		ResourceClass string `json:"resource_class"`
		Type          string `json:"type"`
	} `json:"executor"`
	Parallelism int    `json:"parallelism"`
	Status      string `json:"status"`
	Number      int    `json:"number"`
	Pipeline    struct {
		ID string `json:"id"`
	} `json:"pipeline"`
	Duration  int           `json:"duration"`
	CreatedAt time.Time     `json:"created_at"`
	Messages  []interface{} `json:"messages"`
	Contexts  []struct {
		Name string `json:"name"`
	} `json:"contexts"`
	Organization struct {
		Name string `json:"name"`
	} `json:"organization"`
	QueuedAt  time.Time `json:"queued_at"`
	StoppedAt time.Time `json:"stopped_at"`
}

func GetJobDetails

func GetJobDetails(ci CI, jobId string, vsc string, namespace string, project string, output string) (items JobDetails)

func GetJobParallel

func GetJobParallel(ci CI, jobId string, vsc string, namespace string, project string, output string) (items JobDetails)

type PipelineConfig

type PipelineConfig struct {
	Source              string `json:"source"`
	Compiled            string `json:"compiled"`
	SetupConfig         string `json:"setup-config"`
	CompiledSetupConfig string `json:"compiled-setup-config"`
}

type PipelineItem

type PipelineItem struct {
	ID          string    `json:"id"`
	Errors      []Errors  `json:"errors"`
	ProjectSlug string    `json:"project_slug"`
	UpdatedAt   time.Time `json:"updated_at"`
	Number      int       `json:"number"`
	State       string    `json:"state"`
	CreatedAt   time.Time `json:"created_at"`
	Trigger     Trigger   `json:"trigger"`
	Vcs         Vcs       `json:"vcs"`
}

func GetPipeline

func GetPipeline(ci CI, org string, output string, page int) (items []PipelineItem)

func GetPipelineById

func GetPipelineById(ci CI, pipelineId string, output string) (items PipelineItem)

type PipelineWorkflows

type PipelineWorkflows struct {
	PipelineID     string    `json:"pipeline_id"`
	ID             string    `json:"id"`
	Name           string    `json:"name"`
	ProjectSlug    string    `json:"project_slug"`
	Status         string    `json:"status"`
	StartedBy      string    `json:"started_by"`
	PipelineNumber int       `json:"pipeline_number"`
	CreatedAt      time.Time `json:"created_at"`
	StoppedAt      time.Time `json:"stopped_at"`
	Tag            string    `json:"tag,omitempty"`
}

func GetPipelineWorkflows

func GetPipelineWorkflows(ci CI, pipelineId string, output string) (items []PipelineWorkflows)

type Prameters

type Prameters struct {
	PipelineID string `json:"pipeline_id"`
	Parameter  string `json:"parameter"`
	Default    string `json:"default"`
	Type       string `json:"type"`
	Enum       string `json:"enum"`
}

type ServerInfo

type ServerInfo struct {
	Host, Token, Project string
}

ServerInfo contains the information needed to connect to a Circle server

type TestMetadata

type TestMetadata struct {
	Classname string  `json:"classname"`
	File      string  `json:"file"`
	Name      string  `json:"name"`
	Result    string  `json:"result"`
	Message   string  `json:"message"`
	RunTime   float64 `json:"run_time"`
	Source    string  `json:"source"`
}

func GetTestMetadata

func GetTestMetadata(ci CI, jobId string, vsc string, namespace string, project string, output string, page int) (items []TestMetadata)

type Trigger

type Trigger struct {
	ReceivedAt time.Time `json:"received_at"`
	Type       string    `json:"type"`
	Actor      Actor     `json:"actor"`
}

type Vcs

type Vcs struct {
	OriginRepositoryURL string     `json:"origin_repository_url"`
	TargetRepositoryURL string     `json:"target_repository_url"`
	Revision            string     `json:"revision"`
	ProviderName        string     `json:"provider_name"`
	Branch              string     `json:"branch"`
	Commit              CommitInfo `json:"commit"`
}

type ViperSub

type ViperSub struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type WorkflowItem

type WorkflowItem struct {
	JobNumber   int    `json:"job_number"`
	Id          string `json:"id"`
	StartedAt   string `json:"started_at"`
	Name        string `json:"name"`
	ProjectSlug string `json:"project_slug"`
	Status      string `json:"status"`
	Type        string `json:"type"`
	StoppedAt   string `json:"stopped_at"`
}

func GetWorkflowJob

func GetWorkflowJob(ci CI, workflowId string, output string, data string, token string) (items []WorkflowItem)

type WorkflowPipeline

type WorkflowPipeline struct {
	JobNumber    int            `json:"job_number"`
	Id           string         `json:"id"`
	StartedAt    string         `json:"started_at"`
	Name         string         `json:"name"`
	ProjectSlug  string         `json:"project_slug"`
	Status       string         `json:"status"`
	Type         string         `json:"type"`
	StoppedAt    string         `json:"stopped_at"`
	JobDataSteps []JobDataSteps `json:"job_data_steps"`
}

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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