github.com/crosbymichael/octokat@v0.0.0-20160826194511-076a32289ed5/statuses.go (about) 1 package octokat 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 type Status struct { 9 CreatedAt time.Time `json:"created_at,omitempty"` 10 UpdatedAt time.Time `json:"updated_at,omitempty"` 11 State string `json:"state,omitempty"` 12 TargetURL string `json:"target_url,omitempty"` 13 Description string `json:"description,omitempty"` 14 ID int `json:"id,omitempty"` 15 URL string `json:"url,omitempty"` 16 Creator User `json:"creator,omitempty"` 17 Context string `json:"context,omitempty"` 18 } 19 20 type StatusOptions struct { 21 State string `json:"state"` 22 Description string `json:"description"` 23 URL string `json:"target_url"` 24 Context string `json:"context"` 25 } 26 27 type CombinedStatus struct { 28 State string `json:"state"` 29 Sha string `json:"sha"` 30 TotalCount int `json:"total_count"` 31 Statuses []Status `json:"statuses"` 32 } 33 34 // List all statuses for a given commit 35 // 36 // See http://developer.github.com/v3/repos/statuses 37 func (c *Client) Statuses(repo Repo, sha string, options *Options) (statuses []Status, err error) { 38 path := fmt.Sprintf("repos/%s/statuses/%s", repo, sha) 39 err = c.jsonGet(path, options, &statuses) 40 return 41 } 42 43 func (c *Client) CombinedStatus(repo Repo, sha string, options *Options) (status CombinedStatus, err error) { 44 path := fmt.Sprintf("repos/%s/commits/%s/status", repo, sha) 45 err = c.jsonGet(path, options, &status) 46 return status, err 47 } 48 49 // Set a status for a given sha 50 // 51 // See https://developer.github.com/v3/repos/statuses/#create-a-status 52 func (c *Client) SetStatus(repo Repo, sha string, options *StatusOptions) (status *Status, err error) { 53 path := fmt.Sprintf("repos/%s/statuses/%s", repo, sha) 54 mutOptions := &Options{ 55 Params: map[string]string{ 56 "state": options.State, 57 "description": options.Description, 58 "target_url": options.URL, 59 "context": options.Context, 60 }, 61 } 62 err = c.jsonPost(path, mutOptions, &status) 63 return 64 }