Пример #1
0
def request_changes(stub: DataStub, ptr_from: ReferencePointer, ptr_to: ReferencePointer,
                    contents: bool, uast: bool, unicode: bool) -> Iterator[Change]:
    """
    Invoke GRPC API and get the changes. Used by `with_changed_uasts()` and Review events.

    :return: The stream of the gRPC invocation results. In theory, `.result()` would turn this \
             into a synchronous call, but in practice, that function call hangs for some reason.
    """
    request = ChangesRequest(base=ptr_from.to_pb(), head=ptr_to.to_pb())
    request.exclude_pattern = GARBAGE_PATTERN
    request.exclude_vendored = True
    request.want_contents = contents
    request.want_language = contents or uast
    request.want_uast = uast
    changes = stub.GetChanges(request)
    if unicode:
        changes = map(BytesToUnicodeConverter.convert_change, changes)
    return changes
Пример #2
0
def request_files(stub: DataStub, ptr: ReferencePointer, contents: bool, uast: bool,
                  unicode: bool) -> Iterator[File]:
    """
    Invoke GRPC API and get the files. Used by `with_uasts()` and Push events.

    :return: The stream of the gRPC invocation results.
    """
    request = FilesRequest(revision=ptr.to_pb())
    request.exclude_pattern = GARBAGE_PATTERN
    request.exclude_vendored = True
    request.want_contents = contents
    request.want_language = contents or uast
    request.want_uast = uast
    files = stub.GetFiles(request)
    if unicode:
        files = map(BytesToUnicodeConverter.convert_file, files)
    return files