Skip to content

Commit 5c2fd6c

Browse files
committed
Coverage
1 parent b2226d8 commit 5c2fd6c

File tree

5 files changed

+97
-18
lines changed

5 files changed

+97
-18
lines changed

src/main/java/org/kohsuke/github/GHBranchProtection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ public AllowForcePushes getAllowForcePushes() {
9898
return allowForcePushes;
9999
}
100100

101+
/**
102+
* Gets allow fork syncing.
103+
*
104+
* @return the enforce admins
105+
*/
106+
public AllowForkSyncing getAllowForkSyncing() {
107+
return allowForkSyncing;
108+
}
109+
101110
/**
102111
* Gets block creations.
103112
*

src/test/java/org/kohsuke/github/GHBranchProtectionTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import org.junit.Before;
44
import org.junit.Test;
5+
import org.kohsuke.github.GHBranchProtection.AllowDeletions;
6+
import org.kohsuke.github.GHBranchProtection.AllowForcePushes;
7+
import org.kohsuke.github.GHBranchProtection.AllowForkSyncing;
8+
import org.kohsuke.github.GHBranchProtection.BlockCreations;
59
import org.kohsuke.github.GHBranchProtection.EnforceAdmins;
10+
import org.kohsuke.github.GHBranchProtection.LockBranch;
11+
import org.kohsuke.github.GHBranchProtection.RequiredConversationResolution;
12+
import org.kohsuke.github.GHBranchProtection.RequiredLinearHistory;
613
import org.kohsuke.github.GHBranchProtection.RequiredReviews;
714
import org.kohsuke.github.GHBranchProtection.RequiredStatusChecks;
815

@@ -45,9 +52,17 @@ public void testEnableBranchProtections() throws Exception {
4552
.addRequiredChecks("test-status-check")
4653
.requireBranchIsUpToDate()
4754
.requireCodeOwnReviews()
55+
.requireLastPushApproval()
4856
.dismissStaleReviews()
4957
.requiredReviewers(2)
58+
.allowDeletions()
59+
.allowForcePushes()
60+
.allowForkSyncing()
61+
.blockCreations()
5062
.includeAdmins()
63+
.lockBranch()
64+
.requiredConversationResolution()
65+
.requiredLinearHistory()
5166
.enable();
5267

5368
verifyBranchProtection(protection);
@@ -67,11 +82,40 @@ private void verifyBranchProtection(GHBranchProtection protection) {
6782
assertThat(requiredReviews, notNullValue());
6883
assertThat(requiredReviews.isDismissStaleReviews(), is(true));
6984
assertThat(requiredReviews.isRequireCodeOwnerReviews(), is(true));
85+
assertThat(requiredReviews.isRequireLastPushApproval(), is(true));
7086
assertThat(requiredReviews.getRequiredReviewers(), equalTo(2));
7187

88+
AllowDeletions allowDeletions = protection.getAllowDeletions();
89+
assertThat(allowDeletions, notNullValue());
90+
assertThat(allowDeletions.isEnabled(), is(true));
91+
92+
AllowForcePushes allowForcePushes = protection.getAllowForcePushes();
93+
assertThat(allowForcePushes, notNullValue());
94+
assertThat(allowForcePushes.isEnabled(), is(true));
95+
96+
AllowForkSyncing allowForkSyncing = protection.getAllowForkSyncing();
97+
assertThat(allowForkSyncing, notNullValue());
98+
assertThat(allowForkSyncing.isEnabled(), is(true));
99+
100+
BlockCreations blockCreations = protection.getBlockCreations();
101+
assertThat(blockCreations, notNullValue());
102+
assertThat(blockCreations.isEnabled(), is(true));
103+
72104
EnforceAdmins enforceAdmins = protection.getEnforceAdmins();
73105
assertThat(enforceAdmins, notNullValue());
74106
assertThat(enforceAdmins.isEnabled(), is(true));
107+
108+
LockBranch lockBranch = protection.getLockBranch();
109+
assertThat(lockBranch, notNullValue());
110+
assertThat(lockBranch.isEnabled(), is(true));
111+
112+
RequiredConversationResolution requiredConversationResolution = protection.getRequiredConversationResolution();
113+
assertThat(requiredConversationResolution, notNullValue());
114+
assertThat(requiredConversationResolution.isEnabled(), is(true));
115+
116+
RequiredLinearHistory requiredLinearHistory = protection.getRequiredLinearHistory();
117+
assertThat(requiredLinearHistory, notNullValue());
118+
assertThat(requiredLinearHistory.isEnabled(), is(true));
75119
}
76120

77121
/**

src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,32 @@
1212
"url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/required_pull_request_reviews",
1313
"dismiss_stale_reviews": true,
1414
"require_code_owner_reviews": true,
15-
"required_approving_review_count": 2
15+
"required_approving_review_count": 2,
16+
"require_last_push_approval": true
17+
},
18+
"allow_deletions": {
19+
"enabled": true
20+
},
21+
"allow_force_pushes": {
22+
"enabled": true
23+
},
24+
"allow_fork_syncing": {
25+
"enabled": true
26+
},
27+
"block_creations": {
28+
"enabled": true
1629
},
1730
"enforce_admins": {
1831
"url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/enforce_admins",
1932
"enabled": true
2033
},
21-
"required_linear_history": {
22-
"enabled": false
34+
"lock_branch": {
35+
"enabled": true
2336
},
24-
"allow_force_pushes": {
25-
"enabled": false
37+
"required_conversation_resolution": {
38+
"enabled": true
2639
},
27-
"allow_deletions": {
28-
"enabled": false
40+
"required_linear_history": {
41+
"enabled": true
2942
}
30-
}
43+
}

src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/__files/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-5.json

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,32 @@
1212
"url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/required_pull_request_reviews",
1313
"dismiss_stale_reviews": true,
1414
"require_code_owner_reviews": true,
15-
"required_approving_review_count": 2
15+
"required_approving_review_count": 2,
16+
"require_last_push_approval": true
17+
},
18+
"allow_deletions": {
19+
"enabled": true
20+
},
21+
"allow_force_pushes": {
22+
"enabled": true
23+
},
24+
"allow_fork_syncing": {
25+
"enabled": true
26+
},
27+
"block_creations": {
28+
"enabled": true
1629
},
1730
"enforce_admins": {
1831
"url": "https://api.github.com/repos/hub4j-test-org/temp-testEnableBranchProtections/branches/main/protection/enforce_admins",
1932
"enabled": true
2033
},
21-
"required_linear_history": {
22-
"enabled": false
34+
"lock_branch": {
35+
"enabled": true
2336
},
24-
"allow_force_pushes": {
25-
"enabled": false
37+
"required_conversation_resolution": {
38+
"enabled": true
2639
},
27-
"allow_deletions": {
28-
"enabled": false
40+
"required_linear_history": {
41+
"enabled": true
2942
}
30-
}
43+
}

src/test/resources/org/kohsuke/github/GHBranchProtectionTest/wiremock/testEnableBranchProtections/mappings/repos_hub4j-test-org_temp-testenablebranchprotections_branches_main_protection-4.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"bodyPatterns": [
1313
{
14-
"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}",
14+
"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}",
1515
"ignoreArrayOrder": true,
1616
"ignoreExtraElements": false
1717
}
@@ -49,4 +49,4 @@
4949
"uuid": "3cdd44cf-a62c-43f6-abad-de7c8b65bfe3",
5050
"persistent": true,
5151
"insertionIndex": 4
52-
}
52+
}

0 commit comments

Comments
 (0)