Skip to content

Provide default value for requestForTestingPhrase#452

Open
hartzell wants to merge 1 commit intojaninko:masterfrom
hartzell:patch-1
Open

Provide default value for requestForTestingPhrase#452
hartzell wants to merge 1 commit intojaninko:masterfrom
hartzell:patch-1

Conversation

@hartzell
Copy link

I configure my Jenkinses via a setup.groovy script and never visit the configuration page.

Builds are never run for people who are not on the white list and the admin is never asked to approve builds for them.

It turns out that the reason is that Jenkins is trying to use the requestForTesting phrase but that it has never been set, leading to a NullPointerException:

Unable to handle comment for PR# 1213, repo: git-workshop/git-workshop.<elided>
java.lang.NullPointerException
	at org.jenkinsci.plugins.ghprb.GhprbRepository.addComment(GhprbRepository.java:238)
	at org.jenkinsci.plugins.ghprb.GhprbRepository.addComment(GhprbRepository.java:234)
	at org.jenkinsci.plugins.ghprb.GhprbPullRequest.<init>(GhprbPullRequest.java:139)
	at org.jenkinsci.plugins.ghprb.GhprbRepository.getPullRequest(GhprbRepository.java:365)
	at org.jenkinsci.plugins.ghprb.GhprbRepository.onIssueCommentHook(GhprbRepository.java:345)
	at org.jenkinsci.plugins.ghprb.GhprbTrigger.handleComment(GhprbTrigger.java:611)
	at org.jenkinsci.plugins.ghprb.GhprbRootAction$1.run(GhprbRootAction.java:233)

I'm currently working around the issue like so:

// Set up the Github Pull Request Builder Plugin
//    https://gist.github.com/kpettijohn/e294c50e29ca4e8a329e
def ghprbDesc = Jenkins.instance.getDescriptorByType(org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl.class)

// [other settings elided]
// Set a value to use when Jenkins asks the admins if it's
// ok to run a build from a "stranger".  This field has no
// default value, so if it's not set here, Jenkins accesses a
// null pointer and becomes sad.
Field testPlease = ghprbDesc.class.getDeclaredField("requestForTestingPhrase")
testPlease.setAccessible(true)
testPlease.set(ghprbDesc, "Can one of the admins verify this patch?")

but it seems like it would be safer to provide it with a default value like you do for the other phrases.

Alternatively, org.jenkinsci.plugins.ghprb.GhprbRepository.addComment {sh,c}ould check that it's argument is not null before using it. But, that wouldn't help the 'infrastructure as code' crowd as much as my proposed change.

It would be really nice if there were a programmatic way to configure the plugin. The configure method is tied to a request, so it's not easily usable and using reflection to access the plugin's private bits seems icky.

I configure my Jenkinses via a setup.groovy script and never visit the configuration page.

Builds are never run for people who are not on the white list and the admin is never asked to approve builds for them.

It turns out that the reason is that Jenkins is trying to use the `requestForTesting` phrase but that it has never been set, leading to a `NullPointerException`:

```
Unable to handle comment for PR# 1213, repo: git-workshop/git-workshop.<elided>
java.lang.NullPointerException
	at org.jenkinsci.plugins.ghprb.GhprbRepository.addComment(GhprbRepository.java:238)
	at org.jenkinsci.plugins.ghprb.GhprbRepository.addComment(GhprbRepository.java:234)
	at org.jenkinsci.plugins.ghprb.GhprbPullRequest.<init>(GhprbPullRequest.java:139)
	at org.jenkinsci.plugins.ghprb.GhprbRepository.getPullRequest(GhprbRepository.java:365)
	at org.jenkinsci.plugins.ghprb.GhprbRepository.onIssueCommentHook(GhprbRepository.java:345)
	at org.jenkinsci.plugins.ghprb.GhprbTrigger.handleComment(GhprbTrigger.java:611)
	at org.jenkinsci.plugins.ghprb.GhprbRootAction$1.run(GhprbRootAction.java:233)
```

I'm currently working around the issue like so:

```groovy
// Set up the Github Pull Request Builder Plugin
//    https://gist.github.com/kpettijohn/e294c50e29ca4e8a329e
def ghprbDesc = Jenkins.instance.getDescriptorByType(org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl.class)

// [other settings elided]
// Set a value to use when Jenkins asks the admins if it's
// ok to run a build from a "stranger".  This field has no
// default value, so if it's not set here, Jenkins accesses a
// null pointer and becomes sad.
Field testPlease = ghprbDesc.class.getDeclaredField("requestForTestingPhrase")
testPlease.setAccessible(true)
testPlease.set(ghprbDesc, "Can one of the admins verify this patch?")
```

but it seems like it would be safer to provide it with a default value like you do for the other phrases.

Alternatively, `org.jenkinsci.plugins.ghprb.GhprbRepository.addComment` {sh,c}ould check that it's argument is not null before using it.  **But**, that wouldn't help the 'infrastructure as code' crowd as much as my proposed change.

It would be really nice if there were a programmatic way to configure the plugin.  The `configure` method is tied to a request, so it's not easily usable and using reflection to access the plugin's private bits seems icky.
@alexkomis
Copy link

Can one of the admins verify this patch?

1 similar comment
@meruvasivakumari
Copy link

Can one of the admins verify this patch?

@hartzell
Copy link
Author

hartzell commented Feb 7, 2017

Is there anything I can do to help move this along?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants