Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Repository struct {
AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
AllowAutoMerge *bool `json:"allow_auto_merge,omitempty"`
AllowForking *bool `json:"allow_forking,omitempty"`
WebCommitSignoffRequired *bool `json:"web_commit_signoff_required,omitempty"`
DeleteBranchOnMerge *bool `json:"delete_branch_on_merge,omitempty"`
UseSquashPRTitleAsDefault *bool `json:"use_squash_pr_title_as_default,omitempty"`
SquashMergeCommitTitle *string `json:"squash_merge_commit_title,omitempty"` // Can be one of: "PR_TITLE", "COMMIT_OR_PR_TITLE"
Expand Down Expand Up @@ -843,10 +844,18 @@ type Protection struct {
AllowForcePushes *AllowForcePushes `json:"allow_force_pushes"`
AllowDeletions *AllowDeletions `json:"allow_deletions"`
RequiredConversationResolution *RequiredConversationResolution `json:"required_conversation_resolution"`
BlockCreations *BlockCreations `json:"block_creations,omitempty"`
LockBranch *LockBranch `json:"lock_branch,omitempty"`
AllowForkSyncing *AllowForkSyncing `json:"allow_fork_syncing,omitempty"`
}

// BlockCreations represents whether users can push changes that create branches. If this is true, this
// setting blocks pushes that create new branches, unless the push is initiated by a user, team, or app
// which has the ability to push.
type BlockCreations struct {
Enabled *bool `json:"enabled,omitempty"`
}

// LockBranch represents if the branch is marked as read-only. If this is true, users will not be able to push to the branch.
type LockBranch struct {
Enabled *bool `json:"enabled,omitempty"`
Expand Down Expand Up @@ -994,6 +1003,14 @@ type ProtectionRequest struct {
// RequiredConversationResolution, if set to true, requires all comments
// on the pull request to be resolved before it can be merged to a protected branch.
RequiredConversationResolution *bool `json:"required_conversation_resolution,omitempty"`
// BlockCreations, if set to true, will cause the restrictions setting to also block pushes
// which create new branches, unless initiated by a user, team, app with the ability to push.
BlockCreations *bool `json:"block_creations,omitempty"`
// LockBranch, if set to true, will prevent users from pushing to the branch.
LockBranch *bool `json:"lock_branch,omitempty"`
// AllowForkSyncing, if set to true, will allow users to pull changes from upstream
// when the branch is locked.
AllowForkSyncing *bool `json:"allow_fork_syncing,omitempty"`
}

// RequiredStatusChecks represents the protection status of a individual branch.
Expand Down
39 changes: 39 additions & 0 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,15 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
},
"required_conversation_resolution": {
"enabled": true
},
"block_creations": {
"enabled": false
},
"lock_branch": {
"enabled": false
},
"allow_fork_syncing": {
"enabled": false
}
}`)
})
Expand Down Expand Up @@ -1151,6 +1160,15 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
RequiredConversationResolution: &RequiredConversationResolution{
Enabled: true,
},
BlockCreations: &BlockCreations{
Enabled: Bool(false),
},
LockBranch: &LockBranch{
Enabled: Bool(false),
},
AllowForkSyncing: &AllowForkSyncing{
Enabled: Bool(false),
},
}
if !cmp.Equal(protection, want) {
t.Errorf("Repositories.GetBranchProtection returned %+v, want %+v", protection, want)
Expand Down Expand Up @@ -1299,6 +1317,9 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
Teams: []string{"t"},
Apps: []string{"a"},
},
BlockCreations: Bool(true),
LockBranch: Bool(true),
AllowForkSyncing: Bool(true),
}

mux.HandleFunc("/repos/o/r/branches/b/protection", func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -1350,6 +1371,15 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
"users":[{"id":1,"login":"u"}],
"teams":[{"id":2,"slug":"t"}],
"apps":[{"id":3,"slug":"a"}]
},
"block_creations": {
"enabled": true
},
"lock_branch": {
"enabled": true
},
"allow_fork_syncing": {
"enabled": true
}
}`)
})
Expand Down Expand Up @@ -1407,6 +1437,15 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
{Slug: String("a"), ID: Int64(3)},
},
},
BlockCreations: &BlockCreations{
Enabled: Bool(true),
},
LockBranch: &LockBranch{
Enabled: Bool(true),
},
AllowForkSyncing: &AllowForkSyncing{
Enabled: Bool(true),
},
}
if !cmp.Equal(protection, want) {
t.Errorf("Repositories.UpdateBranchProtection returned %+v, want %+v", protection, want)
Expand Down
14 changes: 13 additions & 1 deletion test/integration/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ func TestRepositories_EditBranches(t *testing.T) {
// TODO: Only organization repositories can have users and team restrictions.
// In order to be able to test these Restrictions, need to add support
// for creating temporary organization repositories.
Restrictions: nil,
Restrictions: nil,
BlockCreations: github.Bool(false),
LockBranch: github.Bool(false),
AllowForkSyncing: github.Bool(false),
}

protection, _, err := client.Repositories.UpdateBranchProtection(context.Background(), *repo.Owner.Login, *repo.Name, "master", protectionRequest)
Expand All @@ -134,6 +137,15 @@ func TestRepositories_EditBranches(t *testing.T) {
Enabled: true,
},
Restrictions: nil,
BlockCreations: &github.BlockCreations{
Enabled: github.Bool(false),
},
LockBranch: &github.LockBranch{
Enabled: github.Bool(false),
},
AllowForkSyncing: &github.AllowForkSyncing{
Enabled: github.Bool(false),
},
}
if !cmp.Equal(protection, want) {
t.Errorf("Repositories.UpdateBranchProtection() returned %+v, want %+v", protection, want)
Expand Down