travis: github.com/kevinburke/travis/lib Index | Examples | Files

package travis

import "github.com/kevinburke/travis/lib"

Package travis implements a Go client for talking to the Travis CI API.

Code:

token, err := travis.GetToken("kevinburke")
if err != nil {
    log.Fatal(err)
}
c := travis.NewClient(token)
build, err := c.Builds.Get(context.TODO(), 366686564, "build.jobs", "job.config")
if err != nil {
    log.Fatal(err)
}
stats, err := c.BuildSummary(context.TODO(), build)
if err != nil {
    log.Fatal(err)
}
fmt.Println(stats)

Index

Examples

Package Files

travis.go

Constants

const Host = "https://api.travis-ci.org"

The Host for the API.

const Version = "0.7"

The client Version.

const WebHost = "https://travis-ci.org"

The hostname for viewing builds in a browser.

func GetToken Uses

func GetToken(organization string) (string, error)

GetToken looks in a config file for the Travis API token. organization is your Github username ("kevinburke") or organization ("golang").

type Branch Uses

type Branch struct {
    Type           string `json:"@type"`
    HREF           string `json:"@href"`
    Representation string `json:"@representation"`
    Name           string `json:"name"`
}

Branch represents a Git branch in Travis CI.

https://developer.travis-ci.org/resource/branch#Branch

type Build Uses

type Build struct {
    Type           string         `json:"@type"`
    HREF           string         `json:"@href"`
    Representation string         `json:"@representation"`
    ID             int64          `json:"id"`
    Number         string         `json:"number"`
    State          string         `json:"state"`
    PreviousState  string         `json:"previous_state"`
    Duration       int64          `json:"duration"`
    StartedAt      time.Time      `json:"started_at"`
    FinishedAt     types.NullTime `json:"finished_at"`
    UpdatedAt      time.Time      `json:"updated_at"`
    Branch         Branch         `json:"branch"`
    Repository     Repository     `json:"repository"`
    Commit         *Commit        `json:"commit"`
    Jobs           []*Job         `json:"jobs"`
}

Build represents a Build in Travis CI.

https://developer.travis-ci.org/resource/build#Build

func (Build) WebURL Uses

func (b Build) WebURL() string

WebURL returns the URL for viewing this build in a web browser.

type BuildService Uses

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

func (*BuildService) Get Uses

func (b *BuildService) Get(ctx context.Context, id int64, include ...string) (*Build, error)

Get retrieves the build with the given ID, or an error. include is a list of resources to load eagerly.

type Client Uses

type Client struct {
    *rest.Client

    // For interacting with Build resources.
    Builds *BuildService
    // For interacting with Job resources.
    Jobs *JobService

    // For interacting with Repository resources.
    Repos *RepoService

    Users *UserService
    // contains filtered or unexported fields
}

Client is a HTTP client for interacting with the Travis API.

func NewClient Uses

func NewClient(token string) *Client

NewClient creates a new Client.

func (*Client) BuildSummary Uses

func (c *Client) BuildSummary(ctx context.Context, b *Build) (string, error)

BuildSummary returns statistics about a build as a multiline string.

func (*Client) NewRequest Uses

func (c *Client) NewRequest(method, path string, body io.Reader) (*http.Request, error)

NewRequest creates a new HTTP request to hit the given endpoint.

func (*Client) RequestRetryUnauth Uses

func (c *Client) RequestRetryUnauth(ctx context.Context, method, path string, body io.Reader, data interface{}) error

type Commit Uses

type Commit struct {
    Type           string    `json:"@type"`
    HREF           string    `json:"@href"`
    Representation string    `json:"@representation"`
    SHA            string    `json:"sha"`
    Ref            string    `json:"ref"`
    Message        string    `json:"message"`
    CompareURL     string    `json:"compare_url"`
    CommittedAt    time.Time `json:"committed_at"`
}

Commit represents a Git commit in Travis CI.

https://developer.travis-ci.org/resource/commit#Commit

type Config Uses

type Config struct {
    Language     string   `json:"language"`
    BeforeScript []string `json:"before_script"`
    Script       []string `json:"script"`
    // "true", "false", "required"
    Sudo   string `json:"sudo"`
    OS     string `json:"os"`
    Group  string `json:"group"`
    Extras map[string]interface{}
}

Not documented, but represents your Travis CI config in JSON form.

func (*Config) UnmarshalJSON Uses

func (c *Config) UnmarshalJSON(b []byte) error

type FileConfig Uses

type FileConfig struct {
    // Default token to use
    Default       string
    Organizations map[string]organization
}

FileConfig represents the structure of your ~/cfg/travis config file.

type Job Uses

type Job struct {
    Type           string          `json:"@type"`
    HREF           string          `json:"@href"`
    Representation string          `json:"@representation"`
    Permissions    map[string]bool `json:"@permissions"`
    ID             int64           `json:"id"`
    AllowFailure   bool            `json:"allow_failure"`
    Number         string          `json:"number"`
    State          string          `json:"state"`
    StartedAt      time.Time       `json:"started_at"`
    FinishedAt     types.NullTime  `json:"finished_at"`
    Queue          string          `json:"queue"`
    CreatedAt      time.Time       `json:"created_at"`
    UpdatedAt      time.Time       `json:"updated_at"`

    Config *Config `json:"config"`
}

Job represents a Job in Travis CI. A Build has one or more Jobs.

https://developer.travis-ci.org/resource/job#Job

func (Job) Failed Uses

func (j Job) Failed() bool

type JobService Uses

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

func (*JobService) GetLog Uses

func (j *JobService) GetLog(ctx context.Context, id int64, include ...string) (*Log, error)

GetLog retrieves the job log for the job with the given ID, or an error. include is a list of resources to eager load.

type ListResponse Uses

type ListResponse struct {
    Type           string     `json:"@type"`
    HREF           string     `json:"@href"`
    Representation string     `json:"@representation"`
    Pagination     Pagination `json:"@pagination"`
    // Set this to whatever data you want to deserialize before calling
    // json.Unmarshal/client.Do.
    Data interface{}
}

ListResponse represents a Travis response for a list of resources.

Code:

token, err := travis.GetToken("kevinburke")
if err != nil {
    log.Fatal(err)
}
client := travis.NewClient(token)
req, err := client.NewRequest("GET", "/repo/rails%2Frails/builds?branch.name=master", nil)
if err != nil {
    log.Fatal(err)
}
req = req.WithContext(context.TODO())
builds := make([]*travis.Build, 0)
resp := &travis.ListResponse{
    Data: &builds,
}
if err := client.Do(req, resp); err != nil {
    log.Fatal(err)
}
for i := range builds {
    fmt.Println(builds[i].ID)
}

func (*ListResponse) UnmarshalJSON Uses

func (r *ListResponse) UnmarshalJSON(b []byte) error

type Log Uses

type Log struct {
    Type           string          `json:"@type"`
    HREF           string          `json:"@href"`
    Representation string          `json:"@representation"`
    Permissions    map[string]bool `json:"@permissions"`
    RawLogHREF     string          `json:"@raw_log_href"`
    ID             int64           `json:"id"`
    Content        string          `json:"content"`
    LogParts       []*LogPart      `json:"log_parts"`
}

Log represents a Travis Log object.

https://developer.travis-ci.org/resource/log#Log

type LogPart Uses

type LogPart struct {
    Content string `json:"content"`
    Final   bool   `json:"final"`
    Number  int    `json:"number"`
}

LogPart represents a log part.

type Pagination Uses

type Pagination struct {
    Limit   int  `json:"limit"`
    Offset  int  `json:"offset"`
    Count   int  `json:"count"`
    IsFirst bool `json:"is_first"`
    IsLast  bool `json:"is_last"`
}

Pagination contains details on paging through API responses.

type RepoService Uses

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

func (*RepoService) Activate Uses

func (r *RepoService) Activate(ctx context.Context, slug string) error

Activate builds for the repo with the given slug ("rails/rails")

func (*RepoService) Deactivate Uses

func (r *RepoService) Deactivate(ctx context.Context, slug string) error

Deactivate builds for the repo with the given slug ("rails/rails")

type Repository Uses

type Repository struct {
    Type           string `json:"@type"`
    HREF           string `json:"@href"`
    Representation string `json:"@representation"`
    ID             int64  `json:"id"`
    Name           string `json:"name"`
    Slug           string `json:"slug"`
}

Repository represents a repository in Travis CI.

https://developer.travis-ci.org/resource/repository#Repository

type Step Uses

type Step struct {
    Name       string
    Start, End time.Time
    // Return code of the step. Not every step has a return code; it is -1 if
    // a return code could not be determined.
    ReturnCode int
    Output     string
}

Step represents a step of a build. These get parsed out of the log files; it's not clear that it's possible to get them any other way.

func ParseLog Uses

func ParseLog(log string) []*Step

ParseLog parses a log file, returning the names of each step in the log, and the amount of time each step took.

type User Uses

type User struct {
    Type           string          `json:"@type"`
    HREF           string          `json:"@href"`
    Representation string          `json:"@representation"`
    Permissions    map[string]bool `json:"@permissions"`
    ID             int64           `json:"id"`
    Login          string          `json:"login"`
    Name           string          `json:"name"`
    GithubID       int64           `json:"github_id"`
    AvatarURL      string          `json:"avatar_url"`
    Education      bool            `json:"education"`
    IsSyncing      bool            `json:"is_syncing"`
    SyncedAt       time.Time       `json:"synced_at"`
}

type UserService Uses

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

func (*UserService) Current Uses

func (u *UserService) Current(ctx context.Context) (*User, error)

func (*UserService) Sync Uses

func (u *UserService) Sync(ctx context.Context, id int64) error

https://developer.travis-ci.com/resource/user#sync

Package travis imports 23 packages (graph) and is imported by 1 packages. Updated 2019-03-06. Refresh now. Tools for package owners.