Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow base64 content for create/update file #1488

Merged
merged 2 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public async Task CrudTest()
repository.Owner.Login,
repository.Name,
"somefile.txt",
new CreateFileRequest("Test commit", "Some Content"));
new CreateFileRequest("Test commit", "U29tZSBDb250ZW50"));
Assert.Equal("somefile.txt", file.Content.Name);

var contents = await fixture.GetAllContents(repository.Owner.Login, repository.Name, "somefile.txt");
Expand All @@ -319,7 +319,7 @@ public async Task CrudTest()
repository.Owner.Login,
repository.Name,
"somefile.txt",
new UpdateFileRequest("Updating file", "New Content", fileSha));
new UpdateFileRequest("Updating file", "TmV3IENvbnRlbnQ=", fileSha));
Assert.Equal("somefile.txt", update.Content.Name);

contents = await fixture.GetAllContents(repository.Owner.Login, repository.Name, "somefile.txt");
Expand Down Expand Up @@ -351,7 +351,7 @@ public async Task CrudTestWithRepositoryId()
var file = await fixture.CreateFile(
repository.Id,
"somefile.txt",
new CreateFileRequest("Test commit", "Some Content"));
new CreateFileRequest("Test commit", "U29tZSBDb250ZW50"));
Assert.Equal("somefile.txt", file.Content.Name);

var contents = await fixture.GetAllContents(repository.Owner.Login, repository.Name, "somefile.txt");
Expand All @@ -361,7 +361,7 @@ public async Task CrudTestWithRepositoryId()
var update = await fixture.UpdateFile(
repository.Id,
"somefile.txt",
new UpdateFileRequest("Updating file", "New Content", fileSha));
new UpdateFileRequest("Updating file", "TmV3IENvbnRlbnQ=", fileSha));
Assert.Equal("somefile.txt", update.Content.Name);

contents = await fixture.GetAllContents(repository.Owner.Login, repository.Name, "somefile.txt");
Expand Down Expand Up @@ -396,7 +396,7 @@ public async Task CrudTestWithNamedBranch()
repository.Owner.Login,
repository.Name,
"somefile.txt",
new CreateFileRequest("Test commit", "Some Content", branchName));
new CreateFileRequest("Test commit", "U29tZSBDb250ZW50", branchName));
Assert.Equal("somefile.txt", file.Content.Name);

var contents = await fixture.GetAllContentsByRef(repository.Owner.Login, repository.Name, "somefile.txt", branchName);
Expand All @@ -407,7 +407,7 @@ public async Task CrudTestWithNamedBranch()
repository.Owner.Login,
repository.Name,
"somefile.txt",
new UpdateFileRequest("Updating file", "New Content", fileSha, branchName));
new UpdateFileRequest("Updating file", "TmV3IENvbnRlbnQ=", fileSha, branchName));
Assert.Equal("somefile.txt", update.Content.Name);

contents = await fixture.GetAllContentsByRef(repository.Owner.Login, repository.Name, "somefile.txt", branchName);
Expand Down Expand Up @@ -442,7 +442,7 @@ public async Task CrudTestWithNamedBranchWithRepositoryId()
var file = await fixture.CreateFile(
repository.Id,
"somefile.txt",
new CreateFileRequest("Test commit", "Some Content", branchName));
new CreateFileRequest("Test commit", "U29tZSBDb250ZW50", branchName));
Assert.Equal("somefile.txt", file.Content.Name);

var contents = await fixture.GetAllContentsByRef(repository.Owner.Login, repository.Name, "somefile.txt", branchName);
Expand All @@ -452,7 +452,7 @@ public async Task CrudTestWithNamedBranchWithRepositoryId()
var update = await fixture.UpdateFile(
repository.Id,
"somefile.txt",
new UpdateFileRequest("Updating file", "New Content", fileSha, branchName));
new UpdateFileRequest("Updating file", "TmV3IENvbnRlbnQ=", fileSha, branchName));
Assert.Equal("somefile.txt", update.Content.Name);

contents = await fixture.GetAllContentsByRef(repository.Owner.Login, repository.Name, "somefile.txt", branchName);
Expand Down
24 changes: 12 additions & 12 deletions Octokit.Tests/Clients/RepositoryContentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public async Task RequestsCorrectUrl()
var client = new RepositoryContentsClient(connection);

string expectedUri = "repos/org/repo/contents/path/to/file";
await client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
await client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -332,7 +332,7 @@ public async Task RequestsCorrectUrlWithRepositoryId()
var client = new RepositoryContentsClient(connection);

string expectedUri = "repositories/1/contents/path/to/file";
await client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
await client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -343,13 +343,13 @@ public async Task PassesRequestObject()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

await client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
await client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}

Expand All @@ -359,13 +359,13 @@ public async Task PassesRequestObjectWithRepositoryId()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

await client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
await client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}

Expand Down Expand Up @@ -480,7 +480,7 @@ public async Task RequestsCorrectUrl()
var client = new RepositoryContentsClient(connection);

string expectedUri = "repos/org/repo/contents/path/to/file";
await client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
await client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -492,7 +492,7 @@ public async Task RequestsCorrectUrlWithRepositoryId()
var client = new RepositoryContentsClient(connection);

string expectedUri = "repositories/1/contents/path/to/file";
await client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
await client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -503,13 +503,13 @@ public async Task PassesRequestObject()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

await client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
await client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}
Expand All @@ -520,13 +520,13 @@ public async Task PassesRequestObjectWithRepositoriesId()
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

await client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
await client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}
Expand Down
24 changes: 12 additions & 12 deletions Octokit.Tests/Reactive/ObservableRepositoryContentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public void RequestsCorrectUrl()
var client = new ObservableRepositoryContentsClient(gitHubClient);

string expectedUri = "repos/org/repo/contents/path/to/file";
client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -419,7 +419,7 @@ public void RequestsCorrectUrlWithRepositoryId()
var client = new ObservableRepositoryContentsClient(gitHubClient);

string expectedUri = "repositories/1/contents/path/to/file";
client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -431,13 +431,13 @@ public void PassesRequestObject()
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);

client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}

Expand All @@ -448,13 +448,13 @@ public void PassesRequestObjectWithRepositoryId()
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);

client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));
client.CreateFile(1, "path/to/file", new CreateFileRequest("message", "bXlmaWxlY29udGVudHM=", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Branch == "mybranch"));
}

Expand Down Expand Up @@ -575,7 +575,7 @@ public void RequestsCorrectUrl()
var client = new ObservableRepositoryContentsClient(gitHubClient);

string expectedUri = "repos/org/repo/contents/path/to/file";
client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -588,7 +588,7 @@ public void RequestsCorrectUrlWithRepositoryId()
var client = new ObservableRepositoryContentsClient(gitHubClient);

string expectedUri = "repositories/1/contents/path/to/file";
client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}
Expand All @@ -600,13 +600,13 @@ public void PassesRequestObject()
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);

client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}
Expand All @@ -618,13 +618,13 @@ public void PassesRequestObjectWithRepositoriesId()
var gitHubClient = new GitHubClient(connection);
var client = new ObservableRepositoryContentsClient(gitHubClient);

client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));
client.UpdateFile(1, "path/to/file", new UpdateFileRequest("message", "bXlmaWxlY29udGVudHM=", "1234abc", "mybranch"));

gitHubClient.Connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Content == "bXlmaWxlY29udGVudHM="
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}
Expand Down
8 changes: 4 additions & 4 deletions Octokit/Models/Request/CreateFileRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class CreateFileRequest : ContentRequest
/// Creates an instance of a <see cref="CreateFileRequest" />.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="content">The content encoded in base64.</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryangribble @haacked how do we feel about this breaking change? Should we instead introduce overloads?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a very subtle breaking change. Probably best to use an overload.

Someday I'd like to write a Base64Content type. 😄 rather than using strings for everything.

public CreateFileRequest(string message, string content) : base(message)
{
Ensure.ArgumentNotNull(content, "content");
Expand All @@ -118,18 +118,18 @@ public CreateFileRequest(string message, string content) : base(message)
/// Initializes a new instance of the <see cref="CreateFileRequest"/> class.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="content">The content.</param>
/// <param name="content">The content encoded in base64.</param>
/// <param name="branch">The branch the request is for.</param>
public CreateFileRequest(string message, string content, string branch) : base(message, branch)
{
Ensure.ArgumentNotNullOrEmptyString(content, "content");

Content = content;
}

/// <summary>
/// The contents of the file to create. This is required.
/// The contents of the file to create, Base64 encoded. This is required.
/// </summary>
[SerializeAsBase64]
public string Content { get; private set; }

internal virtual string DebuggerDisplay
Expand Down