2019-05-07 01:12:51 +00:00
|
|
|
// Copyright 2013 The go-github AUTHORS. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RepoStatus represents the status of a repository at a particular reference.
|
|
|
|
type RepoStatus struct {
|
2020-07-31 14:22:34 +00:00
|
|
|
ID *int64 `json:"id,omitempty"`
|
|
|
|
NodeID *string `json:"node_id,omitempty"`
|
|
|
|
URL *string `json:"url,omitempty"`
|
2019-05-07 01:12:51 +00:00
|
|
|
|
|
|
|
// State is the current state of the repository. Possible values are:
|
|
|
|
// pending, success, error, or failure.
|
|
|
|
State *string `json:"state,omitempty"`
|
|
|
|
|
|
|
|
// TargetURL is the URL of the page representing this status. It will be
|
|
|
|
// linked from the GitHub UI to allow users to see the source of the status.
|
|
|
|
TargetURL *string `json:"target_url,omitempty"`
|
|
|
|
|
|
|
|
// Description is a short high level summary of the status.
|
|
|
|
Description *string `json:"description,omitempty"`
|
|
|
|
|
|
|
|
// A string label to differentiate this status from the statuses of other systems.
|
|
|
|
Context *string `json:"context,omitempty"`
|
|
|
|
|
2021-10-26 07:19:21 +00:00
|
|
|
// AvatarURL is the URL of the avatar of this status.
|
|
|
|
AvatarURL *string `json:"avatar_url,omitempty"`
|
|
|
|
|
2019-05-07 01:12:51 +00:00
|
|
|
Creator *User `json:"creator,omitempty"`
|
|
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
|
|
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r RepoStatus) String() string {
|
|
|
|
return Stringify(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListStatuses lists the statuses of a repository at the specified
|
|
|
|
// reference. ref can be a SHA, a branch name, or a tag name.
|
|
|
|
//
|
2021-08-10 09:49:43 +00:00
|
|
|
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-commit-statuses-for-a-reference
|
2020-07-31 14:22:34 +00:00
|
|
|
func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opts *ListOptions) ([]*RepoStatus, *Response, error) {
|
|
|
|
u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, refURLEscape(ref))
|
|
|
|
u, err := addOptions(u, opts)
|
2019-05-07 01:12:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var statuses []*RepoStatus
|
|
|
|
resp, err := s.client.Do(ctx, req, &statuses)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return statuses, resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateStatus creates a new status for a repository at the specified
|
|
|
|
// reference. Ref can be a SHA, a branch name, or a tag name.
|
|
|
|
//
|
2021-08-10 09:49:43 +00:00
|
|
|
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-commit-status
|
2019-05-07 01:12:51 +00:00
|
|
|
func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) {
|
2020-07-31 14:22:34 +00:00
|
|
|
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, refURLEscape(ref))
|
2019-05-07 01:12:51 +00:00
|
|
|
req, err := s.client.NewRequest("POST", u, status)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
repoStatus := new(RepoStatus)
|
|
|
|
resp, err := s.client.Do(ctx, req, repoStatus)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return repoStatus, resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CombinedStatus represents the combined status of a repository at a particular reference.
|
|
|
|
type CombinedStatus struct {
|
|
|
|
// State is the combined state of the repository. Possible values are:
|
|
|
|
// failure, pending, or success.
|
|
|
|
State *string `json:"state,omitempty"`
|
|
|
|
|
2020-07-31 14:22:34 +00:00
|
|
|
Name *string `json:"name,omitempty"`
|
|
|
|
SHA *string `json:"sha,omitempty"`
|
|
|
|
TotalCount *int `json:"total_count,omitempty"`
|
|
|
|
Statuses []*RepoStatus `json:"statuses,omitempty"`
|
2019-05-07 01:12:51 +00:00
|
|
|
|
|
|
|
CommitURL *string `json:"commit_url,omitempty"`
|
|
|
|
RepositoryURL *string `json:"repository_url,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s CombinedStatus) String() string {
|
|
|
|
return Stringify(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCombinedStatus returns the combined status of a repository at the specified
|
|
|
|
// reference. ref can be a SHA, a branch name, or a tag name.
|
|
|
|
//
|
2021-08-10 09:49:43 +00:00
|
|
|
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#get-the-combined-status-for-a-specific-reference
|
2020-07-31 14:22:34 +00:00
|
|
|
func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opts *ListOptions) (*CombinedStatus, *Response, error) {
|
|
|
|
u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, refURLEscape(ref))
|
|
|
|
u, err := addOptions(u, opts)
|
2019-05-07 01:12:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
status := new(CombinedStatus)
|
|
|
|
resp, err := s.client.Do(ctx, req, status)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return status, resp, nil
|
|
|
|
}
|