circle

package module
v0.0.0-...-d8aac60 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2018 License: MIT Imports: 20 Imported by: 3

README

go-circle

CircleCI

This is a very incomplete wrapper for the CircleCI API. Currently we use it to fetch the latest build for a branch.

You should treat the API as very unstable, library API's that grow from one or two methods to the whole API tend to not be designed very well, so probably at some point you will have to create a Client instance or something.

Token Management

This library will look for your Circle API token in ~/cfg/circleci and (if that does not exist, in ~/.circlerc). The configuration file should look like this:

[organizations]

    [organizations.Shyp]
    token = "aabbccddeeff00"

You can specify any org name you want.

Installation

If you just want the binary, download it from Equinox.io and place the circle file somewhere on your $PATH.

If you want to install the project, first set your $GOPATH in your environment (I set it to ~/code/go), then run

go install github.com/Shyp/go-circle/...

This should place a circle binary in $GOPATH/bin, so for me, ~/code/go/bin/circle.

Wait for tests to pass/fail on a branch

If you want to be notified when your tests finish running, run circle wait [branchname]. The interface for that will certainly change as well; we should be able to determine which organization/project to run tests for by checking your Git remotes.

It's pretty neat! Here's a screenshot.

CircleCI screenshot

Documentation

Index

Constants

View Source
const VERSION = "0.27"

Variables

This section is empty.

Functions

func DownloadArtifact

func DownloadArtifact(artifact *CircleArtifact, directory string, org string) error

func Enable

func Enable(ctx context.Context, host string, org string, repoName string) error

func Rebuild

func Rebuild(ctx context.Context, tb *TreeBuild) error

Types

type Action

type Action struct {
	Name      string         `json:"name"`
	OutputURL URL            `json:"output_url"`
	Runtime   CircleDuration `json:"run_time_millis"`
	Status    string         `json:"status"`
}

func (*Action) Failed

func (a *Action) Failed() bool

type CircleArtifact

type CircleArtifact struct {
	Path       string `json:"path"`
	PrettyPath string `json:"pretty_path"`
	NodeIndex  uint8  `json:"node_index"`
	Url        string `json:"url"`
}

func GetArtifactsForBuild

func GetArtifactsForBuild(org string, project string, buildNum int) ([]*CircleArtifact, error)

type CircleBuild

type CircleBuild struct {
	BuildNum                uint32         `json:"build_num"`
	Parallel                uint8          `json:"parallel"`
	PreviousSuccessfulBuild PreviousBuild  `json:"previous_successful_build"`
	QueuedAt                types.NullTime `json:"queued_at"`
	RepoName                string         `json:"reponame"` // "go"
	Steps                   []Step         `json:"steps"`
	VCSType                 string         `json:"vcs_type"` // "github", "bitbucket"
	UsageQueuedAt           types.NullTime `json:"usage_queued_at"`
	Username                string         `json:"username"` // "golang"
}

func CancelBuild

func CancelBuild(org string, project string, buildNum int) (*CircleBuild, error)

func GetBuild

func GetBuild(org string, project string, buildNum int) (*CircleBuild, error)

func (*CircleBuild) FailureTexts

func (cb *CircleBuild) FailureTexts(ctx context.Context) ([]string, error)

func (*CircleBuild) Failures

func (cb *CircleBuild) Failures() [][2]int

Failures returns an array of (buildStep, containerID) integers identifying the IDs of container/build step pairs that failed.

func (*CircleBuild) Statistics

func (cb *CircleBuild) Statistics() string

Statistics prints out statistics for the given build. If stdout is a TTY, failed builds will be surrounded by red ANSI escape sequences.

type CircleConfig

type CircleConfig struct {
	Organizations map[string]organization
}

type CircleDuration

type CircleDuration time.Duration

func (*CircleDuration) UnmarshalJSON

func (cd *CircleDuration) UnmarshalJSON(b []byte) error

type CircleOutput

type CircleOutput struct {
	Message string    `json:"message"`
	Time    time.Time `json:"time"`
	Type    string    `json:"type"`
}

type CircleOutputs

type CircleOutputs []*CircleOutput

type CircleTreeResponse

type CircleTreeResponse []TreeBuild

func GetTree

func GetTree(org string, project string, branch string) (*CircleTreeResponse, error)

func GetTreeContext

func GetTreeContext(ctx context.Context, org, project, branch string) (*CircleTreeResponse, error)

type FollowResponse

type FollowResponse struct {
	Following bool `json:"following"`
}

type PreviousBuild

type PreviousBuild struct {
	BuildNum int `json:"build_num"`
	// would be neat to make this a time.Duration, easier to use the passed in
	// value.
	Status string `json:"status"`

	BuildDurationMs int `json:"build_time_millis"`
}

type Step

type Step struct {
	Name    string   `json:"name"`
	Actions []Action `json:"actions"`
}

type TreeBuild

type TreeBuild struct {
	BuildNum   int    `json:"build_num"`
	BuildURL   string `json:"build_url"`
	CompareURL string `json:"compare"`
	// Tree builds have a `previous_successful_build` field but as far as I can
	// tell it is always null. Instead this field is set
	Previous      PreviousBuild  `json:"previous"`
	QueuedAt      types.NullTime `json:"queued_at"`
	RepoName      string         `json:"reponame"`
	Status        string         `json:"status"`
	StartTime     types.NullTime `json:"start_time"`
	StopTime      types.NullTime `json:"stop_time"`
	UsageQueuedAt types.NullTime `json:"usage_queued_at"`
	Username      string         `json:"username"`
	VCSRevision   string         `json:"vcs_revision"`
	VCSType       string         `json:"vcs_type"`
}

func (TreeBuild) Failed

func (tb TreeBuild) Failed() bool

func (TreeBuild) NotRunning

func (tb TreeBuild) NotRunning() bool

func (TreeBuild) Passed

func (tb TreeBuild) Passed() bool

func (TreeBuild) Running

func (tb TreeBuild) Running() bool

type URL

type URL struct {
	*url.URL
}

Unmarshallable URL

func (*URL) UnmarshalJSON

func (oururl *URL) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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