Skip to content

Commit 2c1b36c

Browse files
authored
Add Protection to Branch struct (#3095)
1 parent 0e3ab58 commit 2c1b36c

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

github/github-accessors.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,14 @@ type Branch struct {
10031003
Name *string `json:"name,omitempty"`
10041004
Commit *RepositoryCommit `json:"commit,omitempty"`
10051005
Protected *bool `json:"protected,omitempty"`
1006+
1007+
// Protection will always be included in APIs which return the
1008+
// 'Branch With Protection' schema such as 'Get a branch', but may
1009+
// not be included in APIs that return the `Short Branch` schema
1010+
// such as 'List branches'. In such cases, if branch protection is
1011+
// enabled, Protected will be `true` but this will be nil, and
1012+
// additional protection details can be obtained by calling GetBranch().
1013+
Protection *Protection `json:"protection,omitempty"`
10061014
}
10071015

10081016
// Protection represents a repository branch's protection.

github/repos_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ func TestRepositoriesService_GetBranch(t *testing.T) {
930930
for _, test := range tests {
931931
mux.HandleFunc(test.urlPath, func(w http.ResponseWriter, r *http.Request) {
932932
testMethod(t, r, "GET")
933-
fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true}`)
933+
fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true, "protection":{"required_status_checks":{"contexts":["c"]}}}`)
934934
})
935935

936936
ctx := context.Background()
@@ -948,6 +948,11 @@ func TestRepositoriesService_GetBranch(t *testing.T) {
948948
},
949949
},
950950
Protected: Bool(true),
951+
Protection: &Protection{
952+
RequiredStatusChecks: &RequiredStatusChecks{
953+
Contexts: &[]string{"c"},
954+
},
955+
},
951956
}
952957

953958
if !cmp.Equal(branch, want) {
@@ -1000,7 +1005,7 @@ func TestRepositoriesService_GetBranch_StatusMovedPermanently_followRedirects(t
10001005
})
10011006
mux.HandleFunc("/repos/o/r/branches/br", func(w http.ResponseWriter, r *http.Request) {
10021007
testMethod(t, r, "GET")
1003-
fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true}`)
1008+
fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true, "protection":{"required_status_checks":{"contexts":["c"]}}}`)
10041009
})
10051010
ctx := context.Background()
10061011
branch, resp, err := client.Repositories.GetBranch(ctx, "o", "r", "b", 1)
@@ -1020,6 +1025,11 @@ func TestRepositoriesService_GetBranch_StatusMovedPermanently_followRedirects(t
10201025
},
10211026
},
10221027
Protected: Bool(true),
1028+
Protection: &Protection{
1029+
RequiredStatusChecks: &RequiredStatusChecks{
1030+
Contexts: &[]string{"c"},
1031+
},
1032+
},
10231033
}
10241034
if !cmp.Equal(branch, want) {
10251035
t.Errorf("Repositories.GetBranch returned %+v, want %+v", branch, want)

0 commit comments

Comments
 (0)