'For each valid /downloadable change set (up to the received changeset_revision) in the repository\'s
change log, append the changeset tool_versions dictionary to the list that will be returned.'

@web.expose
def get_tool_versions(self, trans, **kwd):

    name = kwd['name']
    owner = kwd['owner']
    changeset_revision = kwd['changeset_revision']
    repository = repository_util.get_repository_by_name_and_owner(trans.app, name, owner)
    repo = hg_util.get_repo_for_repository(trans.app, repository=repository, repo_path=None, create=False)
    tool_version_dicts = []
    for changeset in repo.changelog:
        current_changeset_revision = str(repo.changectx(changeset))
        repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision(trans.app, trans.security.encode_id(repository.id), current_changeset_revision)
        if (repository_metadata and repository_metadata.tool_versions):
            tool_version_dicts.append(repository_metadata.tool_versions)
            if (current_changeset_revision == changeset_revision):
                break
    if tool_version_dicts:
        return json.dumps(tool_version_dicts)
    return ''
