MCPcopy Create free account
hub / github.com/google/go-github / TestRepositories_EditBranches

Function TestRepositories_EditBranches

test/integration/repos_test.go:75–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestRepositories_EditBranches(t *testing.T) {
76 skipIfMissingAuth(t)
77
78 repo := createRandomTestRepository(t, "", true)
79
80 branch, _, err := client.Repositories.GetBranch(t.Context(), *repo.Owner.Login, *repo.Name, "master", 0)
81 if err != nil {
82 t.Fatalf("Repositories.GetBranch() returned error: %v", err)
83 }
84
85 if *branch.Protected {
86 t.Fatalf("Branch %v of repo %v is already protected", "master", *repo.Name)
87 }
88
89 protectionRequest := &github.ProtectionRequest{
90 RequiredStatusChecks: &github.RequiredStatusChecks{
91 Strict: true,
92 Contexts: &[]string{"continuous-integration"},
93 },
94 RequiredPullRequestReviews: &github.PullRequestReviewsEnforcementRequest{
95 DismissStaleReviews: true,
96 },
97 EnforceAdmins: true,
98 // TODO: Only organization repositories can have users and team restrictions.
99 // In order to be able to test these Restrictions, need to add support
100 // for creating temporary organization repositories.
101 Restrictions: nil,
102 BlockCreations: github.Ptr(false),
103 LockBranch: github.Ptr(false),
104 AllowForkSyncing: github.Ptr(false),
105 }
106
107 protection, _, err := client.Repositories.UpdateBranchProtection(t.Context(), *repo.Owner.Login, *repo.Name, "master", protectionRequest)
108 if err != nil {
109 t.Fatalf("Repositories.UpdateBranchProtection() returned error: %v", err)
110 }
111
112 want := &github.Protection{
113 RequiredStatusChecks: &github.RequiredStatusChecks{
114 Strict: true,
115 Contexts: &[]string{"continuous-integration"},
116 },
117 RequiredPullRequestReviews: &github.PullRequestReviewsEnforcement{
118 DismissStaleReviews: true,
119 RequiredApprovingReviewCount: 0,
120 },
121 EnforceAdmins: &github.AdminEnforcement{
122 URL: github.Ptr("https://api.github.com/repos/" + *repo.Owner.Login + "/" + *repo.Name + "/branches/master/protection/enforce_admins"),
123 Enabled: true,
124 },
125 Restrictions: nil,
126 BlockCreations: &github.BlockCreations{
127 Enabled: github.Ptr(false),
128 },
129 LockBranch: &github.LockBranch{
130 Enabled: github.Ptr(false),
131 },
132 AllowForkSyncing: &github.AllowForkSyncing{

Callers

nothing calls this directly

Calls 7

PtrFunction · 0.92
skipIfMissingAuthFunction · 0.85
EqualMethod · 0.80
GetBranchMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…