def _plugin_url(name, version):
    """
    Given a name and an optional version, return the jenkins plugin url.
    If there is no version, grab the latest version of the plugin.

    >>> _plugin_url("git", None)
    'https://updates.jenkins-ci.org/latest/git.hpi'
    >>> _plugin_url("git", "2.3.5")
    'https://updates.jenkins-ci.org/download/plugins/git/2.3.5/git.hpi'
    """
    uri = "latest" if version is None else "download/plugins"
    path = name if version is None else "{}/{}/{}".format(name, version, name)
    plugin = "/{}.hpi".format(path)
    return "https://updates.jenkins-ci.org/{}{}".format(uri, plugin)