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

Reduce usage of deprecated BitbucketRepositoryType. #526

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

falkena
Copy link
Contributor

@falkena falkena commented Nov 24, 2021

This PR is a follow up from #518 and #520

Signed-off-by: Alexander Falkenstern [email protected]

Your checklist for this pull request

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or in Jenkins JIRA
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Did you provide a test-case? That demonstrates feature works or fixes the issue.

@falkena
Copy link
Contributor Author

falkena commented Nov 24, 2021

@KalleOlaviNiemitalo would you take a look please? I think, i removed this time usage properly. See #518 (comment) and #518 (comment)

*/
// The repository type should be immutable for any SCMSource.
@CheckForNull
private final BitbucketRepositoryType repositoryType;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine then. If a user installs a new version of the plugin and the results are serialised without repositoryType, and the user then downgrades the plugin, the field will be left null but that should be OK because it has @CheckForNull.

*/
// The repository type should be immutable for any SCMSource.
@CheckForNull
private final BitbucketRepositoryType repositoryType;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@falkena falkena force-pushed the feature/RemoveDeprecations branch 2 times, most recently from cf4e0bd to d0cce57 Compare November 24, 2021 21:01
Comment on lines 501 to 543
@Override
public void afterSave() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This override might not be necessary at all. It used to ensure that both repositoryType and cloneLinks were set. However, you deleted repositoryType, and cloneLinks is only used in build(SCMHead head, SCMRevision revision), which itself gets the clone links from Bitbucket if not already set. Before your changes, the override might have been necessary because some methods that read repositoryType did not expect null there.

I'm not sure whether deleting the override entirely breaks binary compatibility in Java. If it does, then keep the override and just call super from there.

Or is this necessary for scenarios where a previously initialised cloneLinks list is now out of date — because the SSH port number of the Bitbucket server has been changed, or because build(SCMHead head, SCMRevision revision) was not able to query the links and made incorrect assumptions? Perhaps the Jenkins administrator used to be able to recover from that situation by saving the project configuration again in Jenkins. That seems unlikely to have worked, though, because repositoryType would usually have been non-null and prevented afterSave from making the request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far i understood, this method will be called after job saving. Previous code fetched links, if new job was created, The logic behind was: There is new job available, repository type was changed --> fetch links, if possible. If already existing job was modified, then no action was performed. Now it's the same logic, excepting the guard is cloneLinks and not repositoryType. The question now is: Shall the links be fetched again, if job was changed. From my point of view, yes. I would implement it as:

try {
    BitbucketRepository r = buildBitbucketClient().getRepository();
    Map<String, List<BitbucketHref>> links = r.getLinks();
    if (links != null && links.containsKey("clone")) {
        cloneLinks = links.get("clone");
    }
} catch (InterruptedException | IOException e) {
    LOGGER.log(Level.SEVERE,
    "Could not determine clone links of " + getRepoOwner() + "/" + getRepository() +
    " on " + getServerUrl() + " for " + getOwner() + " falling back to generated links", e);
}

i.e. without if. FDYT?

Comment on lines +533 to +574
if(cloneLinks == null) {
BitbucketRepository r = buildBitbucketClient().getRepository();
Map<String, List<BitbucketHref>> links = r.getLinks();
if (links != null && links.containsKey("clone")) {
cloneLinks = links.get("clone");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, I don't think this is necessary. In previous versions, if the plugin made an HTTP request to get the repository type and got the clone links for free in the same response, it made sense to save them and not have to make a separate request later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this will lead in changed logic. If some error during link fetching is occured, then exception will be thrown and the code below will not be executed. Sadly, i've no idea, if this was implemented on purpose or not. I've no strong preference about leave or remove.

*/
// The repository type should be immutable for any SCMSource.
@CheckForNull
private final BitbucketRepositoryType repositoryType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine then. If a user installs a new version of the plugin and the results are serialised without repositoryType, and the user then downgrades the plugin, the field will be left null but that should be OK because it has @CheckForNull.

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.

None yet

2 participants