Check if a connection is unique #1776
Merged
+32
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ensure a connection is unique before adding it to the connection list.
To prevent data inconsistency caused by partially successful updates, the new list and map are only assigned after validation.
Additionally, GitLabConnectionConfig now overrides configure(StaplerRequest2, JSONObject) to avoid UI failures with no clear error messages on it. The validation exception will be caught and rethrown as FormException.
An error message for duplicate connection names already exists, so no additional message handling is required.
Hopefully, this can fix #1670. However,
addConnection()still doesn't work as https://javadoc.jenkins.io/plugin/gitlab-branch-source/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers.html#addServer(io.jenkins.plugins.gitlabserverconfig.servers.GitLabServer) as described in the issue because instead of throwing an exception about it,addServer()there returns a boolean value to represent if the list is changed or not. Not sure if this is actually also wanted foraddConnection()because there is no other place in the code that will examine the returned boolean value.Testing done
Submitter checklist