Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gheine committed Oct 23, 2023
1 parent b2226d8 commit 5c2fd6c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/kohsuke/github/GHBranchProtection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/org/kohsuke/github/GHBranchProtectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -49,4 +49,4 @@
"uuid": "3cdd44cf-a62c-43f6-abad-de7c8b65bfe3",
"persistent": true,
"insertionIndex": 4
}
}

0 comments on commit 5c2fd6c

Please sign in to comment.