• Stars
    star
    18
  • Rank 1,168,058 (Top 24 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go library for accessing the Codeship API v2

Codeship API v2 Client for Go

Codeship Status Coverage Status Go Doc Go Report Card GitHub Release

Codeship

Codeship API v2 client for Go.

Documentation

https://godoc.org/github.com/codeship/codeship-go

Usage

go get -u github.com/codeship/codeship-go

Package codeship provides a client for using the Codeship API v2.

import codeship "github.com/codeship/codeship-go"

Create a new API Client:

auth := codeship.NewBasicAuth("username", "password")
client, err := codeship.New(auth)

You must then scope the client to a single Organization that you have access to:

org, err := client.Organization(ctx, "codeship")

You can then perform calls to the API on behalf of an Organization:

projects, err := org.ListProjects(ctx)

Authentication

Authentication is handled automatically via the API Client using the provided authentication mechanism.

If you would like to manually re-authenticate, you may do this by calling the Authenticate method on the client:

err := client.Authenticate(ctx)

Two-Factor Authentication

Codeship now supports Two-Factor Authentication (2FA).

However, it is currently not possible to use 2FA with the API. If you try to authenticate via this client with a user that has 2FA enabled you will get the following error:

authentication failed: your account has two-factor authentication enabled, which is not possible to support with the API. Disable two factor authentication or create a dedicated API user without it enabled.

You must disable 2FA for the user you wish to authenticate with using this client. We hope to support Personal Access Tokens in a future version of the API to mitigate this issue.

Response

All API methods also return a codeship.Response type that contains the actual *http.Response embedded as well as a Links type that contains information to be used for pagination.

Pagination

Pagination is provided for all requests that can return multiple results. The methods that are able to be paginated all take a variable argument of type PaginationOption such as: ListProjects(opts ...PaginationOption).

We have defined two helper functions, Page and PerPage, to make pagination easier.

Usage is as follows:

// defaults to first page with page_size of 30
projects, resp, err := org.ListProjects(ctx)

// paging forwards with 50 results per page
for {
    if resp.IsLastPage() || resp.Next == "" {
        break
    }

    next, _ := resp.NextPage()

    projects, resp, _ = org.ListProjects(ctx, codeship.Page(next), codeship.PerPage(50))
}

// paging backwards with 50 results per page
for {
    if current, _ := resp.CurrentPage(); current == 1 || resp.Previous == "" {
        break
    }

    prev, _ := resp.PreviousPage()

    projects, resp, _ = org.ListProjects(ctx, codeship.Page(prev), codeship.PerPage(50))
}

Logging

You can enable verbose logging of all HTTP requests/responses by configuring the client via the functional option Verbose(verbose bool) when instantiating the client:

auth := codeship.NewBasicAuth("username", "password")
client, err := codeship.New(auth, codeship.Verbose(true))

Bring your own Logger

The default logger logs to STDOUT but can be replaced by any type that fulfills the StdLogger interface:

// StdLogger allows you to bring your own log implementation for logging
type StdLogger interface {
	Println(...interface{})
}

Example:

import "github.com/sirupsen/logrus"

var (
    logger = logrus.New()
    auth   = codeship.NewBasicAuth("username", "password")
)

client, err := codeship.New(auth, codeship.Verbose(true), codeship.Logger(logger))

Contributing

This project follows Codeship's Go best practices. Please review them and make sure your PR follows the guidelines laid out before submitting.

Everyone interacting in the project and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Code of Conduct.

Setup

To install all dependencies and external tools, run:

make setup tools

Testing

make test

We aim for > 80% test coverage. You can view the current coverage info by running:

make cover

Linting

make lint

Other

$ make help

setup                          Install all dependencies
tools                          Install external tools
test                           Run all the tests
integration                    Run integration tests
cover                          Run all the tests and opens the coverage report
fmt                            goimports all go files
lint                           Run all the linters

More Repositories

1

go-best-practices

Codeship Golang Best Practices
Makefile
744
star
2

scripts

Scripts for use on Codeship Basic
Shell
217
star
3

go-retro

Retryable errors in Golang
Go
123
star
4

modelist

Flexible & Customizable Modelstructure for awesome data management.
JavaScript
68
star
5

dns_deploy

Continuous Deployment for your DNS Records
Ruby
51
star
6

codeship-tool-examples

Examples to get you started using Codeship Pro. Download the local CLI to follow along with these examples locally.
Shell
51
star
7

codeship-pro-tutorial

A simple introductory tutorial for the Codeship Docker Infrastructure
Ruby
21
star
8

RIG

An aesthetically unopinionated CSS Framework by Codeship.
CSS
20
star
9

shipyard

A lightweight, CSS framework for Rails & Jekyll applications
Sass
15
star
10

dns-example

How to use dnsdeploy with Codeship
Ruby
14
star
11

ci-guide

Ruby
13
star
12

codeship-ruby

[deprecated] Easily interact with Codeship
Ruby
13
star
13

storybook-surge-github-action

Build and deploy your storybook.js to branch specific Surge.sh sites
Shell
12
star
14

jest-acceptance

Snapshot driven acceptance testing with jest
TypeScript
10
star
15

go-hello-world

**Docker 17.05** A simple hello-world application written in Go to illustrate multi-stage builds, and the builder pattern
Go
9
star
16

atom-codeship-status

Display your Codeship status in the Atom status bar!
CoffeeScript
7
star
17

image-size-webinar

4
star
18

screencast-storyboards

The storyboards for screecasts about how to set up the Codeship with various technologies.
Ruby
2
star
19

node-test-app

JavaScript
1
star
20

metriks-sidekiq

Ruby
1
star
21

ci-workflow-demo

CSS
1
star
22

codeship-tool-example-lb

Just example 18: LB as its own project
Go
1
star