mirror of
https://github.com/google/go-github.git
synced 2026-10-28 16:34:37 +08:00
feat: Add required field on combined status responses (#4586)
This commit is contained in:
1 parent
93344bc9bf
commit
9a9d77c007
5 files changed
+32
-3
No files matched your search
@@ -39462,6 +39462,14 @@ func (r *RepoStatus) GetNodeID() string {
|
||||
return *r.NodeID
|
||||
}
|
||||
|
||||
// GetRequired returns the Required field if it's non-nil, zero value otherwise.
|
||||
func (r *RepoStatus) GetRequired() bool {
|
||||
if r == nil || r.Required == nil {
|
||||
return false
|
||||
}
|
||||
return *r.Required
|
||||
}
|
||||
|
||||
// GetState returns the State field if it's non-nil, zero value otherwise.
|
||||
func (r *RepoStatus) GetState() string {
|
||||
if r == nil || r.State == nil {
|
||||
|
||||
@@ -49195,6 +49195,17 @@ func TestRepoStatus_GetNodeID(tt *testing.T) {
|
||||
r.GetNodeID()
|
||||
}
|
||||
|
||||
func TestRepoStatus_GetRequired(tt *testing.T) {
|
||||
tt.Parallel()
|
||||
var zeroValue bool
|
||||
r := &RepoStatus{Required: &zeroValue}
|
||||
r.GetRequired()
|
||||
r = &RepoStatus{}
|
||||
r.GetRequired()
|
||||
r = nil
|
||||
r.GetRequired()
|
||||
}
|
||||
|
||||
func TestRepoStatus_GetState(tt *testing.T) {
|
||||
tt.Parallel()
|
||||
var zeroValue string
|
||||
|
||||
@@ -1952,8 +1952,9 @@ func TestRepoStatus_String(t *testing.T) {
|
||||
Creator: &User{},
|
||||
CreatedAt: &Timestamp{},
|
||||
UpdatedAt: &Timestamp{},
|
||||
Required: new(false),
|
||||
}
|
||||
want := `github.RepoStatus{ID:0, NodeID:"", URL:"", State:"", TargetURL:"", Description:"", Context:"", AvatarURL:"", Creator:github.User{}, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}`
|
||||
want := `github.RepoStatus{ID:0, NodeID:"", URL:"", State:"", TargetURL:"", Description:"", Context:"", AvatarURL:"", Creator:github.User{}, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Required:false}`
|
||||
if got := v.String(); got != want {
|
||||
t.Errorf("RepoStatus.String = %v, want %v", got, want)
|
||||
}
|
||||
|
||||
@@ -36,6 +36,11 @@ type RepoStatus struct {
|
||||
Creator *User `json:"creator,omitempty"`
|
||||
CreatedAt *Timestamp `json:"created_at,omitempty"`
|
||||
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
|
||||
|
||||
// Required indicates whether this status is required for merging. Only
|
||||
// populated in combined status responses; nil means the API did not include
|
||||
// the field (e.g. when not part of a branch-protection rule).
|
||||
Required *bool `json:"required,omitempty"`
|
||||
}
|
||||
|
||||
func (r RepoStatus) String() string {
|
||||
|
||||
@@ -113,7 +113,7 @@ func TestRepositoriesService_GetCombinedStatus(t *testing.T) {
|
||||
mux.HandleFunc("/repos/o/r/commits/r/status", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, "GET")
|
||||
testFormValues(t, r, values{"page": "2"})
|
||||
fmt.Fprint(w, `{"state":"success", "statuses":[{"id":1}]}`)
|
||||
fmt.Fprint(w, `{"state":"success", "statuses":[{"id":1,"required":true},{"id":2,"required":false},{"id":3}]}`)
|
||||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
@@ -123,7 +123,11 @@ func TestRepositoriesService_GetCombinedStatus(t *testing.T) {
|
||||
t.Errorf("Repositories.GetCombinedStatus returned error: %v", err)
|
||||
}
|
||||
|
||||
want := &CombinedStatus{State: new("success"), Statuses: []*RepoStatus{{ID: new(int64(1))}}}
|
||||
want := &CombinedStatus{State: new("success"), Statuses: []*RepoStatus{
|
||||
{ID: new(int64(1)), Required: new(true)},
|
||||
{ID: new(int64(2)), Required: new(false)},
|
||||
{ID: new(int64(3))}, // Required is nil when absent from the response
|
||||
}}
|
||||
if !cmp.Equal(status, want) {
|
||||
t.Errorf("Repositories.GetCombinedStatus returned %+v, want %+v", status, want)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user