def _source_key(source):
    """Creates a key to use to sort a list of sources.

    Arguments:
        source {metadata_pb2.Source} -- the Source for which to formulate a sort key

    Returns:
        tuple -- A key to use to sort a list of sources.
    """
    if source.HasField("git"):
        return ("git", source.git.name, source.git.remote, source.git.sha)
    if source.HasField("generator"):
        return (
            "generator",
            source.generator.name,
            source.generator.version,
            source.generator.docker_image,
        )
    if source.HasField("template"):
        return (
            "template",
            source.template.name,
            source.template.origin,
            source.template.version,
        )