travis

package
v0.0.0-...-2d76400 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

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

Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	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)
}
Output:

Index

Examples

Constants

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

The Host for the API.

View Source
const Version = "0.7"

The client Version.

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

The hostname for viewing builds in a browser.

Variables

This section is empty.

Functions

func GetToken

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").

Types

type Branch

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

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

func (b Build) WebURL() string

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

type BuildService

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

func (*BuildService) Get

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

type Client struct {
	*restclient.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

func NewClient(token string) *Client

NewClient creates a new Client.

func (*Client) BuildSummary

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

BuildSummary returns statistics about a build as a multiline string.

func (*Client) NewRequest

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

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

type Commit

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

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

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

type FileConfig

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

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

func (j Job) Failed() bool

type JobService

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

func (*JobService) GetLog

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

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.

Example
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	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)
	}
}
Output:

func (*ListResponse) UnmarshalJSON

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

type Log

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

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

LogPart represents a log part.

type Pagination

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

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

func (*RepoService) Activate

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

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

func (*RepoService) Deactivate

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

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

type Repository

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

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

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

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

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

func (*UserService) Current

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

Jump to

Keyboard shortcuts

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