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 ¶
- Constants
- func GetToken(organization string) (string, error)
- type Branch
- type Build
- type BuildService
- type Client
- type Commit
- type Config
- type FileConfig
- type Job
- type JobService
- type ListResponse
- type Log
- type LogPart
- type Pagination
- type RepoService
- type Repository
- type Step
- type User
- type UserService
Examples ¶
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.
Variables ¶
This section is empty.
Functions ¶
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.
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.
type BuildService ¶
type BuildService struct {
// contains filtered or unexported fields
}
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 (*Client) BuildSummary ¶
BuildSummary returns statistics about a build as a multiline string.
func (*Client) NewRequest ¶
NewRequest creates a new HTTP request to hit the given endpoint.
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.
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 ¶
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.
type JobService ¶
type JobService struct {
// contains filtered or unexported fields
}
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.
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.
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
}