Repository: google/go-github
Pull request #2632 (2023-01-18 14:08:01)

Add httpcache code example to README.md
Relates to: #2631.

google-cla[bot]: Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this [failed invocation](https://github.com/google/go-github/pull/2632/checks?check_run_id=10726968821) of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2632?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2632](https://codecov.io/gh/google/go-github/pull/2632?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (e8019a0) into [master](https://codecov.io/gh/google/go-github/commit/34cc7b4a47c49f893bfa9d451883f752d13e73ed?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (34cc7b4) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2632   +/-   ##
=======================================
  Coverage   98.03%   98.03%           
=======================================
  Files         130      130           
  Lines       11144    11144           
=======================================
  Hits        10925    10925           
  Misses        150      150           
  Partials       69       69           
```



Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/README.md b/README.md
index 030fd090..744b11b4 100644
--- a/README.md
+++ b/README.md
@@ -209,7 +209,22 @@ The GitHub API has good support for conditional requests which will help
 prevent you from burning through your rate limit, as well as help speed up your
 application. `go-github` does not handle conditional requests directly, but is
 instead designed to work with a caching `http.Transport`. We recommend using
-https://github.com/gregjones/httpcache for that.
+https://github.com/gregjones/httpcache for that. For example:
+
+```go
+import "github.com/gregjones/httpcache"
+
+	ts := oauth2.StaticTokenSource(
+		&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
+	)
+	tc := &http.Client{
+		Transport: &oauth2.Transport{
+			Base:   httpcache.NewMemoryCacheTransport(),
+			Source: ts,
+		},
+	}
+	client := github.NewClient(tc)
+```
 
 Learn more about GitHub conditional requests at
 https://docs.github.com/en/rest/overview/resources-in-the-rest-api#conditional-requests.
diff --git a/github/repos.go b/github/repos.go
index f27444b7..1f6a3181 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -1180,7 +1180,7 @@ type DismissalRestrictionsRequest struct {
 	Users *[]string `json:"users,omitempty"`
 	// The list of team slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
 	Teams *[]string `json:"teams,omitempty"`
-	// The list of apps which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
+	// The list of app slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
 	Apps *[]string `json:"apps,omitempty"`
 }
 
@@ -1676,6 +1676,8 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo
 // It requires the GitHub apps to have `write` access to the `content` permission.
 //
 // GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#get-apps-with-access-to-the-protected-branch
+//
+// Deprecated: Please use ListAppRestrictions instead.
 func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) {
 	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
 	req, err := s.client.NewRequest("GET", u, nil)
@@ -1692,6 +1694,16 @@ func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch
 	return apps, resp, nil
 }
 
+// ListAppRestrictions lists the GitHub apps that have push access to a given protected branch.
+// It requires the GitHub apps to have `write` access to the `content` permission.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#get-apps-with-access-to-the-protected-branch
+//
+// Note: This is a wrapper around ListApps so a naming convention with ListUserRestrictions and ListTeamRestrictions is preserved.
+func (s *RepositoriesService) ListAppRestrictions(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) {
+	return s.ListApps(ctx, owner, repo, branch)
+}
+
 // ReplaceAppRestrictions replaces the apps that have push access to a given protected branch.
 // It removes all apps that previously had push access and grants push access to the new list of apps.
 // It requires the GitHub apps to have `write` access to the `content` permission.
@@ -1699,20 +1711,20 @@ func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch
 // Note: The list of users, apps, and teams in total is limited to 100 items.
 //
 // GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#set-app-access-restrictions
-func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) {
+func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
 	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
-	req, err := s.client.NewRequest("PUT", u, slug)
+	req, err := s.client.NewRequest("PUT", u, apps)
 	if err != nil {
 		return nil, nil, err
 	}
 
-	var apps []*App
-	resp, err := s.client.Do(ctx, req, &apps)
+	var newApps []*App
+	resp, err := s.client.Do(ctx, req, &newApps)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return apps, resp, nil
+	return newApps, resp, nil
 }
 
 // AddAppRestrictions grants the specified apps push access to a given protected branch.
@@ -1721,42 +1733,216 @@ func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner,
 // Note: The list of users, apps, and teams in total is limited to 100 items.
 //
 // GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#add-app-access-restrictions
-func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) {
+func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
 	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
-	req, err := s.client.NewRequest("POST", u, slug)
+	req, err := s.client.NewRequest("POST", u, apps)
 	if err != nil {
 		return nil, nil, err
 	}
 
-	var apps []*App
-	resp, err := s.client.Do(ctx, req, &apps)
+	var newApps []*App
+	resp, err := s.client.Do(ctx, req, &newApps)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return apps, resp, nil
+	return newApps, resp, nil
 }
 
-// RemoveAppRestrictions removes the ability of an app to push to this branch.
+// RemoveAppRestrictions removes the restrictions of an app from pushing to this branch.
 // It requires the GitHub apps to have `write` access to the `content` permission.
 //
 // Note: The list of users, apps, and teams in total is limited to 100 items.
 //
 // GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#remove-app-access-restrictions
-func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner, repo, branch string, slug []string) ([]*App, *Response, error) {
+func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
 	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, branch)
-	req, err := s.client.NewRequest("DELETE", u, slug)
+	req, err := s.client.NewRequest("DELETE", u, apps)
 	if err != nil {
 		return nil, nil, err
 	}
 
-	var apps []*App
-	resp, err := s.client.Do(ctx, req, &apps)
+	var newApps []*App
+	resp, err := s.client.Do(ctx, req, &newApps)
 	if err != nil {
 		return nil, resp, err
 	}
 
-	return apps, resp, nil
+	return newApps, resp, nil
+}
+
+// ListTeamRestrictions lists the GitHub teams that have push access to a given protected branch.
+// It requires the GitHub teams to have `write` access to the `content` permission.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#get-teams-with-access-to-the-protected-branch
+func (s *RepositoriesService) ListTeamRestrictions(ctx context.Context, owner, repo, branch string) ([]*Team, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, branch)
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var teams []*Team
+	resp, err := s.client.Do(ctx, req, &teams)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return teams, resp, nil
+}
+
+// ReplaceTeamRestrictions replaces the team that have push access to a given protected branch.
+// This removes all teams that previously had push access and grants push access to the new list of teams.
+// It requires the GitHub teams to have `write` access to the `content` permission.
+//
+// Note: The list of users, apps, and teams in total is limited to 100 items.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#set-team-access-restrictions
+func (s *RepositoriesService) ReplaceTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, branch)
+	req, err := s.client.NewRequest("PUT", u, teams)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var newTeams []*Team
+	resp, err := s.client.Do(ctx, req, &newTeams)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return newTeams, resp, nil
+}
+
+// AddTeamRestrictions grants the specified teams push access to a given protected branch.
+// It requires the GitHub teams to have `write` access to the `content` permission.
+//
+// Note: The list of users, apps, and teams in total is limited to 100 items.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#add-team-access-restrictions
+func (s *RepositoriesService) AddTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, branch)
+	req, err := s.client.NewRequest("POST", u, teams)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var newTeams []*Team
+	resp, err := s.client.Do(ctx, req, &newTeams)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return newTeams, resp, nil
+}
+
+// RemoveTeamRestrictions removes the restrictions of a team from pushing to this branch.
+// It requires the GitHub teams to have `write` access to the `content` permission.
+//
+// Note: The list of users, apps, and teams in total is limited to 100 items.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#remove-team-access-restrictions
+func (s *RepositoriesService) RemoveTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, branch)
+	req, err := s.client.NewRequest("DELETE", u, teams)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var newTeams []*Team
+	resp, err := s.client.Do(ctx, req, &newTeams)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return newTeams, resp, nil
+}
+
+// ListUserRestrictions lists the GitHub users that have push access to a given protected branch.
+// It requires the GitHub users to have `write` access to the `content` permission.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#get-users-with-access-to-the-protected-branch
+func (s *RepositoriesService) ListUserRestrictions(ctx context.Context, owner, repo, branch string) ([]*User, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, branch)
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var users []*User
+	resp, err := s.client.Do(ctx, req, &users)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return users, resp, nil
+}
+
+// ReplaceUserRestrictions replaces the user that have push access to a given protected branch.
+// It removes all users that previously had push access and grants push access to the new list of users.
+// It requires the GitHub users to have `write` access to the `content` permission.
+//
+// Note: The list of users, apps, and teams in total is limited to 100 items.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#set-team-access-restrictions
+func (s *RepositoriesService) ReplaceUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, branch)
+	req, err := s.client.NewRequest("PUT", u, users)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var newUsers []*User
+	resp, err := s.client.Do(ctx, req, &newUsers)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return newUsers, resp, nil
+}
+
+// AddUserRestrictions grants the specified users push access to a given protected branch.
+// It requires the GitHub users to have `write` access to the `content` permission.
+//
+// Note: The list of users, apps, and teams in total is limited to 100 items.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#add-team-access-restrictions
+func (s *RepositoriesService) AddUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, branch)
+	req, err := s.client.NewRequest("POST", u, users)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var newUsers []*User
+	resp, err := s.client.Do(ctx, req, &newUsers)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return newUsers, resp, nil
+}
+
+// RemoveUserRestrictions removes the restrictions of a user from pushing to this branch.
+// It requires the GitHub users to have `write` access to the `content` permission.
+//
+// Note: The list of users, apps, and teams in total is limited to 100 items.
+//
+// GitHub API docs: https://docs.github.com/en/rest/branches/branch-protection#remove-team-access-restrictions
+func (s *RepositoriesService) RemoveUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, branch)
+	req, err := s.client.NewRequest("DELETE", u, users)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	var newUsers []*User
+	resp, err := s.client.Do(ctx, req, &newUsers)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return newUsers, resp, nil
 }
 
 // TransferRequest represents a request to transfer a repository.


Test patch:
diff --git a/github/repos_test.go b/github/repos_test.go
index 4a3f4f59..5f59216b 100644
--- a/github/repos_test.go
+++ b/github/repos_test.go
@@ -2760,7 +2760,7 @@ func TestRepositoriesService_ReplaceAllTopics_emptySlice(t *testing.T) {
 	}
 }
 
-func TestRepositoriesService_ListApps(t *testing.T) {
+func TestRepositoriesService_ListAppRestrictions(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
 
@@ -2769,19 +2769,19 @@ func TestRepositoriesService_ListApps(t *testing.T) {
 	})
 
 	ctx := context.Background()
-	_, _, err := client.Repositories.ListApps(ctx, "o", "r", "b")
+	_, _, err := client.Repositories.ListAppRestrictions(ctx, "o", "r", "b")
 	if err != nil {
-		t.Errorf("Repositories.ListApps returned error: %v", err)
+		t.Errorf("Repositories.ListAppRestrictions returned error: %v", err)
 	}
 
-	const methodName = "ListApps"
+	const methodName = "ListAppRestrictions"
 	testBadOptions(t, methodName, func() (err error) {
-		_, _, err = client.Repositories.ListApps(ctx, "\n", "\n", "\n")
+		_, _, err = client.Repositories.ListAppRestrictions(ctx, "\n", "\n", "\n")
 		return err
 	})
 
 	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
-		got, resp, err := client.Repositories.ListApps(ctx, "o", "r", "b")
+		got, resp, err := client.Repositories.ListAppRestrictions(ctx, "o", "r", "b")
 		if got != nil {
 			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
 		}
@@ -2899,6 +2899,284 @@ func TestRepositoriesService_RemoveAppRestrictions(t *testing.T) {
 	})
 }
 
+func TestRepositoriesService_ListTeamRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/teams", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+	})
+
+	ctx := context.Background()
+	_, _, err := client.Repositories.ListTeamRestrictions(ctx, "o", "r", "b")
+	if err != nil {
+		t.Errorf("Repositories.ListTeamRestrictions returned error: %v", err)
+	}
+
+	const methodName = "ListTeamRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.ListTeamRestrictions(ctx, "\n", "\n", "\n")
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.ListTeamRestrictions(ctx, "o", "r", "b")
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
+func TestRepositoriesService_ReplaceTeamRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/teams", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PUT")
+		fmt.Fprint(w, `[{
+				"name": "octocat"
+			}]`)
+	})
+	input := []string{"octocat"}
+	ctx := context.Background()
+	got, _, err := client.Repositories.ReplaceTeamRestrictions(ctx, "o", "r", "b", input)
+	if err != nil {
+		t.Errorf("Repositories.ReplaceTeamRestrictions returned error: %v", err)
+	}
+	want := []*Team{
+		{Name: String("octocat")},
+	}
+	if !cmp.Equal(got, want) {
+		t.Errorf("Repositories.ReplaceTeamRestrictions returned %+v, want %+v", got, want)
+	}
+
+	const methodName = "ReplaceTeamRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.ReplaceTeamRestrictions(ctx, "\n", "\n", "\n", input)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.ReplaceTeamRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
+func TestRepositoriesService_AddTeamRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/teams", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "POST")
+		fmt.Fprint(w, `[{
+				"name": "octocat"
+			}]`)
+	})
+	input := []string{"octocat"}
+	ctx := context.Background()
+	got, _, err := client.Repositories.AddTeamRestrictions(ctx, "o", "r", "b", input)
+	if err != nil {
+		t.Errorf("Repositories.AddTeamRestrictions returned error: %v", err)
+	}
+	want := []*Team{
+		{Name: String("octocat")},
+	}
+	if !cmp.Equal(got, want) {
+		t.Errorf("Repositories.AddTeamRestrictions returned %+v, want %+v", got, want)
+	}
+
+	const methodName = "AddTeamRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.AddTeamRestrictions(ctx, "\n", "\n", "\n", input)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.AddTeamRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
+func TestRepositoriesService_RemoveTeamRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/teams", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+		fmt.Fprint(w, `[]`)
+	})
+	input := []string{"octocat"}
+	ctx := context.Background()
+	got, _, err := client.Repositories.RemoveTeamRestrictions(ctx, "o", "r", "b", input)
+	if err != nil {
+		t.Errorf("Repositories.RemoveTeamRestrictions returned error: %v", err)
+	}
+	want := []*Team{}
+	if !cmp.Equal(got, want) {
+		t.Errorf("Repositories.RemoveTeamRestrictions returned %+v, want %+v", got, want)
+	}
+
+	const methodName = "RemoveTeamRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.RemoveTeamRestrictions(ctx, "\n", "\n", "\n", input)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.RemoveTeamRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
+func TestRepositoriesService_ListUserRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/users", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+	})
+
+	ctx := context.Background()
+	_, _, err := client.Repositories.ListUserRestrictions(ctx, "o", "r", "b")
+	if err != nil {
+		t.Errorf("Repositories.ListUserRestrictions returned error: %v", err)
+	}
+
+	const methodName = "ListUserRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.ListUserRestrictions(ctx, "\n", "\n", "\n")
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.ListUserRestrictions(ctx, "o", "r", "b")
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
+func TestRepositoriesService_ReplaceUserRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/users", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PUT")
+		fmt.Fprint(w, `[{
+				"name": "octocat"
+			}]`)
+	})
+	input := []string{"octocat"}
+	ctx := context.Background()
+	got, _, err := client.Repositories.ReplaceUserRestrictions(ctx, "o", "r", "b", input)
+	if err != nil {
+		t.Errorf("Repositories.ReplaceUserRestrictions returned error: %v", err)
+	}
+	want := []*User{
+		{Name: String("octocat")},
+	}
+	if !cmp.Equal(got, want) {
+		t.Errorf("Repositories.ReplaceUserRestrictions returned %+v, want %+v", got, want)
+	}
+
+	const methodName = "ReplaceUserRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.ReplaceUserRestrictions(ctx, "\n", "\n", "\n", input)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.ReplaceUserRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
+func TestRepositoriesService_AddUserRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/users", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "POST")
+		fmt.Fprint(w, `[{
+				"name": "octocat"
+			}]`)
+	})
+	input := []string{"octocat"}
+	ctx := context.Background()
+	got, _, err := client.Repositories.AddUserRestrictions(ctx, "o", "r", "b", input)
+	if err != nil {
+		t.Errorf("Repositories.AddUserRestrictions returned error: %v", err)
+	}
+	want := []*User{
+		{Name: String("octocat")},
+	}
+	if !cmp.Equal(got, want) {
+		t.Errorf("Repositories.AddUserRestrictions returned %+v, want %+v", got, want)
+	}
+
+	const methodName = "AddUserRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.AddUserRestrictions(ctx, "\n", "\n", "\n", input)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.AddUserRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
+func TestRepositoriesService_RemoveUserRestrictions(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/o/r/branches/b/protection/restrictions/users", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "DELETE")
+		fmt.Fprint(w, `[]`)
+	})
+	input := []string{"octocat"}
+	ctx := context.Background()
+	got, _, err := client.Repositories.RemoveUserRestrictions(ctx, "o", "r", "b", input)
+	if err != nil {
+		t.Errorf("Repositories.RemoveUserRestrictions returned error: %v", err)
+	}
+	want := []*User{}
+	if !cmp.Equal(got, want) {
+		t.Errorf("Repositories.RemoveUserRestrictions returned %+v, want %+v", got, want)
+	}
+
+	const methodName = "RemoveUserRestrictions"
+	testBadOptions(t, methodName, func() (err error) {
+		_, _, err = client.Repositories.RemoveUserRestrictions(ctx, "\n", "\n", "\n", input)
+		return err
+	})
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		got, resp, err := client.Repositories.RemoveUserRestrictions(ctx, "o", "r", "b", input)
+		if got != nil {
+			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
+		}
+		return resp, err
+	})
+}
+
 func TestRepositoriesService_Transfer(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()