Skip to content

Commit 3f4c98b

Browse files
committed
Fix binding
1 parent b8168c5 commit 3f4c98b

8 files changed

Lines changed: 43 additions & 16 deletions

File tree

github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/dsl/GitHubBranchJobDslExtenstion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public Object onBranch(Runnable closure) throws ANTLRException {
2424
trigger.setPreStatus(context.isSetPreStatus());
2525
trigger.setCancelQueued(context.isCancelQueued());
2626
trigger.setAbortRunning(context.isAbortRunning());
27+
trigger.setRepoProviders(context.repoProviders());
2728

2829
return trigger;
2930
}

github-pullrequest-plugin/src/main/java/com/github/kostyasha/github/integration/branch/dsl/context/GitHubBranchTriggerDslContext.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public void mode(Runnable closure) {
4242
mode = modeContext.mode();
4343
}
4444

45-
4645
public void setPreStatus() {
4746
setPreStatus = true;
4847
}
@@ -66,6 +65,7 @@ public void repoProviders(Runnable closure) {
6665
GitHubRepoProvidersDslContext repoProvidersContext = new GitHubRepoProvidersDslContext();
6766
ContextExtensionPoint.executeInContext(closure, repoProvidersContext);
6867

68+
repoProviders.clear();
6969
repoProviders.addAll(repoProvidersContext.repoProviders());
7070
}
7171

@@ -100,4 +100,8 @@ public List<GitHubBranchEvent> events() {
100100
public List<String> whitelistedBranches() {
101101
return whitelistedBranches;
102102
}
103+
104+
public List<GitHubRepoProvider> repoProviders() {
105+
return repoProviders;
106+
}
103107
}

github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/dsl/GitHubPRJobDslExtension.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public Object onPullRequest(Runnable closure) throws ANTLRException {
3131
trigger.setPreStatus(context.isSetPreStatus());
3232
trigger.setCancelQueued(context.isCancelQueued());
3333
trigger.setAbortRunning(context.isAbortRunning());
34+
trigger.setRepoProviders(context.repoProviders());
35+
3436
return trigger;
3537
}
3638

github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/dsl/context/GitHubPRTriggerDslContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void repoProviders(Runnable closure) {
6161
GitHubRepoProvidersDslContext repoProvidersContext = new GitHubRepoProvidersDslContext();
6262
ContextExtensionPoint.executeInContext(closure, repoProvidersContext);
6363

64+
repoProviders.clear();
6465
repoProviders.addAll(repoProvidersContext.repoProviders());
6566
}
6667

@@ -87,4 +88,8 @@ public boolean isAbortRunning() {
8788
public List<GitHubPREvent> events() {
8889
return events;
8990
}
91+
92+
public List<GitHubRepoProvider> repoProviders() {
93+
return repoProviders;
94+
}
9095
}

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/dsl/DslIntegrationTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jenkinsci.plugins.github.pullrequest.dsl;
22

33
import com.github.kostyasha.github.integration.generic.GitHubRepoProvider;
4+
import com.github.kostyasha.github.integration.generic.repoprovider.GitHubPluginRepoProvider;
45
import hudson.model.Descriptor;
56
import hudson.model.FreeStyleProject;
67
import hudson.model.Result;
@@ -26,6 +27,8 @@
2627
import java.util.Collection;
2728
import java.util.List;
2829

30+
import static com.github.kostyasha.github.integration.generic.repoprovider.GHPermission.PULL;
31+
import static com.github.kostyasha.github.integration.generic.repoprovider.GHPermission.PUSH;
2932
import static org.hamcrest.Matchers.equalTo;
3033
import static org.hamcrest.Matchers.hasItem;
3134
import static org.hamcrest.Matchers.hasSize;
@@ -91,6 +94,13 @@ public void shouldCreateJobWithExtendedDsl() throws Exception {
9194
assertThat("Should contain repoProvider", repoProviders, notNullValue());
9295
assertThat("Should contain 1 repoProvider", repoProviders, hasSize(1));
9396

97+
final GitHubRepoProvider repoProvider = repoProviders.get(0);
98+
assertThat(repoProvider, instanceOf(GitHubPluginRepoProvider.class));
99+
final GitHubPluginRepoProvider provider = (GitHubPluginRepoProvider) repoProvider;
100+
assertThat(provider.isCacheConnection(), is(false));
101+
assertThat(provider.isManageHooks(), is(false));
102+
assertThat(provider.getRepoPermission(), is(PUSH));
103+
94104
final List<GitHubPREvent> events = trigger.getEvents();
95105
assertThat("Should add events", events, hasSize(17));
96106

github-pullrequest-plugin/src/test/java/org/jenkinsci/plugins/github/pullrequest/dsl/GitHubPRJobDslExtensionTest.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import com.github.kostyasha.github.integration.branch.GitHubBranchTrigger;
44
import com.github.kostyasha.github.integration.branch.events.GitHubBranchEvent;
55
import com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchCommitEvent;
6-
import com.github.kostyasha.github.integration.branch.events.impl.commitchecks.impl.GitHubBranchCommitMessageCheck;
76
import com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchRestrictionFilter;
8-
7+
import com.github.kostyasha.github.integration.branch.events.impl.commitchecks.impl.GitHubBranchCommitMessageCheck;
98
import com.github.kostyasha.github.integration.generic.GitHubRepoProvider;
9+
import com.github.kostyasha.github.integration.generic.repoprovider.GitHubPluginRepoProvider;
1010
import hudson.model.FreeStyleProject;
1111
import hudson.triggers.Trigger;
12-
12+
import javaposse.jobdsl.plugin.ExecuteDslScripts;
13+
import javaposse.jobdsl.plugin.LookupStrategy;
14+
import javaposse.jobdsl.plugin.RemovedJobAction;
15+
import javaposse.jobdsl.plugin.RemovedViewAction;
1316
import org.apache.commons.io.IOUtils;
1417
import org.junit.Rule;
1518
import org.junit.Test;
@@ -18,12 +21,7 @@
1821
import java.util.Collection;
1922
import java.util.List;
2023

21-
import javaposse.jobdsl.plugin.ExecuteDslScripts;
22-
import javaposse.jobdsl.plugin.LookupStrategy;
23-
import javaposse.jobdsl.plugin.RemovedJobAction;
24-
import javaposse.jobdsl.plugin.RemovedViewAction;
25-
26-
import static org.hamcrest.Matchers.contains;
24+
import static com.github.kostyasha.github.integration.generic.repoprovider.GHPermission.PULL;
2725
import static org.hamcrest.Matchers.containsInAnyOrder;
2826
import static org.hamcrest.Matchers.equalTo;
2927
import static org.hamcrest.Matchers.hasItem;
@@ -90,6 +88,13 @@ public void shouldCreateJobWithExtendedDsl() throws Exception {
9088
assertThat("Should contain repoProvider", repoProviders, notNullValue());
9189
assertThat("Should contain 1 repoProvider", repoProviders, hasSize(1));
9290

91+
final GitHubRepoProvider repoProvider = repoProviders.get(0);
92+
assertThat(repoProvider, instanceOf(GitHubPluginRepoProvider.class));
93+
final GitHubPluginRepoProvider provider = (GitHubPluginRepoProvider) repoProvider;
94+
assertThat(provider.isCacheConnection(), is(false));
95+
assertThat(provider.isManageHooks(), is(false));
96+
assertThat(provider.getRepoPermission(), is(PULL));
97+
9398
}
9499

95100
private void verifyCommitChecks(GitHubBranchEvent gitHubBranchEvent) {

github-pullrequest-plugin/src/test/resources/dsl/branch-jobdsl.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ freeStyleJob('gh-branch') {
1313

1414
repoProviders {
1515
gitHubPlugin {
16-
manageHooks(true)
17-
cacheConnection(true)
18-
permission { admin() }
16+
manageHooks(false)
17+
cacheConnection(false)
18+
permission { pull() }
1919
}
2020
}
2121

github-pullrequest-plugin/src/test/resources/dsl/jobdsl.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ freeStyleJob('gh-pull-request') {
1313

1414
repoProviders {
1515
gitHubPlugin {
16-
manageHooks(true)
17-
cacheConnection(true)
18-
permission { admin() }
16+
manageHooks(false)
17+
cacheConnection(false)
18+
permission { push() }
1919
}
2020
}
2121

0 commit comments

Comments
 (0)