diff --git a/src/main/java/org/kohsuke/github/GHBranchProtection.java b/src/main/java/org/kohsuke/github/GHBranchProtection.java index 49956c5d70..834544944f 100644 --- a/src/main/java/org/kohsuke/github/GHBranchProtection.java +++ b/src/main/java/org/kohsuke/github/GHBranchProtection.java @@ -98,6 +98,15 @@ public AllowForcePushes getAllowForcePushes() { return allowForcePushes; } + /** + * Gets allow fork syncing. + * + * @return the enforce admins + */ + public AllowForkSyncing getAllowForkSyncing() { + return allowForkSyncing; + } + /** * Gets block creations. * diff --git a/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java b/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java index 3624068ee5..5254b3a707 100755 --- a/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java +++ b/src/test/java/org/kohsuke/github/GHBranchProtectionTest.java @@ -2,7 +2,14 @@ import org.junit.Before; import org.junit.Test; +import org.kohsuke.github.GHBranchProtection.AllowDeletions; +import org.kohsuke.github.GHBranchProtection.AllowForcePushes; +import org.kohsuke.github.GHBranchProtection.AllowForkSyncing; +import org.kohsuke.github.GHBranchProtection.BlockCreations; import org.kohsuke.github.GHBranchProtection.EnforceAdmins; +import org.kohsuke.github.GHBranchProtection.LockBranch; +import org.kohsuke.github.GHBranchProtection.RequiredConversationResolution; +import org.kohsuke.github.GHBranchProtection.RequiredLinearHistory; import org.kohsuke.github.GHBranchProtection.RequiredReviews; import org.kohsuke.github.GHBranchProtection.RequiredStatusChecks; @@ -45,9 +52,17 @@ public void testEnableBranchProtections() throws Exception { .addRequiredChecks("test-status-check") .requireBranchIsUpToDate() .requireCodeOwnReviews() + .requireLastPushApproval() .dismissStaleReviews() .requiredReviewers(2) + .allowDeletions() + .allowForcePushes() + .allowForkSyncing() + .blockCreations() .includeAdmins() + .lockBranch() + .requiredConversationResolution() + .requiredLinearHistory() .enable(); verifyBranchProtection(protection); @@ -67,11 +82,40 @@ private void verifyBranchProtection(GHBranchProtection protection) { assertThat(requiredReviews, notNullValue()); assertThat(requiredReviews.isDismissStaleReviews(), is(true)); assertThat(requiredReviews.isRequireCodeOwnerReviews(), is(true)); + assertThat(requiredReviews.isRequireLastPushApproval(), is(true)); assertThat(requiredReviews.getRequiredReviewers(), equalTo(2)); + AllowDeletions allowDeletions = protection.getAllowDeletions(); + assertThat(allowDeletions, notNullValue()); + assertThat(allowDeletions.isEnabled(), is(true)); + + AllowForcePushes allowForcePushes = protection.getAllowForcePushes(); + assertThat(allowForcePushes, notNullValue()); + assertThat(allowForcePushes.isEnabled(), is(true)); + + AllowForkSyncing allowForkSyncing = protection.getAllowForkSyncing(); + assertThat(allowForkSyncing, notNullValue()); + assertThat(allowForkSyncing.isEnabled(), is(true)); + + BlockCreations blockCreations = protection.getBlockCreations(); + assertThat(blockCreations, notNullValue()); + assertThat(blockCreations.isEnabled(), is(true)); + EnforceAdmins enforceAdmins = protection.getEnforceAdmins(); assertThat(enforceAdmins, notNullValue()); assertThat(enforceAdmins.isEnabled(), is(true)); + + LockBranch lockBranch = protection.getLockBranch(); + assertThat(lockBranch, notNullValue()); + assertThat(lockBranch.isEnabled(), is(true)); + + RequiredConversationResolution requiredConversationResolution = protection.getRequiredConversationResolution(); + assertThat(requiredConversationResolution, notNullValue()); + assertThat(requiredConversationResolution.isEnabled(), is(true)); + + RequiredLinearHistory requiredLinearHistory = protection.getRequiredLinearHistory(); + assertThat(requiredLinearHistory, notNullValue()); + assertThat(requiredLinearHistory.isEnabled(), is(true)); } /** diff --git a/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json b/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json index ee226bab75..a793b4cefa 100644 --- a/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json +++ b/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json @@ -12,19 +12,32 @@ "url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/required_pull_request_reviews", "dismiss_stale_reviews": true, "require_code_owner_reviews": true, - "required_approving_review_count": 2 + "required_approving_review_count": 2, + "require_last_push_approval": true + }, + "allow_deletions": { + "enabled": true + }, + "allow_force_pushes": { + "enabled": true + }, + "allow_fork_syncing": { + "enabled": true + }, + "block_creations": { + "enabled": true }, "enforce_admins": { "url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/enforce_admins", "enabled": true }, - "required_linear_history": { - "enabled": false + "lock_branch": { + "enabled": true }, - "allow_force_pushes": { - "enabled": false + "required_conversation_resolution": { + "enabled": true }, - "allow_deletions": { - "enabled": false + "required_linear_history": { + "enabled": true } -} \ No newline at end of file +} diff --git a/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-5.json b/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-5.json index ee226bab75..a793b4cefa 100644 --- a/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-5.json +++ b/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-5.json @@ -12,19 +12,32 @@ "url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/required_pull_request_reviews", "dismiss_stale_reviews": true, "require_code_owner_reviews": true, - "required_approving_review_count": 2 + "required_approving_review_count": 2, + "require_last_push_approval": true + }, + "allow_deletions": { + "enabled": true + }, + "allow_force_pushes": { + "enabled": true + }, + "allow_fork_syncing": { + "enabled": true + }, + "block_creations": { + "enabled": true }, "enforce_admins": { "url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/enforce_admins", "enabled": true }, - "required_linear_history": { - "enabled": false + "lock_branch": { + "enabled": true }, - "allow_force_pushes": { - "enabled": false + "required_conversation_resolution": { + "enabled": true }, - "allow_deletions": { - "enabled": false + "required_linear_history": { + "enabled": true } -} \ No newline at end of file +} diff --git a/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/mappings/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json b/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/mappings/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json index 31a205713a..3dfbbcf036 100644 --- a/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/mappings/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json +++ b/src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/mappings/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json @@ -11,7 +11,7 @@ }, "bodyPatterns": [ { - "equalToJson": "{\"required_pull_request_reviews\":{\"required_approving_review_count\":2,\"require_code_owner_reviews\":true,\"dismiss_stale_reviews\":true},\"required_status_checks\":{\"contexts\":[\"test-status-check\"],\"strict\":true},\"restrictions\":null,\"enforce_admins\":true}", + "equalToJson": "{\"required_pull_request_reviews\":{\"required_approving_review_count\":2,\"require_code_owner_reviews\":true,\"dismiss_stale_reviews\":true,\"require_last_push_approval\":true},\"required_status_checks\":{\"contexts\":[\"test-status-check\"],\"strict\":true},\"restrictions\":null,\"allow_deletions\":true,\"allow_force_pushes\":true,\"allow_fork_syncing\":true,\"block_creations\":true,\"enforce_admins\":true,\"lock_branch\":true,\"required_conversation_resolution\":true,\"required_linear_history\":true}", "ignoreArrayOrder": true, "ignoreExtraElements": false } @@ -49,4 +49,4 @@ "uuid": "3cdd44cf-a62c-43f6-abad-de7c8b65bfe3", "persistent": true, "insertionIndex": 4 -} \ No newline at end of file +}