Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-60738] Fix global configuration submission from UI #347

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Dohbedoh
Copy link
Contributor

@Dohbedoh Dohbedoh commented May 2, 2023

Fixes JENKINS-60738 caused by changes introduced in #221.

Databinding of hookUrl is not working properly, per my understanding because the DataboundSetter setHookUrl(String hookUrl) accepts a String but the field is a URL. While adding a public void setHookUrl(URL hookUrl) might solve some of the problem, then there is yet another issue that disabling the Specify another hook URL for GitHub configuration checkbox does not remove the hook URL at all... that seems wrong.

So the propose fix:

  • handle the binding and the optional property state in the configure(StaplerRequest req, JSONObject json)
  • reactivate and adjusted the global configuration UI tests
  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

Copy link

@julieheard julieheard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, manually tested and is working 🙂

@jglick
Copy link
Member

jglick commented May 3, 2023

While this sounds fine as a hotfix, the proper fix would be to delete all the overrides and special cases handling and fix the form to use normal databinding by convention.

Comment on lines 27 to 37
f.entry(title: _("Override Hook URL")) {
g.blockWrapper {
f.optionalBlock(title: _("Specify another hook URL for GitHub configuration"),
name: "isOverrideHookUrl",
inline: true,
checked: instance.isOverrideHookUrl()) {
f.entry(field: "hookUrl") {
f.textbox(checkMethod: "post")
f.textbox(checkMethod: "post", name: "hookUrl")
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example all of this should just be like

<f:entry field="hookUrl">
  <f:textbox label="Alternate hook URL for GitHub configuration"/>
</f:entry>

which may be blank.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Remove all the optional block that is not necessary.. Yeah sounds good to me I can test this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be more work for sure. The usual problem with this sort of fix is retaining compatibility for both XML settings and JCasC. Sometimes hacking up the JSON processing in the GUI logic is the only option since refactoring to a simpler structure would break something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the thing that bother me is the type URL of the hookUrl... Because of that type, the value cannot actually be blank :( :

java.net.MalformedURLException: no protocol: 
	at java.base/java.net.URL.<init>(URL.java:645)
	at java.base/java.net.URL.<init>(URL.java:541)
	at java.base/java.net.URL.<init>(URL.java:488)
	at org.kohsuke.stapler.Stapler$3.convert(Stapler.java:1141)
Caused: org.apache.commons.beanutils.ConversionException: no protocol: 

So it is not that simple to "reset" the hook URL because of the binding.. I thought about changing the type from URL to String but the existing public getter might be a problem: https://github.com/jenkinsci/github-plugin/blob/master/src/main/java/org/jenkinsci/plugins/github/config/GitHubPluginConfig.java#L131-L141

Changing its signature could be a breaking change. Though it does not seem to be used outside the scope of that plugin repo: https://github.com/search?ref=simplesearch&type=code&q=user%3Ajenkinsci++getHookUrl.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW use permalinks for better display:

/**
* @return hook url used as endpoint to search and write auto-managed hooks in GH
* @throws GHPluginConfigException if default jenkins url is malformed
*/
public URL getHookUrl() throws GHPluginConfigException {
if (hookUrl != null) {
return hookUrl;
} else {
return constructDefaultUrl();
}
}

setHookUrl(null);
}
req.bindJSON(this, json);
clearRedundantCaches(configs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than this method call, the whole configure method should not even need to be overridden.

Copy link
Contributor Author

@Dohbedoh Dohbedoh Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way I found to simplify the data-binding and just do a req.bindJson is to change the signature of public URL getHookUrl() to public String getHookUrl(). That could be a breaking change. Example at 77cfb02.

So not sure if that would be acceptable ? cc @KostyaSha

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better ask @jglick i forgot databinding nuances

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be a breaking change. … So not sure if that would be acceptable ?

https://github.com/search?q=org%3Ajenkinsci%20getHookUrl&type=code does not look like it is used from other plugins.

@jtnord
Copy link
Member

jtnord commented Jun 13, 2023

@KostyaSha are you ok with this as the active maintainer of this plugin?

@jrtc27
Copy link

jrtc27 commented Mar 5, 2024

What's the status of this? I've just run into this with our own instance.

@yahooguntu
Copy link

I have the same issue; as a workaround I've been adding <hookUrl> directly to github-plugin-configuration.xml, but unfortunately it's cleared out when I save/apply System settings in the web UI.

@jrtc27
Copy link

jrtc27 commented Mar 6, 2024

I have the same issue; as a workaround I've been adding <hookUrl> directly to github-plugin-configuration.xml, but unfortunately it's cleared out when I save/apply System settings in the web UI.

If you edit the config file and restart so it has the updated value in memory then the UI should show the correct setting and not clobber it on save.

@franknarf8
Copy link

Can this be merged soon? I've just noticed this open PR after implementing the same fix and opening another PR : #375

Feel free to close the other PR

@KostyaSha @jglick

@jglick
Copy link
Member

jglick commented Apr 30, 2024

(I am not a maintainer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants