Go library for interacting with CircleCI

go-circleci

GoDoc Circle CI Go Report Card coverage

Go library for interacting with CircleCI's API. Supports all current API endpoints allowing you do do things like:

  • Query for recent builds
  • Get build details
  • Retry builds
  • Manipulate checkout keys, environment variables, and other settings for a project

The CircleCI HTTP API response schemas are not well documented so please file an issue if you run into something that doesn't match up.

Example usage:

package main

import (
        "fmt"

        "github.com/jszwedko/go-circleci"
)

func main() {
        client := &circleci.Client{Token: "YOUR TOKEN"} // Token not required to query info for public projects

        builds, _ := client.ListRecentBuildsForProject("jszwedko", "circleci-cli", "master", "", -1, 0)

        for _, build := range builds {
                fmt.Printf("%d: %s\n", build.BuildNum, build.Status)
        }
}

For the CLI that uses this library (or to see more example usages), please see circleci-cli.

See GoDoc for API usage.

Feature requests and issues welcome!

Comments
  • Getting interface {} is string, not *string all of a sudden

    Getting interface {} is string, not *string all of a sudden

    panic: interface conversion: interface {} is string, not *string [recovered]
    panic: interface conversion: interface {} is string, not *string
    github.com/jszwedko/go-circleci/circleci.go:756
    
  • Some values returned by the API should be unescaped

    Some values returned by the API should be unescaped

    When I'm trying to list all branches in a project (project.Branches), I'm getting the string which looks like this:

    release%2F0%2E1%2E0
    

    IMHO, the output should be unescaped (maybe by the url.QueryUnescape() function?)

  • Error Parsing Feature Flags

    Error Parsing Feature Flags

    FeatureFlags is defined as map[string]bool But in reality they are sometimes null too

     "feature_flags" : {
       "trusty-beta" : true,
       "osx" : false,
       "set-github-status" : true,
       "build-prs-only" : false,
       "fleet" : null,
       "build-fork-prs" : false,
       "autocancel-builds" : false,
       "junit" : true
     },
    
  • [Improvement]

    [Improvement] "You must log in first" error message should tell you how to login

    What Happpened

    I called an api endpoint like so (psuedo-code)

    circleci.Client{Token: circleToken}.ListProjects()
    

    and got this error message

    401: You must log in first

    What I Was Expecting

    When I call an api endpoint without being authorized, I get an error message like this

    401: You must log in first. You can log in via ...

  • Fixes paramterized build

    Fixes paramterized build

    The request body for parametrized builds expects the body contents to be in the format:

    {  "build_parameters": {
          "parameter_name": "parameter_value",
    },
    

    But currently just the contents inside the build_parameters key is sent, so the values aren't actually used.

    I've updated the unit test, and tested this change on a project locally using the CIRCLE_JOB parameter to trigger a specific job and with these changes included the correct job is now triggered.

  • Parameterized builds

    Parameterized builds

    Problem

    When triggering a build, optional parameters can be passed to override or add environment variables to that job:

    https://circleci.com/docs/parameterized-builds/

    Currently the library doesn't support doing this (Unless I completely missed it 😳)

    Solution

    I though about modifying the Build method to taken an optional (Can be nil) body but it changes the interface that some people may be relying on and as there's currently no versioning in the app could end up breaking peoples apps if they pull down the latest version.

    Opted for a separate method ParameterizedBuild that essentially has an extra parameter for a struct that's Marshalled into a JSON string and posted to the trigger build endpoint.

  • Versioning

    Versioning

    Hey there!

    Great work on the library, we're using it in one of our projects and it would be great if you tagged the repo so we had a version number when adding the package as a dep in our app!

  • add more generic buildOpts method

    add more generic buildOpts method

    It is possible to add more than build_parameters to a build, for example, you can add revision

    Adding a new method, a bit more generic and keep to old ones to not break the API

    I believe it would also solve, at least partially, #26

  • Support for building specific revision?

    Support for building specific revision?

    @jszwedko looks like https://circleci.com/docs/api/v1-reference/#new-build supports building a specific revision or tag. Do you have plans to support it? If so, would you be happy if contribute a patch, such as:

    func (c *Client) Build(account, repo, branch, revision, tag string) (*Build, error) {
        ....
    }
    

    This will be a breaking change, unless you want me to introduce a new method?

  • fix handling of null timestamps

    fix handling of null timestamps

    When running circle-cli projects I receive an error message similar to parsing time "null" as ""2006-01-02T15:04:05Z07:00"": cannot parse "null" as """

    http://stackoverflow.com/questions/26684752/json-decode-cannot-parse-timestamp-in-json-into-go-struct explains that you need to make pointer to *time.Time to handle null dates to become nil.

    This PR changes all time.Time -> *time.Time

  • make lint not working - cannot find package

    make lint not working - cannot find package "golang.org/x/tools/go/gcimporter

    $ make lint
    package golang.org/x/tools/go/gcimporter: cannot find package "golang.org/x/tools/go/gcimporter" in any of:
            /usr/local/Cellar/go/1.7.3/libexec/src/golang.org/x/tools/go/gcimporter (from $GOROOT)
            /Users/patrick/go/src/golang.org/x/tools/go/gcimporter (from $GOPATH)
    
  • starting down the road to supporting the circleci api v2

    starting down the road to supporting the circleci api v2

    In doing some work with the CircleCI API I got a suggestion that I look at v2 of the API. It is not yet released but some of the pre-release documentation is https://github.com/CircleCI-Public/api-preview-docs. Specifically, https://github.com/CircleCI-Public/api-preview-docs/blob/master/docs/api-changes.md holds the definition for the /workflow endpoint.

    This change adds support for v2 of the API by initially adding the ability to fetch details for a specific workflow and all the jobs in that workflow. From there you can fall back to the v1 api to get the full details for a specific job.

    I'm opening this PR for comments on the approach. Is this useful work? If it is, maybe it could be merged in to a v2 tag or something for further work before landing in master, since the API is still in pre-release mode and will likely change.

    Thanks!

    Here's some sample code that exercises the new functions defined: https://gist.github.com/maplebed/d9cb97961448dc02a641200b089e2f19

  • Support for triggering builds by project

    Support for triggering builds by project

    Hi there! There's a new API that's still in beta for triggering builds: https://circleci.com/docs/api/v1-reference/#new-project-build The old trigger build API is not compatible with Circle 2.1, so this new API is the only way to trigger builds for those on the new version.

    I'm happy to take this on - are you accepting PRs? Thanks!

  • add vcs-type parameter and change to v1.1 API

    add vcs-type parameter and change to v1.1 API

    Version Control System (:vcs-type)

    New with v1.1 of the api, for endpoints under /project you will now need to tell CircleCI what version control system type your project uses. Current choices are ‘github’ or ‘bitbucket’.

A Go library for interacting with Cloudflare's API v4.

Go library for the Cloudflare v4 API

Dec 29, 2022
Go library for interacting with the Discord API (work-in-progress)

zombiezen Go Client for Discord zombiezen.com/go/discord is a WIP Go library for interacting with the Discord API. It differs from DiscordGo by provid

Nov 9, 2022
Terraform provider implementation for interacting with the Tailscale API.

Terraform Provider Tailscale This repository contains a Terraform provider implementation for interacting with the Tailscale API.

Oct 3, 2022
Go Client Library for Amazon Product Advertising API

go-amazon-product-advertising-api Go Client Library for Amazon Product Advertising API How to Use go get -u github.com/ngs/go-amazon-product-advertisi

Sep 27, 2022
A Go client library for the Twitter 1.1 API

Anaconda Anaconda is a simple, transparent Go package for accessing version 1.1 of the Twitter API. Successful API queries return native Go structs th

Jan 1, 2023
Go library for http://www.brewerydb.com/ API

brewerydb brewerydb is a Go library for accessing the BreweryDB API usage import "github.com/naegelejd/brewerydb" Construct a new Client using your Br

Sep 27, 2022
Go(lang) client library for Cachet (open source status page system).

cachet Go(lang) client library for Cachet (open source status page system). Features Full API support Components Incidents Metrics Subscribers Various

Sep 27, 2022
Clarifai library for Go

Clarifai Golang Library Library for our v1 API. Disclaimer This API client only supports Clarifai v1 API. Stay tuned for the v2 support. Usage go get

Sep 27, 2022
Go library for accessing the Codeship API v2

Codeship API v2 Client for Go Codeship API v2 client for Go. Documentation https://godoc.org/github.com/codeship/codeship-go Usage go get -u github.co

Sep 27, 2022
Go library to access geocoding and reverse geocoding APIs

GeoService in Go Code Coverage A geocoding service developed in Go's way, idiomatic and elegant, not just in golang. This product is designed to open

Dec 23, 2022
Go library for accessing the GitHub API

go-github go-github is a Go client library for accessing the GitHub API v3. Currently, go-github requires Go version 1.9 or greater. go-github tracks

Dec 30, 2022
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://developer.github.com/v4/).

githubv4 Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). If you're looking for a client

Dec 26, 2022
Go library to use the imgur.com API

go-imgur Go library to use the imgur.com API. At the moment only the anonymous part of the API is supported, but that is used in a production environm

Sep 27, 2022
Go client library for Atlassian Jira
Go client library for Atlassian Jira

go-jira Go client library for Atlassian Jira. Features Authentication (HTTP Basic, OAuth, Session Cookie) Create and retrieve issues Create and retrie

Jan 6, 2023
A GO API library for working with Marathon

Go-Marathon Go-marathon is a API library for working with Marathon. It currently supports Application and group deployment Helper filters for pulling

Dec 28, 2022
Go library for accessing the MyAnimeList API: http://myanimelist.net/modules.php?go=api

go-myanimelist go-myanimelist is a Go client library for accessing the MyAnimeList API. Project Status The MyAnimeList API has been stable for years a

Sep 28, 2022
Go library for accessing trending repositories and developers at Github.
Go library for accessing trending repositories and developers at Github.

go-trending A package to retrieve trending repositories and developers from Github written in golang. This package were inspired by rochefort/git-tren

Dec 21, 2022
a Go (Golang) MusicBrainz WS2 client library - work in progress
a Go (Golang) MusicBrainz WS2 client library - work in progress

gomusicbrainz a Go (Golang) MusicBrainz WS2 client library - a work in progress. Current state Currently GoMusicBrainz provides methods to perform sea

Sep 28, 2022
GoStorm is a Go library that implements the communications protocol required to write Storm spouts and Bolts in Go that communicate with the Storm shells.

gostorm godocs GoStorm is a Go library that implements the communications protocol required for non-Java languages to communicate as part of a storm t

Sep 27, 2022