Ejemplo n.º 1
0
        /// <summary>
        /// Gets a single Blob by SHA.
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/git/blobs/#get-a-blob
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="reference">The SHA of the blob</param>
        public IObservable <Blob> Get(string owner, string name, string reference)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(reference, "reference");

            return(_client.Get(owner, name, reference).ToObservable());
        }
Ejemplo n.º 2
0
    public async Task CanGetABlob()
    {
        var newBlob = new NewBlob
        {
            Content  = "Hello World!",
            Encoding = EncodingType.Utf8
        };

        var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newBlob);

        var blob = await _fixture.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha);

        Assert.Equal(result.Sha, blob.Sha);
        Assert.Equal(EncodingType.Base64, blob.Encoding);

        var contents = Encoding.UTF8.GetString(Convert.FromBase64String(blob.Content));

        Assert.Equal("Hello World!", contents);
    }
Ejemplo n.º 3
0
        public static async Task <string> GetFileContentAsync(
            this IBlobsClient blobsClient, string repoOwner, string repoName, string fileSha)
        {
            Blob fileBlob = await blobsClient.Get(repoOwner, repoName, fileSha);

            switch (fileBlob.Encoding.Value)
            {
            case EncodingType.Utf8:
                return(fileBlob.Content);

            case EncodingType.Base64:
                byte[] bytes = Convert.FromBase64String(fileBlob.Content);
                return(Encoding.UTF8.GetString(bytes));

            default:
                throw new NotSupportedException(
                          $"The blob for file SHA '{fileSha}' in repo '{repoOwner}/{repoName}' uses an unsupported encoding: {fileBlob.Encoding}");
            }
        }