Beispiel #1
0
def _append_git_logs(old_metadata, new_metadata):
    """Adds git logs to git sources in new_metadata.

    Parameters:
        old_metadata: instance of metadata_pb2.Metadata
        old_metadata: instance of metadata_pb2.Metadata
    """
    old_map = _get_git_source_map(old_metadata)
    new_map = _get_git_source_map(new_metadata)
    git = shutil.which("git")
    for name, git_source in new_map.items():
        # Get the git history since the last run:
        old_source = old_map.get(name, metadata_pb2.GitSource())
        if not old_source.sha or not git_source.local_path:
            continue
        output = subprocess.run(
            [
                git,
                "-C",
                git_source.local_path,
                "log",
                "--pretty=%H%n%B",
                "--no-decorate",
                f"{old_source.sha}..HEAD",
            ],
            stdout=subprocess.PIPE,
            universal_newlines=True,
        ).stdout
        git_source.log = output
Beispiel #2
0
def test_to_json():
    metadata = metadata_pb2.Metadata()
    metadata.sources.add(git=metadata_pb2.GitSource(
        name="test name", remote="test remote", sha="test sha"))

    jsonified = google.protobuf.json_format.MessageToJson(metadata)

    assert (jsonified == """\
{
  "sources": [
    {
      "git": {
        "name": "test name",
        "remote": "test remote",
        "sha": "test sha"
      }
    }
  ]
}""")

    print(jsonified)
Beispiel #3
0
def add_git_source(**kwargs) -> None:
    """Adds a git source to the current metadata."""
    _metadata.sources.add(git=metadata_pb2.GitSource(**kwargs))
Beispiel #4
0
def test_basic_operation():
    metadata = metadata_pb2.Metadata()
    metadata.sources.add(git=metadata_pb2.GitSource(
        name="test name", remote="test remote", sha="test sha"))

    assert metadata.sources[0].git.name == "test name"