From 8b5a7fceaf79d9d9dba07e2f28a6ec8d42234b0a Mon Sep 17 00:00:00 2001 From: Chris Simpson Date: Wed, 20 Jul 2022 23:17:10 +0100 Subject: [PATCH] feat: Fixing master > main in integration tests (#2489) --- .../Clients/IObservableReferencesClient.cs | 12 +- .../IObservableRepositoryContentsClient.cs | 8 +- .../Clients/ObservableReferencesClient.cs | 20 +- .../ObservableRepositoryContentsClient.cs | 8 +- .../Clients/CheckRunsClientTests.cs | 24 +- .../Clients/CheckSuitesClientTests.cs | 16 +- .../Clients/MigrationsClientTests.cs | 6 +- ...nizationOutsideCollaboratorsClientTests.cs | 20 +- .../Clients/RepositoriesClientTests.cs | 10 +- .../Clients/RepositoryBranchesClientTests.cs | 2902 ++++++++--------- .../Clients/TeamsClientTests.cs | 6 +- Octokit.Tests.Integration/Helper.cs | 5 + .../Helpers/GithubClientExtensions.cs | 33 +- .../OrganizationRepositoryWithTeamContext.cs | 48 +- .../Helpers/OrganizationTestAttribute.cs | 2 +- .../Helpers/ReferenceExtensionsTests.cs | 2 +- .../Helpers/RepositoryContext.cs | 2 + ...nizationOutsideCollaboratorsClientTests.cs | 18 +- ...ObservableRepositoryBranchesClientTests.cs | 627 ++-- .../Reactive/ObservableTeamsClientTests.cs | 2 +- Octokit.Tests.Integration/SelfTests.cs | 10 + Octokit.Tests/Clients/EventsClientTests.cs | 10 +- .../Clients/RepositoryContentsClientTests.cs | 16 +- Octokit.Tests/Fixtures/release.json | 2 +- Octokit.Tests/Fixtures/releases.json | 18 +- Octokit.Tests/Fixtures/repositories.json | Bin 66996 -> 66992 bytes Octokit.Tests/Fixtures/repository.json | Bin 2610 -> 2606 bytes Octokit.Tests/GitHubConstants.cs | 7 + Octokit.Tests/Models/CheckRunEventTests.cs | 4 +- Octokit.Tests/Models/CheckSuiteEventTests.cs | 2 +- Octokit.Tests/Models/MigrationTests.cs | 2 +- .../Models/SearchRepositoryResultTests.cs | 4 +- ...ObservableRepositoryContentsClientTests.cs | 16 +- Octokit/Clients/IReferencesClient.cs | 44 +- Octokit/Clients/IRepositoryContentsClient.cs | 8 +- Octokit/Clients/ReferencesClient.cs | 32 +- Octokit/Clients/RepositoryContentsClient.cs | 8 +- Octokit/Helpers/ApiUrls.cs | 4 +- Octokit/Helpers/ReferenceExtensions.cs | 26 +- Octokit/Models/Request/CreateFileRequest.cs | 2 +- Octokit/Models/Request/NewReference.cs | 4 +- Octokit/Models/Request/NewRelease.cs | 2 +- Octokit/Models/Request/ReleaseUpdate.cs | 2 +- 43 files changed, 1955 insertions(+), 2039 deletions(-) create mode 100644 Octokit.Tests/GitHubConstants.cs diff --git a/Octokit.Reactive/Clients/IObservableReferencesClient.cs b/Octokit.Reactive/Clients/IObservableReferencesClient.cs index 323e1caa..7747528f 100644 --- a/Octokit.Reactive/Clients/IObservableReferencesClient.cs +++ b/Octokit.Reactive/Clients/IObservableReferencesClient.cs @@ -20,7 +20,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] @@ -33,7 +33,7 @@ namespace Octokit.Reactive /// http://developer.github.com/v3/git/refs/#get-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] @@ -162,7 +162,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// The updated reference data /// IObservable Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate); @@ -174,7 +174,7 @@ namespace Octokit.Reactive /// http://developer.github.com/v3/git/refs/#update-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// The updated reference data /// IObservable Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate); @@ -187,7 +187,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// IObservable Delete(string owner, string name, string reference); @@ -198,7 +198,7 @@ namespace Octokit.Reactive /// http://developer.github.com/v3/git/refs/#delete-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// IObservable Delete(long repositoryId, string reference); } diff --git a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs index b55afc63..9e577976 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs @@ -163,7 +163,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) /// The content path IObservable GetAllContentsByRef(string owner, string name, string reference, string path); @@ -187,7 +187,7 @@ namespace Octokit.Reactive /// See the API documentation for more information. /// /// The Id of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) /// The content path IObservable GetAllContentsByRef(long repositoryId, string reference, string path); @@ -196,14 +196,14 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) IObservable GetAllContentsByRef(string owner, string name, string reference); /// /// Returns the contents of the home directory in a repository. /// /// The Id of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) IObservable GetAllContentsByRef(long repositoryId, string reference); /// diff --git a/Octokit.Reactive/Clients/ObservableReferencesClient.cs b/Octokit.Reactive/Clients/ObservableReferencesClient.cs index 21fcba50..e666d5b6 100644 --- a/Octokit.Reactive/Clients/ObservableReferencesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReferencesClient.cs @@ -32,7 +32,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// public IObservable Get(string owner, string name, string reference) { @@ -50,7 +50,7 @@ namespace Octokit.Reactive /// http://developer.github.com/v3/git/refs/#get-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// public IObservable Get(long repositoryId, string reference) { @@ -148,9 +148,9 @@ namespace Octokit.Reactive /// Options for changing the API response /// /// The subNamespace parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// public IObservable GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options) { @@ -192,9 +192,9 @@ namespace Octokit.Reactive /// Options for changing the API response /// /// The subNamespace parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// public IObservable GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options) { @@ -252,7 +252,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// The updated reference data /// public IObservable Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) @@ -272,7 +272,7 @@ namespace Octokit.Reactive /// http://developer.github.com/v3/git/refs/#update-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// The updated reference data /// public IObservable Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate) @@ -291,7 +291,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// public IObservable Delete(string owner, string name, string reference) { @@ -309,7 +309,7 @@ namespace Octokit.Reactive /// http://developer.github.com/v3/git/refs/#delete-a-reference /// /// The Id of the repository - /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/master" or "tags/release-1" + /// The canonical name of the reference without the 'refs/' prefix. e.g. "heads/main" or "tags/release-1" /// public IObservable Delete(long repositoryId, string reference) { diff --git a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs index a044e090..777b380f 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs @@ -281,7 +281,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) /// The content path public IObservable GetAllContentsByRef(string owner, string name, string reference, string path) { @@ -325,7 +325,7 @@ namespace Octokit.Reactive /// See the API documentation for more information. /// /// The Id of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) /// The content path public IObservable GetAllContentsByRef(long repositoryId, string reference, string path) { @@ -340,7 +340,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) public IObservable GetAllContentsByRef(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); @@ -354,7 +354,7 @@ namespace Octokit.Reactive /// Returns the contents of the home directory in a repository. /// /// The Id of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main ) public IObservable GetAllContentsByRef(long repositoryId, string reference) { Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 07ba5f93..cd101699 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -27,7 +27,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -49,7 +49,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -85,7 +85,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -117,7 +117,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -163,7 +163,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -198,7 +198,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -247,7 +247,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -283,7 +283,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -332,7 +332,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "main"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -359,7 +359,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "main"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -400,7 +400,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch @@ -433,7 +433,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check run for the feature branch diff --git a/Octokit.Tests.Integration/Clients/CheckSuitesClientTests.cs b/Octokit.Tests.Integration/Clients/CheckSuitesClientTests.cs index 52a97b03..03be9d99 100644 --- a/Octokit.Tests.Integration/Clients/CheckSuitesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckSuitesClientTests.cs @@ -26,7 +26,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Need to get a CheckSuiteId so we can test the Get method - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha)).CheckSuites.First(); // Get Check Suite by Id @@ -44,7 +44,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Need to get a CheckSuiteId so we can test the Get method - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha)).CheckSuites.First(); // Get Check Suite by Id @@ -75,7 +75,7 @@ namespace Octokit.Tests.Integration.Clients { using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); var checkSuites = await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha); @@ -92,7 +92,7 @@ namespace Octokit.Tests.Integration.Clients { using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var checkSuites = await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha); @@ -176,7 +176,7 @@ namespace Octokit.Tests.Integration.Clients await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryOwner, repoContext.RepositoryName, preference); // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check suite for the feature branch @@ -199,7 +199,7 @@ namespace Octokit.Tests.Integration.Clients await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryId, preference); // Create a new feature branch - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature"); // Create a check suite for the feature branch @@ -232,7 +232,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Need to get a CheckSuiteId so we can test the Get method - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha)).CheckSuites.First(); // Get Check Suite by Id @@ -248,7 +248,7 @@ namespace Octokit.Tests.Integration.Clients using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { // Need to get a CheckSuiteId so we can test the Get method - var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master"); + var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryId, headCommit.Sha)).CheckSuites.First(); // Get Check Suite by Id diff --git a/Octokit.Tests.Integration/Clients/MigrationsClientTests.cs b/Octokit.Tests.Integration/Clients/MigrationsClientTests.cs index 4d1e93b0..8b868d2c 100644 --- a/Octokit.Tests.Integration/Clients/MigrationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/MigrationsClientTests.cs @@ -28,17 +28,17 @@ public class MigrationsClientTests : IDisposable private async Task CreateTheWorld() { - _repos.Add(await _gitHub.CreateRepositoryContext(_orgName, new NewRepository(Helper.MakeNameWithTimestamp("migrationtest-repo1")) + _repos.Add(await _gitHub.CreateOrganizationRepositoryContext(_orgName, new NewRepository(Helper.MakeNameWithTimestamp("migrationtest-repo1")) { GitignoreTemplate = "VisualStudio", LicenseTemplate = "mit" })); - _repos.Add(await _gitHub.CreateRepositoryContext(_orgName, new NewRepository(Helper.MakeNameWithTimestamp("migrationtest-repo2")) + _repos.Add(await _gitHub.CreateOrganizationRepositoryContext(_orgName, new NewRepository(Helper.MakeNameWithTimestamp("migrationtest-repo2")) { GitignoreTemplate = "VisualStudio", LicenseTemplate = "mit" })); - _repos.Add(await _gitHub.CreateRepositoryContext(_orgName, new NewRepository(Helper.MakeNameWithTimestamp("migrationtest-repo3")) + _repos.Add(await _gitHub.CreateOrganizationRepositoryContext(_orgName, new NewRepository(Helper.MakeNameWithTimestamp("migrationtest-repo3")) { GitignoreTemplate = "VisualStudio", LicenseTemplate = "mit" diff --git a/Octokit.Tests.Integration/Clients/OrganizationOutsideCollaboratorsClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationOutsideCollaboratorsClientTests.cs index 57ffce1e..ab4c548a 100644 --- a/Octokit.Tests.Integration/Clients/OrganizationOutsideCollaboratorsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/OrganizationOutsideCollaboratorsClientTests.cs @@ -20,7 +20,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsNoOutsideCollaborators() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { var outsideCollaborators = await _gitHub.Organization .OutsideCollaborator @@ -35,7 +35,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsOutsideCollaborators() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); @@ -52,7 +52,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithoutStart() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); @@ -75,7 +75,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithStart() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -100,7 +100,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilter() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -118,7 +118,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterAndApiOptions() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -142,7 +142,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterWithStart() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -179,7 +179,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilter() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -198,7 +198,7 @@ namespace Octokit.Tests.Integration.Clients public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilterAndApiOptions() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -234,7 +234,7 @@ namespace Octokit.Tests.Integration.Clients public async Task CanRemoveOutsideCollaborator() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index 161c21a0..18b75783 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -456,7 +456,7 @@ public class RepositoriesClientTests var repoName = Helper.MakeNameWithTimestamp("public-org-repo"); - using (var context = await github.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await github.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { var createdRepository = context.Repository; @@ -484,7 +484,7 @@ public class RepositoriesClientTests var repository = new NewRepository(repoName); - using (var context = await github.CreateRepositoryContext(Helper.Organization, repository)) + using (var context = await github.CreateOrganizationRepositoryContext(Helper.Organization, repository)) { var createdRepository = context.Repository; @@ -1604,7 +1604,7 @@ public class RepositoriesClientTests { _theRepoOwner = Helper.Organization; _theRepository = Helper.MakeNameWithTimestamp("topics"); - _context = _github.CreateRepositoryContext(_theRepoOwner, new NewRepository(_theRepository)).Result; + _context = _github.CreateOrganizationRepositoryContext(_theRepoOwner, new NewRepository(_theRepository)).Result; var defaultTopicAssignmentResult = _github.Repository.ReplaceAllTopics(_context.RepositoryId, _defaultTopics).Result; } @@ -2035,7 +2035,7 @@ public class RepositoriesClientTests var github = Helper.GetAuthenticatedClient(); var newRepo = new NewRepository(Helper.MakeNameWithTimestamp("transferred-repo")); var newOwner = Helper.UserName; - using (var context = await github.CreateRepositoryContext(Helper.Organization, newRepo)) + using (var context = await github.CreateOrganizationRepositoryContext(Helper.Organization, newRepo)) { var transfer = new RepositoryTransfer(newOwner); await github.Repository.Transfer(context.RepositoryOwner, context.RepositoryName, transfer); @@ -2051,7 +2051,7 @@ public class RepositoriesClientTests var github = Helper.GetAuthenticatedClient(); var newRepo = new NewRepository(Helper.MakeNameWithTimestamp("transferred-repo")); var newOwner = Helper.UserName; - using (var context = await github.CreateRepositoryContext(Helper.Organization, newRepo)) + using (var context = await github.CreateOrganizationRepositoryContext(Helper.Organization, newRepo)) { var transfer = new RepositoryTransfer(newOwner); await github.Repository.Transfer(context.RepositoryId, transfer); diff --git a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs index 6e2b747b..9632171b 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs @@ -1,1689 +1,1507 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; -using Octokit; -using Octokit.Tests.Integration; +using Octokit.Helpers; using Octokit.Tests.Integration.Helpers; using Xunit; -public class RepositoryBranchesClientTests +namespace Octokit.Tests.Integration.Clients { - public class TheGetAllMethod + public class RepositoryBranchesClientTests { - [IntegrationTest] - public async Task GetsAllBranches() + public class TheGetAllMethod : GitHubClientTestBase { - var github = Helper.GetAuthenticatedClient(); - - var branches = await github.Repository.Branch.GetAll("octokit", "octokit.net"); - - Assert.NotEmpty(branches); - } - - [IntegrationTest] - public async Task GetsAllBranchesWithRepositoryId() - { - var github = Helper.GetAuthenticatedClient(); - - var branches = await github.Repository.Branch.GetAll(7528679); - - Assert.NotEmpty(branches); - } - - [IntegrationTest] - public async Task ReturnsCorrectCountOfBranchesWithoutStart() - { - var github = Helper.GetAuthenticatedClient(); - - var options = new ApiOptions + [IntegrationTest] + public async Task GetsAllBranches() { - PageSize = 5, - PageCount = 1 - }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); - var branches = await github.Repository.Branch.GetAll("octokit", "octokit.net", options); + var branches = await _github.Repository.Branch.GetAll(repoContext.RepositoryOwner, repoContext.RepositoryName); - Assert.Equal(5, branches.Count); - } + Assert.NotEmpty(branches); + } + } - [IntegrationTest] - public async Task ReturnsCorrectCountOfBranchesWithoutStartWithRepositoryId() - { - var github = Helper.GetAuthenticatedClient(); - - var options = new ApiOptions + [IntegrationTest] + public async Task GetsAllBranchesWithRepositoryId() { - PageSize = 5, - PageCount = 1 - }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); - var branches = await github.Repository.Branch.GetAll(7528679, options); + var branches = await _github.Repository.Branch.GetAll(repoContext.RepositoryId); - Assert.Equal(5, branches.Count); - } + Assert.NotEmpty(branches); + } + } - [IntegrationTest] - public async Task ReturnsCorrectCountOfBranchesWithStart() - { - var github = Helper.GetAuthenticatedClient(); - - var options = new ApiOptions + [IntegrationTest] + public async Task ReturnsCorrectCountOfBranchesWithoutStart() { - PageSize = 5, - PageCount = 1, - StartPage = 2 - }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-4", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-5", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-6", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-7", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-8", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-9", repoContext.Repository.DefaultBranch); - var branches = await github.Repository.Branch.GetAll("octokit", "octokit.net", options); + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; - Assert.Equal(5, branches.Count); - } + var branches = await _github.Repository.Branch.GetAll(repoContext.RepositoryOwner, repoContext.RepositoryName, options); - [IntegrationTest] - public async Task ReturnsCorrectCountOfBranchesWithStartWithRepositoryId() - { - var github = Helper.GetAuthenticatedClient(); + Assert.Equal(5, branches.Count); + } + } - var options = new ApiOptions + [IntegrationTest] + public async Task ReturnsCorrectCountOfBranchesWithoutStartWithRepositoryId() { - PageSize = 5, - PageCount = 1, - StartPage = 2 - }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-4", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-5", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-6", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-7", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-8", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-9", repoContext.Repository.DefaultBranch); - var branches = await github.Repository.Branch.GetAll(7528679, options); + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; - Assert.Equal(5, branches.Count); - } + var branches = await _github.Repository.Branch.GetAll(repoContext.RepositoryId, options); - [IntegrationTest] - public async Task GetsPagesOfBranches() - { - var github = Helper.GetAuthenticatedClient(); + Assert.Equal(5, branches.Count); + } + } - var firstPageOptions = new ApiOptions + [IntegrationTest] + public async Task ReturnsCorrectCountOfBranchesWithStart() { - PageSize = 5, - StartPage = 1, - PageCount = 1 - }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-4", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-5", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-6", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-7", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-8", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-9", repoContext.Repository.DefaultBranch); - var firstPage = await github.Repository.Branch.GetAll("octokit", "octokit.net", firstPageOptions); + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; - var secondPageOptions = new ApiOptions + var branches = await _github.Repository.Branch.GetAll(repoContext.RepositoryOwner, repoContext.RepositoryName, options); + + Assert.Equal(5, branches.Count); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfBranchesWithStartWithRepositoryId() { - PageSize = 5, - StartPage = 2, - PageCount = 1 - }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-4", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-5", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-6", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-7", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-8", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-9", repoContext.Repository.DefaultBranch); - var secondPage = await github.Repository.Branch.GetAll("octokit", "octokit.net", secondPageOptions); + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; - Assert.Equal(5, firstPage.Count); - Assert.Equal(5, secondPage.Count); + var branches = await _github.Repository.Branch.GetAll(repoContext.RepositoryId, options); - Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); - Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); - Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); - Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); - Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); - } + Assert.Equal(5, branches.Count); + } + } - [IntegrationTest] - public async Task GetsPagesOfBranchesWithRepositoryId() - { - var github = Helper.GetAuthenticatedClient(); - - var firstPageOptions = new ApiOptions + [IntegrationTest] + public async Task GetsPagesOfBranches() { - PageSize = 5, - StartPage = 1, - PageCount = 1 - }; + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-4", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-5", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-6", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-7", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-8", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-9", repoContext.Repository.DefaultBranch); - var firstPage = await github.Repository.Branch.GetAll(7528679, firstPageOptions); + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; - var secondPageOptions = new ApiOptions + var firstPage = await _github.Repository.Branch.GetAll(repoContext.RepositoryOwner, repoContext.RepositoryName, firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 2, + PageCount = 1 + }; + + var secondPage = await _github.Repository.Branch.GetAll(repoContext.RepositoryOwner, repoContext.RepositoryName, secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); + } + } + + [IntegrationTest] + public async Task GetsPagesOfBranchesWithRepositoryId() { - PageSize = 5, - StartPage = 2, - PageCount = 1 - }; - - var secondPage = await github.Repository.Branch.GetAll(7528679, secondPageOptions); - - Assert.Equal(5, firstPage.Count); - Assert.Equal(5, secondPage.Count); - - Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); - Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); - Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); - Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); - Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); - } - } - - public class TheGetMethod - { - [IntegrationTest] - public async Task GetsABranch() - { - var github = Helper.GetAuthenticatedClient(); - - var branch = await github.Repository.Branch.Get("octokit", "octokit.net", "master"); - - Assert.NotNull(branch); - Assert.Equal("master", branch.Name); - - Assert.True(branch.Protected); - } - - [IntegrationTest] - public async Task GetsABranchWithRepositoryId() - { - var github = Helper.GetAuthenticatedClient(); - - var branch = await github.Repository.Branch.Get(7528679, "master"); - - Assert.NotNull(branch); - Assert.Equal("master", branch.Name); - - Assert.True(branch.Protected); - } - } - - public class TheGetBranchProtectionMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - - public TheGetBranchProtectionMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsBranchProtection() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var protection = await _client.GetBranchProtection(repoOwner, repoName, "main"); - - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - - Assert.Null(protection.Restrictions); - - Assert.True(protection.EnforceAdmins.Enabled); - Assert.True(protection.RequiredLinearHistory.Enabled); - Assert.True(protection.AllowForcePushes.Enabled); - Assert.True(protection.AllowDeletions.Enabled); - Assert.False(protection.BlockCreations.Enabled); - Assert.True(protection.RequiredConversationResolution.Enabled); - } - - [IntegrationTest] - public async Task GetsBranchProtectionWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var protection = await _client.GetBranchProtection(repoId, "main"); - - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - - Assert.Null(protection.Restrictions); - - Assert.True(protection.EnforceAdmins.Enabled); - Assert.True(protection.RequiredLinearHistory.Enabled); - Assert.True(protection.AllowForcePushes.Enabled); - Assert.True(protection.AllowDeletions.Enabled); - Assert.False(protection.BlockCreations.Enabled); - Assert.True(protection.RequiredConversationResolution.Enabled); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - } - } - - public class TheGetBranchOrgProtectionMethod : IDisposable - { - IRepositoryBranchesClient _client; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheGetBranchOrgProtectionMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [OrganizationTest] - public async Task GetsBranchProtectionForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var protection = await _client.GetBranchProtection(repoOwner, repoName, "main"); - - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - - Assert.Equal(1, protection.Restrictions.Teams.Count); - Assert.Equal(0, protection.Restrictions.Users.Count); - - Assert.True(protection.EnforceAdmins.Enabled); - } - - [OrganizationTest] - public async Task GetsBranchProtectionForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var protection = await _client.GetBranchProtection(repoId, "main"); - - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - - Assert.Equal(1, protection.Restrictions.Teams.Count); - Assert.Equal(0, protection.Restrictions.Users.Count); - - Assert.True(protection.EnforceAdmins.Enabled); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheUpdateBranchProtectionMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheUpdateBranchProtectionMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task UpdatesBranchProtection() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(false, true, 2), - false); - - var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update); - - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - - Assert.Null(protection.Restrictions); - - Assert.False(protection.EnforceAdmins.Enabled); - } - - [IntegrationTest] - public async Task UpdatesBranchProtectionWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(false, true, 2), - false); - - var protection = await _client.UpdateBranchProtection(repoId, "master", update); - - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - - Assert.Null(protection.Restrictions); - - Assert.False(protection.EnforceAdmins.Enabled); - } - - [IntegrationTest] - public async Task UpdatesBranchProtectionForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), - new BranchProtectionPushRestrictionsUpdate(), - false); - - var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update); - - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - - Assert.Empty(protection.Restrictions.Teams); - Assert.Empty(protection.Restrictions.Users); - - Assert.False(protection.EnforceAdmins.Enabled); - } - - [IntegrationTest] - public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), - new BranchProtectionPushRestrictionsUpdate(), - false); - - var protection = await _client.UpdateBranchProtection(repoId, "master", update); - - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - - Assert.Empty(protection.Restrictions.Teams); - Assert.Empty(protection.Restrictions.Users); - - Assert.False(protection.EnforceAdmins.Enabled); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheDeleteBranchProtectionMethod - { - IGitHubClient _github; - IRepositoryBranchesClient _client; - - public TheDeleteBranchProtectionMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task DeletesBranchProtection() - { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) - { - var repoOwner = context.RepositoryOwner; - var repoName = context.RepositoryName; - var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "master"); - - Assert.True(deleted); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-1", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-2", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-3", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-4", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-5", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-6", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-7", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-8", repoContext.Repository.DefaultBranch); + await _github.Git.Reference.CreateBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, "patch-9", repoContext.Repository.DefaultBranch); + + var firstPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 1, + PageCount = 1 + }; + + var firstPage = await _github.Repository.Branch.GetAll(repoContext.RepositoryId, firstPageOptions); + + var secondPageOptions = new ApiOptions + { + PageSize = 5, + StartPage = 2, + PageCount = 1 + }; + + var secondPage = await _github.Repository.Branch.GetAll(repoContext.RepositoryId, secondPageOptions); + + Assert.Equal(5, firstPage.Count); + Assert.Equal(5, secondPage.Count); + + Assert.NotEqual(firstPage[0].Name, secondPage[0].Name); + Assert.NotEqual(firstPage[1].Name, secondPage[1].Name); + Assert.NotEqual(firstPage[2].Name, secondPage[2].Name); + Assert.NotEqual(firstPage[3].Name, secondPage[3].Name); + Assert.NotEqual(firstPage[4].Name, secondPage[4].Name); + } } } - [IntegrationTest] - public async Task DeletesBranchProtectionWithRepositoryId() + public class TheGetMethod : GitHubClientTestBase { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task GetsABranch() { - var repoId = context.RepositoryId; - var deleted = await _client.DeleteBranchProtection(repoId, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var branch = await _github.Repository.Branch.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(branch); + Assert.Equal(repoContext.RepositoryDefaultBranch, branch.Name); + + Assert.True(branch.Protected); + } + } + + [IntegrationTest] + public async Task GetsABranchWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var branch = await _github.Repository.Branch.Get(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(branch); + Assert.Equal(repoContext.RepositoryDefaultBranch, branch.Name); + + Assert.True(branch.Protected); + } } } - [IntegrationTest] - public async Task DeletesBranchProtectionForOrgRepo() + public class TheGetBranchProtectionMethod : GitHubClientTestBase { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task GetsBranchProtection() { - var repoOwner = context.RepositoryContext.RepositoryOwner; - var repoName = context.RepositoryContext.RepositoryName; - var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var protection = await _github.Repository.Branch.GetBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + + Assert.Null(protection.Restrictions); + + Assert.True(protection.EnforceAdmins.Enabled); + Assert.True(protection.RequiredLinearHistory.Enabled); + Assert.True(protection.AllowForcePushes.Enabled); + Assert.True(protection.AllowDeletions.Enabled); + Assert.False(protection.BlockCreations.Enabled); + Assert.True(protection.RequiredConversationResolution.Enabled); + } + } + + [IntegrationTest] + public async Task GetsBranchProtectionWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var protection = await _github.Repository.Branch.GetBranchProtection(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + + Assert.Null(protection.Restrictions); + + Assert.True(protection.EnforceAdmins.Enabled); + Assert.True(protection.RequiredLinearHistory.Enabled); + Assert.True(protection.AllowForcePushes.Enabled); + Assert.True(protection.AllowDeletions.Enabled); + Assert.False(protection.BlockCreations.Enabled); + Assert.True(protection.RequiredConversationResolution.Enabled); + } + } + + [OrganizationTest] + public async Task GetsBranchProtectionForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var protection = await _github.Repository.Branch.GetBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + + Assert.Equal(1, protection.Restrictions.Teams.Count); + Assert.Equal(0, protection.Restrictions.Users.Count); + + Assert.True(protection.EnforceAdmins.Enabled); + } + } + + [OrganizationTest] + public async Task GetsBranchProtectionForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var protection = await _github.Repository.Branch.GetBranchProtection(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + + Assert.Equal(1, protection.Restrictions.Teams.Count); + Assert.Equal(0, protection.Restrictions.Users.Count); + + Assert.True(protection.EnforceAdmins.Enabled); + } } } - [IntegrationTest] - public async Task DeletesBranchProtectionForOrgRepoWithRepositoryId() + public class TheUpdateBranchProtectionMethod : GitHubClientTestBase { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task UpdatesBranchProtection() { - var repoId = context.RepositoryContext.RepositoryId; - var deleted = await _client.DeleteBranchProtection(repoId, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(false, true, 2), + false); + + var protection = await _github.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + + Assert.Null(protection.Restrictions); + + Assert.False(protection.EnforceAdmins.Enabled); + } } - } - } - public class TheGetRequiredStatusChecksMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - - public TheGetRequiredStatusChecksMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsRequiredStatusChecks() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var requiredStatusChecks = await _client.GetRequiredStatusChecks(repoOwner, repoName, "master"); - - Assert.NotNull(requiredStatusChecks); - Assert.NotNull(requiredStatusChecks.Contexts); - Assert.True(requiredStatusChecks.Strict); - Assert.Equal(2, requiredStatusChecks.Contexts.Count); - } - - [IntegrationTest] - public async Task GetsRequiredStatusChecksWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var requiredStatusChecks = await _client.GetRequiredStatusChecks(repoId, "master"); - - Assert.NotNull(requiredStatusChecks); - Assert.NotNull(requiredStatusChecks.Contexts); - Assert.True(requiredStatusChecks.Strict); - Assert.Equal(2, requiredStatusChecks.Contexts.Count); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - } - } - - public class TheUpdateRequiredStatusChecksMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - - public TheUpdateRequiredStatusChecksMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task UpdateRequiredStatusChecks() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "new" }); - var requiredStatusChecks = await _client.UpdateRequiredStatusChecks(repoOwner, repoName, "master", update); - - Assert.NotNull(requiredStatusChecks); - Assert.NotNull(requiredStatusChecks.Contexts); - Assert.Contains("new", requiredStatusChecks.Contexts); - Assert.True(requiredStatusChecks.Strict); - Assert.Equal(1, requiredStatusChecks.Contexts.Count); - } - - [IntegrationTest] - public async Task UpdatesRequiredStatusChecksWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "new" }); - var requiredStatusChecks = await _client.UpdateRequiredStatusChecks(repoId, "master", update); - - Assert.NotNull(requiredStatusChecks); - Assert.NotNull(requiredStatusChecks.Contexts); - Assert.Contains("new", requiredStatusChecks.Contexts); - Assert.True(requiredStatusChecks.Strict); - Assert.Equal(1, requiredStatusChecks.Contexts.Count); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - } - } - - public class TheDeleteRequiredStatusChecksMethod - { - IGitHubClient _github; - IRepositoryBranchesClient _client; - - public TheDeleteRequiredStatusChecksMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task DeletesRequiredStatusChecks() - { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task UpdatesBranchProtectionWithRepositoryId() { - var repoOwner = context.RepositoryOwner; - var repoName = context.RepositoryName; - var deleted = await _client.DeleteRequiredStatusChecks(repoOwner, repoName, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(false, true, 2), + false); + + var protection = await _github.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + + Assert.Null(protection.Restrictions); + + Assert.False(protection.EnforceAdmins.Enabled); + } + } + + [OrganizationTest] + public async Task UpdatesBranchProtectionForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), + new BranchProtectionPushRestrictionsUpdate(), + false); + + var protection = await _github.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + + Assert.Empty(protection.Restrictions.Teams); + Assert.Empty(protection.Restrictions.Users); + + Assert.False(protection.EnforceAdmins.Enabled); + } + } + + [OrganizationTest] + public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), + new BranchProtectionPushRestrictionsUpdate(), + false); + + var protection = await _github.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + + Assert.Empty(protection.Restrictions.Teams); + Assert.Empty(protection.Restrictions.Users); + + Assert.False(protection.EnforceAdmins.Enabled); + } } } - [IntegrationTest] - public async Task DeletesRequiredStatusChecksWithRepositoryId() + public class TheDeleteBranchProtectionMethod : GitHubClientTestBase { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task DeletesBranchProtection() { - var repoId = context.RepositoryId; - var deleted = await _client.DeleteRequiredStatusChecks(repoId, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var deleted = await _github.Repository.Branch.DeleteBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } } - } - } - public class TheGetAllRequiredStatusChecksContextsMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - - public TheGetAllRequiredStatusChecksContextsMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsRequiredStatusChecksContexts() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var requiredStatusChecksContexts = await _client.GetAllRequiredStatusChecksContexts(repoOwner, repoName, "master"); - - Assert.NotNull(requiredStatusChecksContexts); - Assert.Equal(2, requiredStatusChecksContexts.Count); - } - - [IntegrationTest] - public async Task GetsRequiredStatusChecksContextsWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var requiredStatusChecksContexts = await _client.GetAllRequiredStatusChecksContexts(repoId, "master"); - - Assert.NotNull(requiredStatusChecksContexts); - Assert.Equal(2, requiredStatusChecksContexts.Count); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - } - } - - public class TheUpdateRequiredStatusChecksContextsMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - - public TheUpdateRequiredStatusChecksContextsMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task UpdateRequiredStatusChecksContexts() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var update = new List() { "build2" }; - var requiredStatusChecksContexts = await _client.UpdateRequiredStatusChecksContexts(repoOwner, repoName, "master", update); - - Assert.Equal(1, requiredStatusChecksContexts.Count); - } - - [IntegrationTest] - public async Task UpdatesRequiredStatusChecksContextsWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var update = new List() { "build2" }; - var requiredStatusChecksContexts = await _client.UpdateRequiredStatusChecksContexts(repoId, "master", update); - - Assert.Equal(1, requiredStatusChecksContexts.Count); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - } - } - - public class TheAddRequiredStatusChecksContextsMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - - public TheAddRequiredStatusChecksContextsMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task AddsRequiredStatusChecksContexts() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var update = new List() { "build2", "deploy" }; - var requiredStatusChecksContexts = await _client.AddRequiredStatusChecksContexts(repoOwner, repoName, "master", update); - - Assert.NotNull(requiredStatusChecksContexts); - Assert.Equal(4, requiredStatusChecksContexts.Count); - } - - [IntegrationTest] - public async Task AddsRequiredStatusChecksContextsWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var update = new List() { "build2", "deploy" }; - var requiredStatusChecksContexts = await _client.AddRequiredStatusChecksContexts(repoId, "master", update); - - Assert.NotNull(requiredStatusChecksContexts); - Assert.Equal(4, requiredStatusChecksContexts.Count); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - } - } - - public class TheDeleteRequiredStatusChecksContextsMethod - { - IGitHubClient _github; - IRepositoryBranchesClient _client; - - public TheDeleteRequiredStatusChecksContextsMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task DeletesRequiredStatusChecksContexts() - { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task DeletesBranchProtectionWithRepositoryId() { - var repoOwner = context.RepositoryOwner; - var repoName = context.RepositoryName; - var contextsToRemove = new List() { "build" }; - var deleted = await _client.DeleteRequiredStatusChecksContexts(repoOwner, repoName, "master", contextsToRemove); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.NotNull(deleted); - Assert.Contains("test", deleted); + var deleted = await _github.Repository.Branch.DeleteBranchProtection(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + + [OrganizationTest] + public async Task DeletesBranchProtectionForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var deleted = await _github.Repository.Branch.DeleteBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + + [OrganizationTest] + public async Task DeletesBranchProtectionForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var deleted = await _github.Repository.Branch.DeleteBranchProtection(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } } } - [IntegrationTest] - public async Task DeletesRequiredStatusChecksContextsWithRepositoryId() + public class TheGetRequiredStatusChecksMethod : GitHubClientTestBase { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task GetsRequiredStatusChecks() { - var repoId = context.RepositoryId; - var contextsToRemove = new List() { "build" }; - var deleted = await _client.DeleteRequiredStatusChecksContexts(repoId, "master", contextsToRemove); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + var requiredStatusChecks = await _github.Repository.Branch.GetRequiredStatusChecks(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); - Assert.NotNull(deleted); - Assert.Contains("test", deleted); + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(2, requiredStatusChecks.Contexts.Count); + } } - } - } - public class TheGetReviewEnforcementMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheGetReviewEnforcementMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsReviewEnforcement() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master"); - - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - } - - [IntegrationTest] - public async Task GetsReviewEnforcementWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var requiredReviews = await _client.GetReviewEnforcement(repoId, "master"); - - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - } - - [IntegrationTest] - public async Task GetsReviewEnforcementForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master"); - - Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - } - - [IntegrationTest] - public async Task GetsReviewEnforcementForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var requiredReviews = await _client.GetReviewEnforcement(repoId, "master"); - - Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheUpdateReviewEnforcementMethod : IDisposable - { - IRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheUpdateReviewEnforcementMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task UpdatesReviewEnforcement() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); - - var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update); - - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); - } - - [IntegrationTest] - public async Task UpdatesReviewEnforcementWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); - - var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update); - - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); - } - - [IntegrationTest] - public async Task UpdatesReviewEnforcementForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), - false, - false, - 2); - - var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update); - - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); - } - - [IntegrationTest] - public async Task UpdatesReviewEnforcementForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), - false, - false, - 2); - - var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update); - - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); - } - - [IntegrationTest] - public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnly() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), - false, - false, - 2); - - var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update); - - Assert.Empty(requiredReviews.DismissalRestrictions.Teams); - Assert.Empty(requiredReviews.DismissalRestrictions.Users); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); - } - - [IntegrationTest] - public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnlyWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), - false, - false, - 2); - - var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update); - - Assert.Empty(requiredReviews.DismissalRestrictions.Teams); - Assert.Empty(requiredReviews.DismissalRestrictions.Users); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheRemoveReviewEnforcementMethod - { - IGitHubClient _github; - IRepositoryBranchesClient _client; - - public TheRemoveReviewEnforcementMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task RemovesReviewEnforcement() - { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task GetsRequiredStatusChecksWithRepositoryId() { - var repoOwner = context.RepositoryOwner; - var repoName = context.RepositoryName; - var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + var requiredStatusChecks = await _github.Repository.Branch.GetRequiredStatusChecks(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); - Assert.True(deleted); + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(2, requiredStatusChecks.Contexts.Count); + } } } - [IntegrationTest] - public async Task RemovesReviewEnforcementWithRepositoryId() + public class TheUpdateRequiredStatusChecksMethod : GitHubClientTestBase { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task UpdateRequiredStatusChecks() { - var repoId = context.RepositoryId; - var deleted = await _client.RemoveReviewEnforcement(repoId, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "new" }); + var requiredStatusChecks = await _github.Repository.Branch.UpdateRequiredStatusChecks(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.Contains("new", requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(1, requiredStatusChecks.Contexts.Count); + } + } + + [IntegrationTest] + public async Task UpdatesRequiredStatusChecksWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "new" }); + var requiredStatusChecks = await _github.Repository.Branch.UpdateRequiredStatusChecks(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.Contains("new", requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(1, requiredStatusChecks.Contexts.Count); + } } } - [IntegrationTest] - public async Task RemovesReviewEnforcementForOrgRepo() + public class TheDeleteRequiredStatusChecksMethod : GitHubClientTestBase { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task DeletesRequiredStatusChecks() { - var repoOwner = context.RepositoryContext.RepositoryOwner; - var repoName = context.RepositoryContext.RepositoryName; - var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var deleted = await _github.Repository.Branch.DeleteRequiredStatusChecks(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + + [IntegrationTest] + public async Task DeletesRequiredStatusChecksWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var deleted = await _github.Repository.Branch.DeleteRequiredStatusChecks(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } } } - [IntegrationTest] - public async Task RemovesReviewEnforcementForOrgRepoWithRepositoryId() + public class TheGetAllRequiredStatusChecksContextsMethod : GitHubClientTestBase { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task GetsRequiredStatusChecksContexts() { - var repoId = context.RepositoryContext.RepositoryId; - var deleted = await _client.RemoveReviewEnforcement(repoId, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var requiredStatusChecksContexts = await _github.Repository.Branch.GetAllRequiredStatusChecksContexts(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(requiredStatusChecksContexts); + Assert.Equal(2, requiredStatusChecksContexts.Count); + } } - } - } - public class TheGetAdminEnforcementMethod : IDisposable - { - private readonly IRepositoryBranchesClient _client; - private readonly RepositoryContext _userRepoContext; - - public TheGetAdminEnforcementMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsAdminEnforcement() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var enforceAdmins = await _client.GetAdminEnforcement(repoOwner, repoName, "master"); - - Assert.NotNull(enforceAdmins); - Assert.True(enforceAdmins.Enabled); - } - - [IntegrationTest] - public async Task GetsAdminEnforcementWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - var enforceAdmins = await _client.GetAdminEnforcement(repoId, "master"); - - Assert.NotNull(enforceAdmins); - Assert.True(enforceAdmins.Enabled); - } - - public void Dispose() - { - if (_userRepoContext != null) + [IntegrationTest] + public async Task GetsRequiredStatusChecksContextsWithRepositoryId() { - _userRepoContext.Dispose(); - } - } - } + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - public class TheAddAdminEnforcementMethod : IDisposable - { - private readonly IRepositoryBranchesClient _client; - private readonly RepositoryContext _userRepoContext; + var requiredStatusChecksContexts = await _github.Repository.Branch.GetAllRequiredStatusChecksContexts(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); - public TheAddAdminEnforcementMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task AddsAdminEnforcement() - { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - - await _client.RemoveAdminEnforcement(repoOwner, repoName, "master"); - var enforceAdmins = await _client.AddAdminEnforcement(repoOwner, repoName, "master"); - - Assert.NotNull(enforceAdmins); - Assert.True(enforceAdmins.Enabled); - } - - [IntegrationTest] - public async Task AddsAdminEnforcementoWithRepositoryId() - { - var repoId = _userRepoContext.RepositoryId; - - await _client.RemoveAdminEnforcement(repoId, "master"); - var enforceAdmins = await _client.AddAdminEnforcement(repoId, "master"); - - Assert.NotNull(enforceAdmins); - Assert.True(enforceAdmins.Enabled); - } - - public void Dispose() - { - if (_userRepoContext != null) - { - _userRepoContext.Dispose(); - } - } - } - - public class TheRemoveAdminEnforcementMethod - { - private readonly IRepositoryBranchesClient _client; - private readonly IGitHubClient _github; - - public TheRemoveAdminEnforcementMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task RemovesAdminEnforcement() - { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) - { - var repoOwner = context.RepositoryOwner; - var repoName = context.RepositoryName; - var deleted = await _client.RemoveAdminEnforcement(repoOwner, repoName, "master"); - - Assert.True(deleted); - - var enforceAdmins = await _client.GetAdminEnforcement(repoOwner, repoName, "master"); - - Assert.NotNull(enforceAdmins); - Assert.False(enforceAdmins.Enabled); + Assert.NotNull(requiredStatusChecksContexts); + Assert.Equal(2, requiredStatusChecksContexts.Count); + } } } - [IntegrationTest] - public async Task RemovesAdminEnforcementWithRepositoryId() + public class TheUpdateRequiredStatusChecksContextsMethod : GitHubClientTestBase { - using (var context = await _github.CreateRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task UpdateRequiredStatusChecksContexts() { - var repoId = context.RepositoryId; - var deleted = await _client.RemoveAdminEnforcement(repoId, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var update = new List() { "build2" }; + var requiredStatusChecksContexts = await _github.Repository.Branch.UpdateRequiredStatusChecksContexts(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); - var enforceAdmins = await _client.GetAdminEnforcement(repoId, "master"); - - Assert.NotNull(enforceAdmins); - Assert.False(enforceAdmins.Enabled); + Assert.Equal(1, requiredStatusChecksContexts.Count); + } } - } - } - public class TheGetProtectedBranchRestrictionsMethod : IDisposable - { - IRepositoryBranchesClient _client; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheGetProtectedBranchRestrictionsMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsRequirProtectedBranchRestrictionsForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var restrictions = await _client.GetProtectedBranchRestrictions(repoOwner, repoName, "master"); - - Assert.Equal(1, restrictions.Teams.Count); - Assert.Equal(0, restrictions.Users.Count); - } - - [IntegrationTest] - public async Task GetsProtectedBranchRestrictionsForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var restrictions = await _client.GetProtectedBranchRestrictions(repoId, "master"); - - Assert.Equal(1, restrictions.Teams.Count); - Assert.Equal(0, restrictions.Users.Count); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheDeleteProtectedBranchRestrictionsMethod - { - IGitHubClient _github; - IRepositoryBranchesClient _client; - - public TheDeleteProtectedBranchRestrictionsMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task DeletesRProtectedBranchRestrictionsForOrgRepo() - { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task UpdatesRequiredStatusChecksContextsWithRepositoryId() { - var repoOwner = context.RepositoryContext.RepositoryOwner; - var repoName = context.RepositoryContext.RepositoryName; - var deleted = await _client.DeleteProtectedBranchRestrictions(repoOwner, repoName, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var update = new List() { "build2" }; + var requiredStatusChecksContexts = await _github.Repository.Branch.UpdateRequiredStatusChecksContexts(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.Equal(1, requiredStatusChecksContexts.Count); + } } } - [IntegrationTest] - public async Task DeletesProtectedBranchRestrictionsForOrgRepoWithRepositoryId() + public class TheAddRequiredStatusChecksContextsMethod : GitHubClientTestBase { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task AddsRequiredStatusChecksContexts() { - var repoId = context.RepositoryContext.RepositoryId; - var deleted = await _client.DeleteProtectedBranchRestrictions(repoId, "master"); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.True(deleted); + var update = new List() { "build2", "deploy" }; + var requiredStatusChecksContexts = await _github.Repository.Branch.AddRequiredStatusChecksContexts(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + + Assert.NotNull(requiredStatusChecksContexts); + Assert.Equal(4, requiredStatusChecksContexts.Count); + } } - } - } - public class TheGetAllProtectedBranchTeamRestrictionsMethod : IDisposable - { - IRepositoryBranchesClient _client; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheGetAllProtectedBranchTeamRestrictionsMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsProtectedBranchTeamRestrictionsForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var restrictions = await _client.GetAllProtectedBranchTeamRestrictions(repoOwner, repoName, "master"); - - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); - } - - [IntegrationTest] - public async Task GetsProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var restrictions = await _client.GetAllProtectedBranchTeamRestrictions(repoId, "master"); - - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheUpdateProtectedBranchTeamRestrictionsMethod : IDisposable - { - IRepositoryBranchesClient _client; - OrganizationRepositoryWithTeamContext _orgRepoContext; - TeamContext _contextOrgTeam2; - IGitHubClient _github; - - public TheUpdateProtectedBranchTeamRestrictionsMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - - _contextOrgTeam2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; - _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task UpdatesProtectedBranchTeamRestrictionsForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - - // Grant team push access to repo - await _github.Organization.Team.AddRepository( - _contextOrgTeam2.TeamId, - repoOwner, - repoName, - new RepositoryPermissionRequest(Permission.Push)); - - var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; - var restrictions = await _client.UpdateProtectedBranchTeamRestrictions(repoOwner, repoName, "master", newTeam); - - Assert.NotNull(restrictions); - Assert.Equal(_contextOrgTeam2.TeamName, restrictions[0].Name); - } - - [IntegrationTest] - public async Task UpdatesProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - - // Grant team push access to repo - await _github.Organization.Team.AddRepository( - _contextOrgTeam2.TeamId, - repoOwner, - repoName, - new RepositoryPermissionRequest(Permission.Push)); - - var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; - var restrictions = await _client.UpdateProtectedBranchTeamRestrictions(repoId, "master", newTeam); - - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - - if (_contextOrgTeam2 != null) - _contextOrgTeam2.Dispose(); - } - } - - public class TheAddProtectedBranchTeamRestrictionsMethod : IDisposable - { - IRepositoryBranchesClient _client; - OrganizationRepositoryWithTeamContext _orgRepoContext; - TeamContext _contextOrgTeam2; - IGitHubClient _github; - - public TheAddProtectedBranchTeamRestrictionsMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - - _contextOrgTeam2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; - _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task AddsProtectedBranchTeamRestrictionsForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - - // Grant team push access to repo - await _github.Organization.Team.AddRepository( - _contextOrgTeam2.TeamId, - repoOwner, - repoName, - new RepositoryPermissionRequest(Permission.Push)); - - var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; - var restrictions = await _client.AddProtectedBranchTeamRestrictions(repoOwner, repoName, "master", newTeam); - - Assert.NotNull(restrictions); - Assert.Equal(2, restrictions.Count); - } - - [IntegrationTest] - public async Task AddsProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - - // Grant team push access to repo - await _github.Organization.Team.AddRepository( - _contextOrgTeam2.TeamId, - repoOwner, - repoName, - new RepositoryPermissionRequest(Permission.Push)); - - var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; - var restrictions = await _client.AddProtectedBranchTeamRestrictions(repoId, "master", newTeam); - - Assert.NotNull(restrictions); - Assert.Equal(2, restrictions.Count); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - - if (_contextOrgTeam2 != null) - _contextOrgTeam2.Dispose(); - } - } - - public class TheDeleteProtectedBranchTeamRestrictions - { - IGitHubClient _github; - IRepositoryBranchesClient _client; - - public TheDeleteProtectedBranchTeamRestrictions() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task DeletesRProtectedBranchTeamRestrictionsForOrgRepo() - { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task AddsRequiredStatusChecksContextsWithRepositoryId() { - var repoOwner = context.RepositoryContext.RepositoryOwner; - var repoName = context.RepositoryContext.RepositoryName; - var teamToRemove = new BranchProtectionTeamCollection() { context.TeamContext.TeamName }; - var deleted = await _client.DeleteProtectedBranchTeamRestrictions(repoOwner, repoName, "master", teamToRemove); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.NotNull(deleted); - Assert.Equal(0, deleted.Count); + var update = new List() { "build2", "deploy" }; + var requiredStatusChecksContexts = await _github.Repository.Branch.AddRequiredStatusChecksContexts(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.NotNull(requiredStatusChecksContexts); + Assert.Equal(4, requiredStatusChecksContexts.Count); + } } } - [IntegrationTest] - public async Task DeletesProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + public class TheDeleteRequiredStatusChecksContextsMethod : GitHubClientTestBase { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task DeletesRequiredStatusChecksContexts() { - var repoId = context.RepositoryContext.RepositoryId; - var teamToRemove = new BranchProtectionTeamCollection() { context.TeamContext.TeamName }; - var deleted = await _client.DeleteProtectedBranchTeamRestrictions(repoId, "master", teamToRemove); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.NotNull(deleted); - Assert.Equal(0, deleted.Count); + var contextsToRemove = new List() { "build" }; + var deleted = await _github.Repository.Branch.DeleteRequiredStatusChecksContexts(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, contextsToRemove); + + Assert.NotNull(deleted); + Assert.Contains("test", deleted); + } } - } - } - public class TheGetAllProtectedBranchUserRestrictionsMethod : IDisposable - { - IRepositoryBranchesClient _client; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheGetAllProtectedBranchUserRestrictionsMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = github.Repository.Branch; - - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task GetsProtectedBranchUserRestrictionsForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var restrictions = await _client.GetAllProtectedBranchUserRestrictions(repoOwner, repoName, "master"); - - Assert.NotNull(restrictions); - Assert.Equal(0, restrictions.Count); - } - - [IntegrationTest] - public async Task GetsProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var restrictions = await _client.GetAllProtectedBranchUserRestrictions(repoId, "master"); - - Assert.NotNull(restrictions); - Assert.Equal(0, restrictions.Count); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheUpdateProtectedBranchUserRestrictionsMethod : IDisposable - { - IRepositoryBranchesClient _client; - IGitHubClient _github; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheUpdateProtectedBranchUserRestrictionsMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - - _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task UpdatesProtectedBranchUserRestrictionsForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; - - var restrictions = await _client.UpdateProtectedBranchUserRestrictions(repoOwner, repoName, "master", newUser); - - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); - } - - [IntegrationTest] - public async Task UpdatesProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; - - var restrictions = await _client.UpdateProtectedBranchUserRestrictions(repoId, "master", newUser); - - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheAddProtectedBranchUserRestrictionsMethod : IDisposable - { - IRepositoryBranchesClient _client; - IGitHubClient _github; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheAddProtectedBranchUserRestrictionsMethod() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - - _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; - } - - [IntegrationTest] - public async Task AddsProtectedBranchUserRestrictionsForOrgRepo() - { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; - - var restrictions = await _client.AddProtectedBranchUserRestrictions(repoOwner, repoName, "master", newUser); - - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); - } - - [IntegrationTest] - public async Task AddsProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() - { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; - - var restrictions = await _client.AddProtectedBranchUserRestrictions(repoId, "master", newUser); - - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); - } - } - - public class TheDeleteProtectedBranchUserRestrictions - { - IGitHubClient _github; - IRepositoryBranchesClient _client; - - public TheDeleteProtectedBranchUserRestrictions() - { - _github = Helper.GetAuthenticatedClient(); - _client = _github.Repository.Branch; - } - - [IntegrationTest] - public async Task DeletesProtectedBranchUserRestrictionsForOrgRepo() - { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task DeletesRequiredStatusChecksContextsWithRepositoryId() { - var repoOwner = context.RepositoryContext.RepositoryOwner; - var repoName = context.RepositoryContext.RepositoryName; - var user = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; - var restrictions = await _client.AddProtectedBranchUserRestrictions(repoOwner, repoName, "master", user); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); + var contextsToRemove = new List() { "build" }; + var deleted = await _github.Repository.Branch.DeleteRequiredStatusChecksContexts(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, contextsToRemove); - var deleted = await _client.DeleteProtectedBranchUserRestrictions(repoOwner, repoName, "master", user); - - Assert.NotNull(deleted); - Assert.Equal(0, deleted.Count); + Assert.NotNull(deleted); + Assert.Contains("test", deleted); + } } } - [IntegrationTest] - public async Task DeletesProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + public class TheGetReviewEnforcementMethod : GitHubClientTestBase { - using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + [IntegrationTest] + public async Task GetsReviewEnforcement() { - var repoId = context.RepositoryContext.RepositoryId; - var user = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; - var restrictions = await _client.AddProtectedBranchUserRestrictions(repoId, "master", user); + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); - Assert.NotNull(restrictions); - Assert.Equal(1, restrictions.Count); + var requiredReviews = await _github.Repository.Branch.GetReviewEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); - var deleted = await _client.DeleteProtectedBranchUserRestrictions(repoId, "master", user); + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } + } - Assert.NotNull(deleted); - Assert.Equal(0, deleted.Count); + [IntegrationTest] + public async Task GetsReviewEnforcementWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var requiredReviews = await _github.Repository.Branch.GetReviewEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } + } + + [OrganizationTest] + public async Task GetsReviewEnforcementForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var requiredReviews = await _github.Repository.Branch.GetReviewEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } + } + + [OrganizationTest] + public async Task GetsReviewEnforcementForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var requiredReviews = await _github.Repository.Branch.GetReviewEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } + } + } + + public class TheUpdateReviewEnforcementMethod : GitHubClientTestBase + { + [IntegrationTest] + public async Task UpdatesReviewEnforcement() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); + + var requiredReviews = await _github.Repository.Branch.UpdateReviewEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } + } + + [IntegrationTest] + public async Task UpdatesReviewEnforcementWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); + + var requiredReviews = await _github.Repository.Branch.UpdateReviewEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } + } + + [OrganizationTest] + public async Task UpdatesReviewEnforcementForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), + false, + false, + 2); + + var requiredReviews = await _github.Repository.Branch.UpdateReviewEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } + } + + [OrganizationTest] + public async Task UpdatesReviewEnforcementForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), + false, + false, + 2); + + var requiredReviews = await _github.Repository.Branch.UpdateReviewEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } + } + + [OrganizationTest] + public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnly() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), + false, + false, + 2); + + var requiredReviews = await _github.Repository.Branch.UpdateReviewEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + + Assert.Empty(requiredReviews.DismissalRestrictions.Teams); + Assert.Empty(requiredReviews.DismissalRestrictions.Users); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } + } + + [OrganizationTest] + public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnlyWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), + false, + false, + 2); + + var requiredReviews = await _github.Repository.Branch.UpdateReviewEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, update); + + Assert.Empty(requiredReviews.DismissalRestrictions.Teams); + Assert.Empty(requiredReviews.DismissalRestrictions.Users); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } + } + } + + public class TheRemoveReviewEnforcementMethod : GitHubClientTestBase + { + [IntegrationTest] + public async Task RemovesReviewEnforcement() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var deleted = await _github.Repository.Branch.RemoveReviewEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + + [IntegrationTest] + public async Task RemovesReviewEnforcementWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var deleted = await _github.Repository.Branch.RemoveReviewEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + + [OrganizationTest] + public async Task RemovesReviewEnforcementForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var deleted = await _github.Repository.Branch.RemoveReviewEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + + [OrganizationTest] + public async Task RemovesReviewEnforcementForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var deleted = await _github.Repository.Branch.RemoveReviewEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + } + + public class TheGetAdminEnforcementMethod : GitHubClientTestBase + { + [IntegrationTest] + public async Task GetsAdminEnforcement() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var enforceAdmins = await _github.Repository.Branch.GetAdminEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(enforceAdmins); + Assert.True(enforceAdmins.Enabled); + } + } + + [IntegrationTest] + public async Task GetsAdminEnforcementWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var enforceAdmins = await _github.Repository.Branch.GetAdminEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(enforceAdmins); + Assert.True(enforceAdmins.Enabled); + } + } + } + + public class TheAddAdminEnforcementMethod : GitHubClientTestBase + { + [IntegrationTest] + public async Task AddsAdminEnforcement() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + await _github.Repository.Branch.RemoveAdminEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + var enforceAdmins = await _github.Repository.Branch.AddAdminEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(enforceAdmins); + Assert.True(enforceAdmins.Enabled); + } + } + + [IntegrationTest] + public async Task AddsAdminEnforcementoWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + await _github.Repository.Branch.RemoveAdminEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + var enforceAdmins = await _github.Repository.Branch.AddAdminEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(enforceAdmins); + Assert.True(enforceAdmins.Enabled); + } + } + } + + public class TheRemoveAdminEnforcementMethod : GitHubClientTestBase + { + [IntegrationTest] + public async Task RemovesAdminEnforcement() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var deleted = await _github.Repository.Branch.RemoveAdminEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + + var enforceAdmins = await _github.Repository.Branch.GetAdminEnforcement(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(enforceAdmins); + Assert.False(enforceAdmins.Enabled); + } + } + + [IntegrationTest] + public async Task RemovesAdminEnforcementWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var deleted = await _github.Repository.Branch.RemoveAdminEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + + var enforceAdmins = await _github.Repository.Branch.GetAdminEnforcement(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(enforceAdmins); + Assert.False(enforceAdmins.Enabled); + } + } + } + + public class TheGetProtectedBranchRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task GetsRequirProtectedBranchRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var restrictions = await _github.Repository.Branch.GetProtectedBranchRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.Equal(1, restrictions.Teams.Count); + Assert.Equal(0, restrictions.Users.Count); + } + } + + [OrganizationTest] + public async Task GetsProtectedBranchRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var restrictions = await _github.Repository.Branch.GetProtectedBranchRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.Equal(1, restrictions.Teams.Count); + Assert.Equal(0, restrictions.Users.Count); + } + } + } + + public class TheDeleteProtectedBranchRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task DeletesRProtectedBranchRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var deleted = await _github.Repository.Branch.DeleteProtectedBranchRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + + [OrganizationTest] + public async Task DeletesProtectedBranchRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext()) + { + await _github.ProtectDefaultBranch(repoContext); + + var deleted = await _github.Repository.Branch.DeleteProtectedBranchRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.True(deleted); + } + } + } + + public class TheGetAllProtectedBranchTeamRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task GetsProtectedBranchTeamRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var restrictions = await _github.Repository.Branch.GetAllProtectedBranchTeamRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + } + + [OrganizationTest] + public async Task GetsProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var restrictions = await _github.Repository.Branch.GetAllProtectedBranchTeamRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + } + } + + public class TheUpdateProtectedBranchTeamRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task UpdatesProtectedBranchTeamRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var team2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + team2.TeamId, + repoContext.RepositoryOwner, + repoContext.RepositoryName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; + var restrictions = await _github.Repository.Branch.UpdateProtectedBranchTeamRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(team2.TeamName, restrictions[0].Name); + } + } + + [OrganizationTest] + public async Task UpdatesProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var team2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + team2.TeamId, + repoContext.RepositoryOwner, + repoContext.RepositoryName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; + var restrictions = await _github.Repository.Branch.UpdateProtectedBranchTeamRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + } + } + + public class TheAddProtectedBranchTeamRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task AddsProtectedBranchTeamRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var team2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + team2.TeamId, + repoContext.RepositoryOwner, + repoContext.RepositoryName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; + var restrictions = await _github.Repository.Branch.AddProtectedBranchTeamRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(2, restrictions.Count); + } + } + + [OrganizationTest] + public async Task AddsProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var team2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + team2.TeamId, + repoContext.RepositoryOwner, + repoContext.RepositoryName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; + var restrictions = await _github.Repository.Branch.AddProtectedBranchTeamRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(2, restrictions.Count); + } + } + } + + public class TheDeleteProtectedBranchTeamRestrictions : GitHubClientTestBase + { + [OrganizationTest] + public async Task DeletesRProtectedBranchTeamRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + var team = await _github.ProtectDefaultBranchWithTeam(repoContext); + + var teamToRemove = new BranchProtectionTeamCollection() { team.TeamName }; + var deleted = await _github.Repository.Branch.DeleteProtectedBranchTeamRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, teamToRemove); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } + } + + [OrganizationTest] + public async Task DeletesProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + var team = await _github.ProtectDefaultBranchWithTeam(repoContext); + + var teamToRemove = new BranchProtectionTeamCollection() { team.TeamName }; + var deleted = await _github.Repository.Branch.DeleteProtectedBranchTeamRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, teamToRemove); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } + } + } + + public class TheGetAllProtectedBranchUserRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task GetsProtectedBranchUserRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var restrictions = await _github.Repository.Branch.GetAllProtectedBranchUserRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(restrictions); + Assert.Equal(0, restrictions.Count); + } + } + + [OrganizationTest] + public async Task GetsProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var restrictions = await _github.Repository.Branch.GetAllProtectedBranchUserRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch); + + Assert.NotNull(restrictions); + Assert.Equal(0, restrictions.Count); + } + } + } + + public class TheUpdateProtectedBranchUserRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task UpdatesProtectedBranchUserRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _github.Repository.Branch.UpdateProtectedBranchUserRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + } + + [OrganizationTest] + public async Task UpdatesProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _github.Repository.Branch.UpdateProtectedBranchUserRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + } + } + + public class TheAddProtectedBranchUserRestrictionsMethod : GitHubClientTestBase + { + [OrganizationTest] + public async Task AddsProtectedBranchUserRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + var team = await _github.ProtectDefaultBranchWithTeam(repoContext); + + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _github.Repository.Branch.AddProtectedBranchUserRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + } + + [OrganizationTest] + public async Task AddsProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _github.Repository.Branch.AddProtectedBranchUserRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + } + } + + public class TheDeleteProtectedBranchUserRestrictions : GitHubClientTestBase + { + [OrganizationTest] + public async Task DeletesProtectedBranchUserRestrictionsForOrgRepo() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var user = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + var restrictions = await _github.Repository.Branch.AddProtectedBranchUserRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, user); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + + var deleted = await _github.Repository.Branch.DeleteProtectedBranchUserRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, user); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } + } + + [OrganizationTest] + public async Task DeletesProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + using (var repoContext = await _github.CreateOrganizationRepositoryContext()) + { + await _github.ProtectDefaultBranchWithTeam(repoContext); + + var user = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + var restrictions = await _github.Repository.Branch.AddProtectedBranchUserRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, user); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + + var deleted = await _github.Repository.Branch.DeleteProtectedBranchUserRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, user); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } } } } -} +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index ec6252c0..ac926027 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -18,7 +18,7 @@ public class TeamsClientTests var teamName = Helper.MakeNameWithTimestamp("new-team"); var teamDescription = Helper.MakeNameWithTimestamp("team description"); - using (var context = await github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("org-repo")))) + using (var context = await github.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("org-repo")))) { var newTeam = new NewTeam(teamName) { @@ -295,7 +295,7 @@ public class TeamsClientTests { var github = Helper.GetAuthenticatedClient(); - using (var repositoryContext = await github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("teamrepo")))) + using (var repositoryContext = await github.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("teamrepo")))) { github.Organization.Team.AddRepository(_team.Id, Helper.Organization, repositoryContext.RepositoryName); @@ -320,7 +320,7 @@ public class TeamsClientTests public async Task CanAddRepository() { using (var teamContext = await _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team")))) - using (var repoContext = await _github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("team-repository")))) + using (var repoContext = await _github.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("team-repository")))) { var team = teamContext.Team; var repo = repoContext.Repository; diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index f005e0ff..455b8a7d 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -113,8 +113,13 @@ namespace Octokit.Tests.Integration } public static string UserName { get; private set; } + public static string Organization { get; private set; } + public static bool HasNoOrganization => Organization == null; + + public static bool HasOrganization => Organization != null; + /// /// These credentials should be set to a test GitHub account using the powershell script configure-integration-tests.ps1 /// diff --git a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs index 3c6b0f3f..a30f4e62 100644 --- a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs @@ -4,6 +4,17 @@ namespace Octokit.Tests.Integration.Helpers { internal static class GithubClientExtensions { + /// + /// Creates a public repository with the timestamped name public-repo + /// + internal static async Task CreateRepositoryContext(this IGitHubClient client) + { + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true }); + + return new RepositoryContext(client.Connection, repo); + } + internal static async Task CreateRepositoryContext(this IGitHubClient client, string repositoryName) { var repoName = Helper.MakeNameWithTimestamp(repositoryName); @@ -12,16 +23,30 @@ namespace Octokit.Tests.Integration.Helpers return new RepositoryContext(client.Connection, repo); } - internal static async Task CreateRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository) + internal static async Task CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository) { - var repo = await client.Repository.Create(organizationLogin, newRepository); + var repo = await client.Repository.Create(newRepository); return new RepositoryContext(client.Connection, repo); } - internal static async Task CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository) + /// + /// Creates an organisationrepository with the timestamped name organisation-repo + /// + internal static async Task CreateOrganizationRepositoryContext(this IGitHubClient client) { - var repo = await client.Repository.Create(newRepository); + var repoName = Helper.MakeNameWithTimestamp("organization-repo"); + var repo = await client.Repository.Create(Helper.Organization, new NewRepository(repoName) { AutoInit = true }); + + return new RepositoryContext(client.Connection, repo); + } + + /// + /// Creates an organization repository + /// + internal static async Task CreateOrganizationRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository) + { + var repo = await client.Repository.Create(organizationLogin, newRepository); return new RepositoryContext(client.Connection, repo); } diff --git a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs index c0e89ba7..df568cfe 100644 --- a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs +++ b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs @@ -23,13 +23,30 @@ namespace Octokit.Tests.Integration.Helpers internal static class RepositoryProtectedBranchHelperExtensions { + internal async static Task ProtectDefaultBranch(this IGitHubClient client, RepositoryContext repoContext) + { + // Protect default branch + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }), + new BranchProtectionRequiredReviewsUpdate(true, true, 3), + null, + true, + true, + true, + true, + false, + true); + + await client.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, update); + } + internal async static Task CreateRepositoryWithProtectedBranch(this IGitHubClient client) { // Create user owned repo var userRepo = new NewRepository(Helper.MakeNameWithTimestamp("protected-repo")) { AutoInit = true }; var contextUserRepo = await client.CreateRepositoryContext(userRepo); - // Protect master branch + // Protect default branch var update = new BranchProtectionSettingsUpdate( new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }), new BranchProtectionRequiredReviewsUpdate(true, true, 3), @@ -46,11 +63,34 @@ namespace Octokit.Tests.Integration.Helpers return contextUserRepo; } + internal async static Task ProtectDefaultBranchWithTeam(this IGitHubClient client, RepositoryContext repoContext) + { + // Create team in org + var team = await client.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team"))); + + // Grant team push access to repo + await client.Organization.Team.AddRepository( + team.TeamId, + repoContext.RepositoryOwner, + repoContext.RepositoryName, + new RepositoryPermissionRequest(Permission.Push)); + + // Protect default branch + var protection = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }), + new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(new BranchProtectionTeamCollection { team.TeamName }), true, true, 3), + new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { team.TeamName }), + true); + await client.Repository.Branch.UpdateBranchProtection(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, protection); + + return team; + } + internal async static Task CreateOrganizationRepositoryWithProtectedBranch(this IGitHubClient client) { // Create organization owned repo var orgRepo = new NewRepository(Helper.MakeNameWithTimestamp("protected-org-repo")) { AutoInit = true }; - var contextOrgRepo = await client.CreateRepositoryContext(Helper.Organization, orgRepo); + var contextOrgRepo = await client.CreateOrganizationRepositoryContext(Helper.Organization, orgRepo); // Create team in org var contextOrgTeam = await client.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team"))); @@ -62,13 +102,13 @@ namespace Octokit.Tests.Integration.Helpers contextOrgRepo.RepositoryName, new RepositoryPermissionRequest(Permission.Push)); - // Protect master branch + // Protect default branch var protection = new BranchProtectionSettingsUpdate( new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }), new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }), true, true, 3), new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }), true); - await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "master", protection); + await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "main", protection); return new OrganizationRepositoryWithTeamContext { diff --git a/Octokit.Tests.Integration/Helpers/OrganizationTestAttribute.cs b/Octokit.Tests.Integration/Helpers/OrganizationTestAttribute.cs index 2d886f07..817b2b7a 100644 --- a/Octokit.Tests.Integration/Helpers/OrganizationTestAttribute.cs +++ b/Octokit.Tests.Integration/Helpers/OrganizationTestAttribute.cs @@ -17,7 +17,7 @@ namespace Octokit.Tests.Integration public IEnumerable Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) { - if (Helper.Organization == null) + if (Helper.HasNoOrganization) { return Enumerable.Empty(); } diff --git a/Octokit.Tests.Integration/Helpers/ReferenceExtensionsTests.cs b/Octokit.Tests.Integration/Helpers/ReferenceExtensionsTests.cs index cba19977..3a7f9113 100644 --- a/Octokit.Tests.Integration/Helpers/ReferenceExtensionsTests.cs +++ b/Octokit.Tests.Integration/Helpers/ReferenceExtensionsTests.cs @@ -15,7 +15,7 @@ namespace Octokit.Tests.Integration.Helpers using (var context = await client.CreateRepositoryContext("public-repo")) { - var branchFromMaster = await fixture.CreateBranch(context.RepositoryOwner, context.RepositoryName, "patch-1"); + var branchFromMaster = await fixture.CreateBranch(context.RepositoryOwner, context.RepositoryName, "patch-1", context.Repository.DefaultBranch); var branchFromPath = await fixture.CreateBranch(context.RepositoryOwner, context.RepositoryName, "patch-2", branchFromMaster); diff --git a/Octokit.Tests.Integration/Helpers/RepositoryContext.cs b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs index 4d30f2b1..35f62931 100644 --- a/Octokit.Tests.Integration/Helpers/RepositoryContext.cs +++ b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs @@ -16,12 +16,14 @@ namespace Octokit.Tests.Integration.Helpers RepositoryId = repo.Id; RepositoryOwner = repo.Owner.Login; RepositoryName = repo.Name; + RepositoryDefaultBranch = repo.DefaultBranch; } private IConnection _connection; internal long RepositoryId { get; private set; } internal string RepositoryOwner { get; private set; } internal string RepositoryName { get; private set; } + internal string RepositoryDefaultBranch { get; private set; } internal Repository Repository { get; private set; } diff --git a/Octokit.Tests.Integration/Reactive/ObservableOrganizationOutsideCollaboratorsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableOrganizationOutsideCollaboratorsClientTests.cs index ab8d40ed..d3aca712 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableOrganizationOutsideCollaboratorsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableOrganizationOutsideCollaboratorsClientTests.cs @@ -34,7 +34,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsOutsideCollaborators() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); @@ -50,7 +50,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithoutStart() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); @@ -72,7 +72,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithStart() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -96,7 +96,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilter() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -113,7 +113,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterAndApiOptions() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -136,7 +136,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterWithStart() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -171,7 +171,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilter() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -189,7 +189,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilterAndApiOptions() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test2"); @@ -226,7 +226,7 @@ namespace Octokit.Tests.Integration.Reactive public async Task CanRemoveOutsideCollaborator() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName))) + using (var context = await _gitHub.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(repoName))) { await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator); diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryBranchesClientTests.cs index 2e49b7e3..808a8421 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryBranchesClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryBranchesClientTests.cs @@ -1,281 +1,262 @@ -using System; -using System.Linq; -using System.Reactive.Linq; +using System.Reactive.Linq; using System.Threading.Tasks; using Octokit.Reactive; using Octokit.Tests.Integration.Helpers; using Xunit; -namespace Octokit.Tests.Integration +namespace Octokit.Tests.Integration.Reactive { public class ObservableRepositoryBranchesClientTests { - public class TheGetBranchProtectionMethod : IDisposable + public class TheGetBranchProtectionMethod { + IGitHubClient _github; IObservableRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - OrganizationRepositoryWithTeamContext _orgRepoContext; public TheGetBranchProtectionMethod() { - var github = Helper.GetAuthenticatedClient(); - _client = new ObservableRepositoryBranchesClient(github); - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; + _github = Helper.GetAuthenticatedClient(); + _client = new ObservableRepositoryBranchesClient(_github); } [IntegrationTest] public async Task GetsBranchProtection() { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var protection = await _client.GetBranchProtection(repoOwner, repoName, "master"); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryOwner; + var repoName = context.RepositoryName; + var protection = await _client.GetBranchProtection(repoOwner, repoName, "main"); - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Null(protection.Restrictions); + Assert.Null(protection.Restrictions); - Assert.True(protection.EnforceAdmins.Enabled); + Assert.True(protection.EnforceAdmins.Enabled); + } } [IntegrationTest] public async Task GetsBranchProtectionWithRepositoryId() { - var repoId = _userRepoContext.RepositoryId; - var protection = await _client.GetBranchProtection(repoId, "master"); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryId; + var protection = await _client.GetBranchProtection(repoId, "main"); - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Null(protection.Restrictions); + Assert.Null(protection.Restrictions); - Assert.True(protection.EnforceAdmins.Enabled); + Assert.True(protection.EnforceAdmins.Enabled); + } } - [IntegrationTest] + [OrganizationTest] public async Task GetsBranchProtectionForOrgRepo() { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var protection = await _client.GetBranchProtection(repoOwner, repoName, "master"); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var protection = await _client.GetBranchProtection(repoOwner, repoName, "main"); - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Equal(1, protection.Restrictions.Teams.Count); - Assert.Equal(0, protection.Restrictions.Users.Count); + Assert.Equal(1, protection.Restrictions.Teams.Count); + Assert.Equal(0, protection.Restrictions.Users.Count); - Assert.True(protection.EnforceAdmins.Enabled); + Assert.True(protection.EnforceAdmins.Enabled); + } } - [IntegrationTest] + [OrganizationTest] public async Task GetsBranchProtectionForOrgRepoWithRepositoryId() { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var protection = await _client.GetBranchProtection(repoId, "master"); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var protection = await _client.GetBranchProtection(repoId, "main"); - Assert.True(protection.RequiredStatusChecks.Strict); - Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); + Assert.True(protection.RequiredStatusChecks.Strict); + Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count); - Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); - Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Equal(1, protection.RequiredPullRequestReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, protection.RequiredPullRequestReviews.DismissalRestrictions.Users.Count); + Assert.True(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(3, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Equal(1, protection.Restrictions.Teams.Count); - Assert.Equal(0, protection.Restrictions.Users.Count); + Assert.Equal(1, protection.Restrictions.Teams.Count); + Assert.Equal(0, protection.Restrictions.Users.Count); - Assert.True(protection.EnforceAdmins.Enabled); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); + Assert.True(protection.EnforceAdmins.Enabled); + } } } - public class TheUpdateBranchProtectionMethod : IDisposable + public class TheUpdateBranchProtectionMethod { + IGitHubClient _github; IObservableRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; public TheUpdateBranchProtectionMethod() { - var github = Helper.GetAuthenticatedClient(); - _client = new ObservableRepositoryBranchesClient(github); - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; + _github = Helper.GetAuthenticatedClient(); + _client = new ObservableRepositoryBranchesClient(_github); } [IntegrationTest] public async Task UpdatesBranchProtection() { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(false, true, 2), - false); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryOwner; + var repoName = context.RepositoryName; + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(false, true, 2), + false); - var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "main", update); + var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "main", update); - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Null(protection.Restrictions); + Assert.Null(protection.Restrictions); - Assert.False(protection.EnforceAdmins.Enabled); + Assert.False(protection.EnforceAdmins.Enabled); + } } [IntegrationTest] public async Task UpdatesBranchProtectionWithRepositoryId() { - var repoId = _userRepoContext.RepositoryId; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(false, true, 2), - false); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryId; + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(false, true, 2), + false); - var protection = await _client.UpdateBranchProtection(repoId, "main", update); + var protection = await _client.UpdateBranchProtection(repoId, "main", update); - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.True(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Null(protection.Restrictions); + Assert.Null(protection.Restrictions); - Assert.False(protection.EnforceAdmins.Enabled); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - } - } - - public class TheUpdateOrgBranchProtectionMethod : IDisposable - { - IObservableRepositoryBranchesClient _client; - OrganizationRepositoryWithTeamContext _orgRepoContext; - - public TheUpdateOrgBranchProtectionMethod() - { - var github = Helper.GetAuthenticatedClient(); - _client = new ObservableRepositoryBranchesClient(github); - - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; + Assert.False(protection.EnforceAdmins.Enabled); + } } [OrganizationTest] public async Task UpdatesBranchProtectionForOrgRepo() { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), - new BranchProtectionPushRestrictionsUpdate(), - false, - true, - true, - true, - true, - true); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), + new BranchProtectionPushRestrictionsUpdate(), + false, + true, + true, + true, + true, + true); - var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "main", update); + var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "main", update); - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Empty(protection.Restrictions.Teams); - Assert.Empty(protection.Restrictions.Users); + Assert.Empty(protection.Restrictions.Teams); + Assert.Empty(protection.Restrictions.Users); - Assert.False(protection.EnforceAdmins.Enabled); - Assert.True(protection.RequiredLinearHistory.Enabled); - Assert.True(protection.AllowForcePushes.Enabled); - Assert.True(protection.AllowDeletions.Enabled); - Assert.True(protection.BlockCreations.Enabled); - Assert.True(protection.RequiredConversationResolution.Enabled); + Assert.False(protection.EnforceAdmins.Enabled); + Assert.True(protection.RequiredLinearHistory.Enabled); + Assert.True(protection.AllowForcePushes.Enabled); + Assert.True(protection.AllowDeletions.Enabled); + Assert.True(protection.BlockCreations.Enabled); + Assert.True(protection.RequiredConversationResolution.Enabled); + } } [OrganizationTest] public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId() { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var update = new BranchProtectionSettingsUpdate( - new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), - new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), - new BranchProtectionPushRestrictionsUpdate(), - false, - true, - true, - true, - true, - true); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var update = new BranchProtectionSettingsUpdate( + new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }), + new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2), + new BranchProtectionPushRestrictionsUpdate(), + false, + true, + true, + true, + true, + true); - var protection = await _client.UpdateBranchProtection(repoId, "main", update); + var protection = await _client.UpdateBranchProtection(repoId, "main", update); - Assert.False(protection.RequiredStatusChecks.Strict); - Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); + Assert.False(protection.RequiredStatusChecks.Strict); + Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count); - Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); - Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); - Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); - Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); + Assert.Null(protection.RequiredPullRequestReviews.DismissalRestrictions); + Assert.False(protection.RequiredPullRequestReviews.DismissStaleReviews); + Assert.False(protection.RequiredPullRequestReviews.RequireCodeOwnerReviews); + Assert.Equal(2, protection.RequiredPullRequestReviews.RequiredApprovingReviewCount); - Assert.Empty(protection.Restrictions.Teams); - Assert.Empty(protection.Restrictions.Users); + Assert.Empty(protection.Restrictions.Teams); + Assert.Empty(protection.Restrictions.Users); - Assert.False(protection.EnforceAdmins.Enabled); - Assert.True(protection.RequiredLinearHistory.Enabled); - Assert.True(protection.AllowForcePushes.Enabled); - Assert.True(protection.AllowDeletions.Enabled); - Assert.True(protection.BlockCreations.Enabled); - Assert.True(protection.RequiredConversationResolution.Enabled); - } - - public void Dispose() - { - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); + Assert.False(protection.EnforceAdmins.Enabled); + Assert.True(protection.RequiredLinearHistory.Enabled); + Assert.True(protection.AllowForcePushes.Enabled); + Assert.True(protection.AllowDeletions.Enabled); + Assert.True(protection.BlockCreations.Enabled); + Assert.True(protection.RequiredConversationResolution.Enabled); + } } } @@ -297,7 +278,7 @@ namespace Octokit.Tests.Integration { var repoOwner = context.RepositoryOwner; var repoName = context.RepositoryName; - var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "master"); + var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "main"); Assert.True(deleted); } @@ -309,237 +290,241 @@ namespace Octokit.Tests.Integration using (var context = await _github.CreateRepositoryWithProtectedBranch()) { var repoId = context.RepositoryId; - var deleted = await _client.DeleteBranchProtection(repoId, "master"); + var deleted = await _client.DeleteBranchProtection(repoId, "main"); Assert.True(deleted); } } - [IntegrationTest] + [OrganizationTest] public async Task DeletesBranchProtectionForOrgRepo() { using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) { var repoOwner = context.RepositoryContext.RepositoryOwner; var repoName = context.RepositoryContext.RepositoryName; - var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "master"); + var deleted = await _client.DeleteBranchProtection(repoOwner, repoName, "main"); Assert.True(deleted); } } - [IntegrationTest] + [OrganizationTest] public async Task DeletesBranchProtectionForOrgRepoWithRepositoryId() { using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) { var repoId = context.RepositoryContext.RepositoryId; - var deleted = await _client.DeleteBranchProtection(repoId, "master"); + var deleted = await _client.DeleteBranchProtection(repoId, "main"); Assert.True(deleted); } } } - public class TheGetReviewEnforcementMethod : IDisposable + public class TheGetReviewEnforcementMethod { + IGitHubClient _github; IObservableRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - OrganizationRepositoryWithTeamContext _orgRepoContext; public TheGetReviewEnforcementMethod() { - var github = Helper.GetAuthenticatedClient(); - _client = new ObservableRepositoryBranchesClient(github); - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; + _github = Helper.GetAuthenticatedClient(); + _client = new ObservableRepositoryBranchesClient(_github); } [IntegrationTest] public async Task GetsReviewEnforcement() { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master"); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryOwner; + var repoName = context.RepositoryName; + var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "main"); - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } } [IntegrationTest] public async Task GetsReviewEnforcementWithRepositoryId() { - var repoId = _userRepoContext.RepositoryId; - var requiredReviews = await _client.GetReviewEnforcement(repoId, "master"); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryId; + var requiredReviews = await _client.GetReviewEnforcement(repoId, "main"); - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } } - [IntegrationTest] + [OrganizationTest] public async Task GetsReviewEnforcementForOrgRepo() { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "master"); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var requiredReviews = await _client.GetReviewEnforcement(repoOwner, repoName, "main"); - Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } } - [IntegrationTest] + [OrganizationTest] public async Task GetsReviewEnforcementForOrgRepoWithRepositoryId() { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var requiredReviews = await _client.GetReviewEnforcement(repoId, "master"); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var requiredReviews = await _client.GetReviewEnforcement(repoId, "main"); - Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); - Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); - Assert.True(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); + Assert.Equal(1, requiredReviews.DismissalRestrictions.Teams.Count); + Assert.Equal(0, requiredReviews.DismissalRestrictions.Users.Count); + Assert.True(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + } } } - public class TheUpdateReviewEnforcementMethod : IDisposable + public class TheUpdateReviewEnforcementMethod { + IGitHubClient _github; IObservableRepositoryBranchesClient _client; - RepositoryContext _userRepoContext; - OrganizationRepositoryWithTeamContext _orgRepoContext; public TheUpdateReviewEnforcementMethod() { - var github = Helper.GetAuthenticatedClient(); - _client = new ObservableRepositoryBranchesClient(github); - - _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; - _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; + _github = Helper.GetAuthenticatedClient(); + _client = new ObservableRepositoryBranchesClient(_github); } [IntegrationTest] public async Task UpdatesReviewEnforcement() { - var repoOwner = _userRepoContext.RepositoryOwner; - var repoName = _userRepoContext.RepositoryName; - var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryOwner; + var repoName = context.RepositoryName; + var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); - var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update); + var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "main", update); - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } } [IntegrationTest] public async Task UpdatesReviewEnforcementWithRepositoryId() { - var repoId = _userRepoContext.RepositoryId; - var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryId; + var update = new BranchProtectionRequiredReviewsUpdate(false, true, 2); - var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update); + var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "main", update); - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.True(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.True(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } } - [IntegrationTest] + [OrganizationTest] public async Task UpdatesReviewEnforcementForOrgRepo() { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), - false, - false, - 2); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), + false, + false, + 2); - var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update); + var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "main", update); - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } } - [IntegrationTest] + [OrganizationTest] public async Task UpdatesReviewEnforcementForOrgRepoWithRepositoryId() { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), - false, - false, - 2); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), + false, + false, + 2); - var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update); + var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "main", update); - Assert.Null(requiredReviews.DismissalRestrictions); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + Assert.Null(requiredReviews.DismissalRestrictions); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } } - [IntegrationTest] + [OrganizationTest] public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnly() { - var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; - var repoName = _orgRepoContext.RepositoryContext.RepositoryName; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), - false, - false, - 2); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), + false, + false, + 2); - var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "master", update); + var requiredReviews = await _client.UpdateReviewEnforcement(repoOwner, repoName, "main", update); - Assert.Empty(requiredReviews.DismissalRestrictions.Teams); - Assert.Empty(requiredReviews.DismissalRestrictions.Users); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Empty(requiredReviews.DismissalRestrictions.Teams); + Assert.Empty(requiredReviews.DismissalRestrictions.Users); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + } } - [IntegrationTest] + [OrganizationTest] public async Task UpdatesReviewEnforcementForOrgRepoWithAdminOnlyWithRepositoryId() { - var repoId = _orgRepoContext.RepositoryContext.RepositoryId; - var update = new BranchProtectionRequiredReviewsUpdate( - new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), - false, - false, - 2); + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var update = new BranchProtectionRequiredReviewsUpdate( + new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(true), + false, + false, + 2); - var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "master", update); + var requiredReviews = await _client.UpdateReviewEnforcement(repoId, "main", update); - Assert.Empty(requiredReviews.DismissalRestrictions.Teams); - Assert.Empty(requiredReviews.DismissalRestrictions.Users); - Assert.False(requiredReviews.DismissStaleReviews); - Assert.False(requiredReviews.RequireCodeOwnerReviews); - Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); - } - - public void Dispose() - { - if (_userRepoContext != null) - _userRepoContext.Dispose(); - - if (_orgRepoContext != null) - _orgRepoContext.Dispose(); + Assert.Empty(requiredReviews.DismissalRestrictions.Teams); + Assert.Empty(requiredReviews.DismissalRestrictions.Users); + Assert.False(requiredReviews.DismissStaleReviews); + Assert.False(requiredReviews.RequireCodeOwnerReviews); + Assert.Equal(2, requiredReviews.RequiredApprovingReviewCount); + } } } @@ -561,7 +546,7 @@ namespace Octokit.Tests.Integration { var repoOwner = context.RepositoryOwner; var repoName = context.RepositoryName; - var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master"); + var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "main"); Assert.True(deleted); } @@ -573,32 +558,32 @@ namespace Octokit.Tests.Integration using (var context = await _github.CreateRepositoryWithProtectedBranch()) { var repoId = context.RepositoryId; - var deleted = await _client.RemoveReviewEnforcement(repoId, "master"); + var deleted = await _client.RemoveReviewEnforcement(repoId, "main"); Assert.True(deleted); } } - [IntegrationTest] + [OrganizationTest] public async Task RemovesReviewEnforcementForOrgRepo() { using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) { var repoOwner = context.RepositoryContext.RepositoryOwner; var repoName = context.RepositoryContext.RepositoryName; - var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "master"); + var deleted = await _client.RemoveReviewEnforcement(repoOwner, repoName, "main"); Assert.True(deleted); } } - [IntegrationTest] + [OrganizationTest] public async Task RemovesReviewEnforcementForOrgRepoWithRepositoryId() { using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) { var repoId = context.RepositoryContext.RepositoryId; - var deleted = await _client.RemoveReviewEnforcement(repoId, "master"); + var deleted = await _client.RemoveReviewEnforcement(repoId, "main"); Assert.True(deleted); } diff --git a/Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs index 0e813365..87431a8f 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs @@ -254,7 +254,7 @@ public class ObservableTeamsClientTests var github = Helper.GetAuthenticatedClient(); var client = new ObservableTeamsClient(github); - using (var repositoryContext = await github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("teamrepo")))) + using (var repositoryContext = await github.CreateOrganizationRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("teamrepo")))) { client.AddRepository(_team.Id, Helper.Organization, repositoryContext.RepositoryName); diff --git a/Octokit.Tests.Integration/SelfTests.cs b/Octokit.Tests.Integration/SelfTests.cs index 418b512d..23b286e9 100644 --- a/Octokit.Tests.Integration/SelfTests.cs +++ b/Octokit.Tests.Integration/SelfTests.cs @@ -15,4 +15,14 @@ namespace Octokit.Tests.Integration Assert.Equal("", errors); } } + + public class GitHubClientTestBase + { + protected readonly IGitHubClient _github; + + public GitHubClientTestBase() + { + _github = Helper.GetAuthenticatedClient(); + } + } } diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index d2bb2bfd..90b22719 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -637,7 +637,7 @@ namespace Octokit.Tests.Clients { "payload", new { - @ref = "master", + @ref = GitHubConstants.DefaultBranchName, ref_type = "branch", } } @@ -648,7 +648,7 @@ namespace Octokit.Tests.Clients Assert.Equal(1, activities.Count); var payload = activities.FirstOrDefault().Payload as CreateEventPayload; - Assert.Equal("master", payload.Ref); + Assert.Equal(GitHubConstants.DefaultBranchName, payload.Ref); Assert.Equal(RefType.Branch, payload.RefType); } @@ -661,7 +661,7 @@ namespace Octokit.Tests.Clients { "payload", new { - @ref = "master", + @ref = GitHubConstants.DefaultBranchName, ref_type = "branch", } } @@ -672,7 +672,7 @@ namespace Octokit.Tests.Clients Assert.Equal(1, activities.Count); var payload = activities.FirstOrDefault().Payload as DeleteEventPayload; - Assert.Equal("master", payload.Ref); + Assert.Equal(GitHubConstants.DefaultBranchName, payload.Ref); Assert.Equal(RefType.Branch, payload.RefType); } @@ -955,7 +955,7 @@ namespace Octokit.Tests.Clients { new { - name = "master", + name = GitHubConstants.DefaultBranchName, commit = new { sha = "9049f1265b7d61be4a8904a9a27120d2064dab3b", diff --git a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs index 4f4ad442..1d6046aa 100644 --- a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs @@ -261,9 +261,9 @@ namespace Octokit.Tests.Clients connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); var contentsClient = new RepositoryContentsClient(connection); - var contents = await contentsClient.GetAllContentsByRef("fake", "repo", "readme.md", "master"); + var contents = await contentsClient.GetAllContentsByRef("fake", "repo", "readme.md", GitHubConstants.DefaultBranchName); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == $"repos/fake/repo/contents/readme.md?ref={GitHubConstants.DefaultBranchName}")); Assert.Equal(1, contents.Count); } @@ -276,9 +276,9 @@ namespace Octokit.Tests.Clients connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); var contentsClient = new RepositoryContentsClient(connection); - var contents = await contentsClient.GetAllContentsByRef(1, "readme.md", "master"); + var contents = await contentsClient.GetAllContentsByRef(1, "readme.md", GitHubConstants.DefaultBranchName); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/contents/readme.md?ref=master")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == $"repositories/1/contents/readme.md?ref={GitHubConstants.DefaultBranchName}")); Assert.Equal(1, contents.Count); } @@ -291,9 +291,9 @@ namespace Octokit.Tests.Clients connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); var contentsClient = new RepositoryContentsClient(connection); - var contents = await contentsClient.GetAllContentsByRef("fake", "repo", "master"); + var contents = await contentsClient.GetAllContentsByRef("fake", "repo", GitHubConstants.DefaultBranchName); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/?ref=master")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == $"repos/fake/repo/contents/?ref={GitHubConstants.DefaultBranchName}")); Assert.Equal(1, contents.Count); } @@ -306,9 +306,9 @@ namespace Octokit.Tests.Clients connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); var contentsClient = new RepositoryContentsClient(connection); - var contents = await contentsClient.GetAllContentsByRef(1, "master"); + var contents = await contentsClient.GetAllContentsByRef(1, GitHubConstants.DefaultBranchName); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/contents/?ref=master")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == $"repositories/1/contents/?ref={GitHubConstants.DefaultBranchName}")); Assert.Equal(1, contents.Count); } diff --git a/Octokit.Tests/Fixtures/release.json b/Octokit.Tests/Fixtures/release.json index 78847fed..3d0a1a2b 100644 --- a/Octokit.Tests/Fixtures/release.json +++ b/Octokit.Tests/Fixtures/release.json @@ -4,7 +4,7 @@ "upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name}", "id": 1, "tag_name": "v1.0.0", - "target_commitish": "master", + "target_commitish": "main", "name": "v1.0.0", "body": "Description of the release", "draft": false, diff --git a/Octokit.Tests/Fixtures/releases.json b/Octokit.Tests/Fixtures/releases.json index 36022092..07fbffc9 100644 --- a/Octokit.Tests/Fixtures/releases.json +++ b/Octokit.Tests/Fixtures/releases.json @@ -6,7 +6,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.18.0", "id": 16259, "tag_name": "v0.18.0", - "target_commitish": "master", + "target_commitish": "main", "name": "0.18.0", "body": "* Improve unshelve (#351)\r\n* Better support for running git-tfs in bare repositories (#353)\r\n* Use the saved author file for `rcheckin` (#366)\r\n* Add \"except\" to include an otherwise \"ignored\" file (#377)\r\n* Update libgit2sharp (#387)\r\n* Add a `--nofetch` option to the `branch` (#392) and `init-branch` (#379) commands\r\n* Reduce memory consumption during a fetch (#394)\r\n* Use only one workspace per fetch (rather than one workspace per changeset fetched) (#414)\r\n* Other fixes (#367, #376, #385, #389, #390, #397, #398, #400, #416)\r\n\r\n[Full diff](https://github.com/git-tfs/git-tfs/compare/v0.17.2...v0.18.0)", "draft": false, @@ -35,7 +35,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.12.1", "id": 10541, "tag_name": "v0.12.1", - "target_commitish": "master", + "target_commitish": "main", "name": "", "body": "- Fixed: 'TF14045: The identity MYDOMAIN\\John Doe is not a recognized identity' (#76, #81)\r\n- Fixed: exception on unshelve if some items was renamed (#77)\r\n- Fixed: rare problem when TFS' mixed mode assemblies cannot be loaded correctly (#93)\r\n- Some fixes for Unicode filenames and TFS usernames (#80)\r\n- git-tfs exit codes are now positive\r\n- git-tfs cleans up files if clone command resulted in exception (#94)\r\n- Restored VS2008 functionality (#99)", "draft": false, @@ -53,7 +53,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.14.0", "id": 10540, "tag_name": "v0.14.0", - "target_commitish": "master", + "target_commitish": "main", "name": "", "body": "- Fixed a bug in shelve (#133).\r\n- Fixed rename problem in checkintool (#148).\r\n- Fixed shelve -f (#157).\r\n- Fixed (or unfixed) case sensitivity (#159).\r\n- When a git subprocess exits with error, show the return/error code (#151).\r\n- Add support for VS11.", "draft": false, @@ -71,7 +71,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.15.0", "id": 10539, "tag_name": "v0.15.0", - "target_commitish": "master", + "target_commitish": "main", "name": "", "body": "- Use [libgit2sharp](https://github.com/libgit2/libgit2sharp).\r\n- Add default comment for shelves (#187)\r\n- Add support for files with international characters (#200)\r\n- Fix the mixed case problem (once and for all?) (#213)\r\n- Add support for authors file\r\n- Set up CI with [travis](http://travis-ci.org/git-tfs/git-tfs) and [teamcity](http://teamcity.codebetter.com/)", "draft": false, @@ -89,7 +89,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.17.2", "id": 277, "tag_name": "v0.17.2", - "target_commitish": "master", + "target_commitish": "main", "name": "0.17.2", "body": "* Use the git author as the TFS committer during `git tfs rcheckin` (#336) and `git tfs rcheckin --quick` (#357)\r\n* Improve temporary workspace handling (#328, #372)\r\n* Use libgit2sharp more and git-core less (#361)\r\n* Bug fix for bare repositories (#352)\r\n* Bug fix for crash during `git tfs clone` (#349)\r\n* Bug fix for VS2008 (#362)\r\n* Update libgit2sharp\r\n* Improved release process (#333, #340)\r\n\r\n[Full diff](https://github.com/git-tfs/git-tfs/compare/v0.17.1...v0.17.2)", "draft": false, @@ -118,7 +118,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.17.1", "id": 203, "tag_name": "v0.17.1", - "target_commitish": "master", + "target_commitish": "main", "name": "v0.17.1", "body": "- Fixed `git tfs clone` broken in some cases in 0.17 (#330)", "draft": false, @@ -147,7 +147,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.17.0", "id": 198, "tag_name": "v0.17.0", - "target_commitish": "master", + "target_commitish": "main", "name": "0.17.0", "body": "- [branch](commands/branch.md)\r\n- [labels](commands/labels.md) (#256)\r\n- git tfs pull --rebase (#254)\r\n- git tfs clone --with-branches (#255)\r\n- unicode support (#204)\r\n- Use a custom workspace (#266)\r\n- Clean workspaces directory (#269)\r\n- Add a note on the commit to keep trace of the workitems (#276)\r\n- Remove orphan folders (except in specific cases) (#323)", "draft": false, @@ -176,7 +176,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.16.0", "id": 171, "tag_name": "v0.16.0", - "target_commitish": "master", + "target_commitish": "main", "name": "0.16.0", "body": "- [init-branch](commands/init-branch.md)!! (#232)\r\n- Faster clone (#226) and quick-clone.\r\n- Add `git tfs info` (#219)\r\n- Better metadata processing during rcheckin: remove the flags (#237), ignore whitespace (#238), add `git-tfs-force:` reason (#219).\r\n- Always use CRLF in TFS checkin comments (#239)\r\n- Checkin notes (#245)\r\n- Use authors file more, and save it so you don't have to tell git-tfs about it every time you need it. (#252)", "draft": false, @@ -205,7 +205,7 @@ "html_url": "https://github.com/git-tfs/git-tfs/releases/v0.16.1", "id": 110, "tag_name": "v0.16.1", - "target_commitish": "master", + "target_commitish": "main", "name": "0.16.1", "body": "- Fixed `git tfs unshelve` (broken in 0.16.0) (#253).", "draft": false, diff --git a/Octokit.Tests/Fixtures/repositories.json b/Octokit.Tests/Fixtures/repositories.json index b6ffaa7c476ce0991f1a1108b1516fe2cad41809..986c5a3d387d15f6136a6ab4181f16c0d7afadd1 100644 GIT binary patch delta 22 ccmdne&9VWAZUiuAGUQDT6jt8M6u4;%0B2$dy8r+H delta 26 icmdnc&9bGNWy6gC_F{$-hE#^4$$`SkoBsuD+5!NIe+r=h diff --git a/Octokit.Tests/Fixtures/repository.json b/Octokit.Tests/Fixtures/repository.json index 44f352d78b6571944a9a96afff6192520fcbd558..44a88134290623187349f1c744825710ba0ef9dd 100644 GIT binary patch delta 16 XcmdlavQA{f8y4nFhP=(6S?pN>H$esQ delta 20 bcmZ1{vPopa8y5Crh7yKUhN8{yS?pN>P4NcU diff --git a/Octokit.Tests/GitHubConstants.cs b/Octokit.Tests/GitHubConstants.cs new file mode 100644 index 00000000..cce10958 --- /dev/null +++ b/Octokit.Tests/GitHubConstants.cs @@ -0,0 +1,7 @@ +namespace Octokit.Tests +{ + public class GitHubConstants + { + public const string DefaultBranchName = "main"; + } +} diff --git a/Octokit.Tests/Models/CheckRunEventTests.cs b/Octokit.Tests/Models/CheckRunEventTests.cs index 360a7238..c94f97ce 100644 --- a/Octokit.Tests/Models/CheckRunEventTests.cs +++ b/Octokit.Tests/Models/CheckRunEventTests.cs @@ -30,7 +30,7 @@ namespace Octokit.Tests.Models ""name"": ""randscape"", ""check_suite"": { ""id"": 5, - ""head_branch"": ""master"", + ""head_branch"": ""main"", ""head_sha"": ""d6fde92930d4715a2b49857d24b940956b26d2d3"", ""status"": ""completed"", ""conclusion"": ""neutral"", @@ -201,7 +201,7 @@ namespace Octokit.Tests.Models ""forks"": 0, ""open_issues"": 3, ""watchers"": 0, - ""default_branch"": ""master"" + ""default_branch"": ""main"" }, ""organization"": { ""login"": ""github"", diff --git a/Octokit.Tests/Models/CheckSuiteEventTests.cs b/Octokit.Tests/Models/CheckSuiteEventTests.cs index cccfa914..45da12ea 100644 --- a/Octokit.Tests/Models/CheckSuiteEventTests.cs +++ b/Octokit.Tests/Models/CheckSuiteEventTests.cs @@ -8,7 +8,7 @@ namespace Octokit.Tests.Models [Fact] public void CanBeDeserialized() { - const string json = "{\r\n \"action\": \"rerequested\",\r\n \"check_suite\": {\r\n \"id\": 276096,\r\n \"head_branch\": null,\r\n \"head_sha\": \"73955d02043135d48809add98052c2170522158f\",\r\n \"status\": \"queued\",\r\n \"conclusion\": null,\r\n \"url\": \"https://api.github.com/repos/tgstation/tgstation/check-suites/276096\",\r\n \"before\": null,\r\n \"after\": null,\r\n \"pull_requests\": [\r\n\r\n ],\r\n \"app\": {\r\n \"id\": 9880,\r\n \"owner\": {\r\n \"login\": \"Cyberboss\",\r\n \"id\": 8171642,\r\n \"avatar_url\": \"https://avatars3.githubusercontent.com/u/8171642?v=4\",\r\n \"gravatar_id\": \"\",\r\n \"url\": \"https://api.github.com/users/Cyberboss\",\r\n \"html_url\": \"https://github.com/Cyberboss\",\r\n \"followers_url\": \"https://api.github.com/users/Cyberboss/followers\",\r\n \"following_url\": \"https://api.github.com/users/Cyberboss/following{/other_user}\",\r\n \"gists_url\": \"https://api.github.com/users/Cyberboss/gists{/gist_id}\",\r\n \"starred_url\": \"https://api.github.com/users/Cyberboss/starred{/owner}{/repo}\",\r\n \"subscriptions_url\": \"https://api.github.com/users/Cyberboss/subscriptions\",\r\n \"organizations_url\": \"https://api.github.com/users/Cyberboss/orgs\",\r\n \"repos_url\": \"https://api.github.com/users/Cyberboss/repos\",\r\n \"events_url\": \"https://api.github.com/users/Cyberboss/events{/privacy}\",\r\n \"received_events_url\": \"https://api.github.com/users/Cyberboss/received_events\",\r\n \"type\": \"User\",\r\n \"site_admin\": false\r\n },\r\n \"name\": \"MapDiffBot\",\r\n \"description\": \"Creates diff images of BYOND .dmm maps\",\r\n \"external_url\": \"https://github.com/MapDiffBot/MapDiffBot\",\r\n \"html_url\": \"https://github.com/apps/mapdiffbot\",\r\n \"created_at\": 1520618356,\r\n \"updated_at\": 1521225691\r\n },\r\n \"created_at\": \"2018-05-11T05:42:21Z\",\r\n \"updated_at\": \"2018-05-11T13:45:34Z\",\r\n \"unique_check_runs_count\": 1,\r\n \"check_runs_url\": \"https://api.github.com/repos/tgstation/tgstation/check-suites/276096/check-runs\",\r\n \"head_commit\": {\r\n \"id\": \"73955d02043135d48809add98052c2170522158f\",\r\n \"tree_id\": \"ef367b2a31c69d095c45e1b357afb9c78c4b6631\",\r\n \"message\": \"Remove a duplicate pipe in MetaStation maint\",\r\n \"timestamp\": \"2018-05-07T22:36:13-07:00\",\r\n \"author\": {\r\n \"name\": \"Tad Hardesty\",\r\n \"email\": \"tad@platymuus.com\"\r\n },\r\n \"committer\": {\r\n \"name\": \"Tad Hardesty\",\r\n \"email\": \"tad@platymuus.com\"\r\n }\r\n }\r\n },\r\n \"repository\": {\r\n \"id\": 3234987,\r\n \"name\": \"tgstation\",\r\n \"full_name\": \"tgstation/tgstation\",\r\n \"owner\": {\r\n \"login\": \"tgstation\",\r\n \"id\": 1363778,\r\n \"avatar_url\": \"https://avatars2.githubusercontent.com/u/1363778?v=4\",\r\n \"gravatar_id\": \"\",\r\n \"url\": \"https://api.github.com/users/tgstation\",\r\n \"html_url\": \"https://github.com/tgstation\",\r\n \"followers_url\": \"https://api.github.com/users/tgstation/followers\",\r\n \"following_url\": \"https://api.github.com/users/tgstation/following{/other_user}\",\r\n \"gists_url\": \"https://api.github.com/users/tgstation/gists{/gist_id}\",\r\n \"starred_url\": \"https://api.github.com/users/tgstation/starred{/owner}{/repo}\",\r\n \"subscriptions_url\": \"https://api.github.com/users/tgstation/subscriptions\",\r\n \"organizations_url\": \"https://api.github.com/users/tgstation/orgs\",\r\n \"repos_url\": \"https://api.github.com/users/tgstation/repos\",\r\n \"events_url\": \"https://api.github.com/users/tgstation/events{/privacy}\",\r\n \"received_events_url\": \"https://api.github.com/users/tgstation/received_events\",\r\n \"type\": \"Organization\",\r\n \"site_admin\": false\r\n },\r\n \"private\": false,\r\n \"html_url\": \"https://github.com/tgstation/tgstation\",\r\n \"description\": \"the /tg/station branch of SS13\",\r\n \"fork\": false,\r\n \"url\": \"https://api.github.com/repos/tgstation/tgstation\",\r\n \"forks_url\": \"https://api.github.com/repos/tgstation/tgstation/forks\",\r\n \"keys_url\": \"https://api.github.com/repos/tgstation/tgstation/keys{/key_id}\",\r\n \"collaborators_url\": \"https://api.github.com/repos/tgstation/tgstation/collaborators{/collaborator}\",\r\n \"teams_url\": \"https://api.github.com/repos/tgstation/tgstation/teams\",\r\n \"hooks_url\": \"https://api.github.com/repos/tgstation/tgstation/hooks\",\r\n \"issue_events_url\": \"https://api.github.com/repos/tgstation/tgstation/issues/events{/number}\",\r\n \"events_url\": \"https://api.github.com/repos/tgstation/tgstation/events\",\r\n \"assignees_url\": \"https://api.github.com/repos/tgstation/tgstation/assignees{/user}\",\r\n \"branches_url\": \"https://api.github.com/repos/tgstation/tgstation/branches{/branch}\",\r\n \"tags_url\": \"https://api.github.com/repos/tgstation/tgstation/tags\",\r\n \"blobs_url\": \"https://api.github.com/repos/tgstation/tgstation/git/blobs{/sha}\",\r\n \"git_tags_url\": \"https://api.github.com/repos/tgstation/tgstation/git/tags{/sha}\",\r\n \"git_refs_url\": \"https://api.github.com/repos/tgstation/tgstation/git/refs{/sha}\",\r\n \"trees_url\": \"https://api.github.com/repos/tgstation/tgstation/git/trees{/sha}\",\r\n \"statuses_url\": \"https://api.github.com/repos/tgstation/tgstation/statuses/{sha}\",\r\n \"languages_url\": \"https://api.github.com/repos/tgstation/tgstation/languages\",\r\n \"stargazers_url\": \"https://api.github.com/repos/tgstation/tgstation/stargazers\",\r\n \"contributors_url\": \"https://api.github.com/repos/tgstation/tgstation/contributors\",\r\n \"subscribers_url\": \"https://api.github.com/repos/tgstation/tgstation/subscribers\",\r\n \"subscription_url\": \"https://api.github.com/repos/tgstation/tgstation/subscription\",\r\n \"commits_url\": \"https://api.github.com/repos/tgstation/tgstation/commits{/sha}\",\r\n \"git_commits_url\": \"https://api.github.com/repos/tgstation/tgstation/git/commits{/sha}\",\r\n \"comments_url\": \"https://api.github.com/repos/tgstation/tgstation/comments{/number}\",\r\n \"issue_comment_url\": \"https://api.github.com/repos/tgstation/tgstation/issues/comments{/number}\",\r\n \"contents_url\": \"https://api.github.com/repos/tgstation/tgstation/contents/{+path}\",\r\n \"compare_url\": \"https://api.github.com/repos/tgstation/tgstation/compare/{base}...{head}\",\r\n \"merges_url\": \"https://api.github.com/repos/tgstation/tgstation/merges\",\r\n \"archive_url\": \"https://api.github.com/repos/tgstation/tgstation/{archive_format}{/ref}\",\r\n \"downloads_url\": \"https://api.github.com/repos/tgstation/tgstation/downloads\",\r\n \"issues_url\": \"https://api.github.com/repos/tgstation/tgstation/issues{/number}\",\r\n \"pulls_url\": \"https://api.github.com/repos/tgstation/tgstation/pulls{/number}\",\r\n \"milestones_url\": \"https://api.github.com/repos/tgstation/tgstation/milestones{/number}\",\r\n \"notifications_url\": \"https://api.github.com/repos/tgstation/tgstation/notifications{?since,all,participating}\",\r\n \"labels_url\": \"https://api.github.com/repos/tgstation/tgstation/labels{/name}\",\r\n \"releases_url\": \"https://api.github.com/repos/tgstation/tgstation/releases{/id}\",\r\n \"deployments_url\": \"https://api.github.com/repos/tgstation/tgstation/deployments\",\r\n \"created_at\": \"2012-01-21T17:32:47Z\",\r\n \"updated_at\": \"2018-05-11T06:24:11Z\",\r\n \"pushed_at\": \"2018-05-11T12:11:58Z\",\r\n \"git_url\": \"git://github.com/tgstation/tgstation.git\",\r\n \"ssh_url\": \"git@github.com:tgstation/tgstation.git\",\r\n \"clone_url\": \"https://github.com/tgstation/tgstation.git\",\r\n \"svn_url\": \"https://github.com/tgstation/tgstation\",\r\n \"homepage\": \"https://www.tgstation13.org/\",\r\n \"size\": 1126165,\r\n \"stargazers_count\": 515,\r\n \"watchers_count\": 515,\r\n \"language\": \"DM\",\r\n \"has_issues\": true,\r\n \"has_projects\": true,\r\n \"has_downloads\": true,\r\n \"has_wiki\": true,\r\n \"has_pages\": false,\r\n \"forks_count\": 1783,\r\n \"mirror_url\": null,\r\n \"archived\": false,\r\n \"open_issues_count\": 1211,\r\n \"license\": {\r\n \"key\": \"agpl-3.0\",\r\n \"name\": \"GNU Affero General Public License v3.0\",\r\n \"spdx_id\": \"AGPL-3.0\",\r\n \"url\": \"https://api.github.com/licenses/agpl-3.0\"\r\n },\r\n \"forks\": 1783,\r\n \"open_issues\": 1211,\r\n \"watchers\": 515,\r\n \"default_branch\": \"master\"\r\n },\r\n \"organization\": {\r\n \"login\": \"tgstation\",\r\n \"id\": 1363778,\r\n \"url\": \"https://api.github.com/orgs/tgstation\",\r\n \"repos_url\": \"https://api.github.com/orgs/tgstation/repos\",\r\n \"events_url\": \"https://api.github.com/orgs/tgstation/events\",\r\n \"hooks_url\": \"https://api.github.com/orgs/tgstation/hooks\",\r\n \"issues_url\": \"https://api.github.com/orgs/tgstation/issues\",\r\n \"members_url\": \"https://api.github.com/orgs/tgstation/members{/member}\",\r\n \"public_members_url\": \"https://api.github.com/orgs/tgstation/public_members{/member}\",\r\n \"avatar_url\": \"https://avatars2.githubusercontent.com/u/1363778?v=4\",\r\n \"description\": \"\"\r\n },\r\n \"sender\": {\r\n \"login\": \"Cyberboss\",\r\n \"id\": 8171642,\r\n \"avatar_url\": \"https://avatars3.githubusercontent.com/u/8171642?v=4\",\r\n \"gravatar_id\": \"\",\r\n \"url\": \"https://api.github.com/users/Cyberboss\",\r\n \"html_url\": \"https://github.com/Cyberboss\",\r\n \"followers_url\": \"https://api.github.com/users/Cyberboss/followers\",\r\n \"following_url\": \"https://api.github.com/users/Cyberboss/following{/other_user}\",\r\n \"gists_url\": \"https://api.github.com/users/Cyberboss/gists{/gist_id}\",\r\n \"starred_url\": \"https://api.github.com/users/Cyberboss/starred{/owner}{/repo}\",\r\n \"subscriptions_url\": \"https://api.github.com/users/Cyberboss/subscriptions\",\r\n \"organizations_url\": \"https://api.github.com/users/Cyberboss/orgs\",\r\n \"repos_url\": \"https://api.github.com/users/Cyberboss/repos\",\r\n \"events_url\": \"https://api.github.com/users/Cyberboss/events{/privacy}\",\r\n \"received_events_url\": \"https://api.github.com/users/Cyberboss/received_events\",\r\n \"type\": \"User\",\r\n \"site_admin\": false\r\n },\r\n \"installation\": {\r\n \"id\": 103621\r\n }\r\n}"; + const string json = "{\r\n \"action\": \"rerequested\",\r\n \"check_suite\": {\r\n \"id\": 276096,\r\n \"head_branch\": null,\r\n \"head_sha\": \"73955d02043135d48809add98052c2170522158f\",\r\n \"status\": \"queued\",\r\n \"conclusion\": null,\r\n \"url\": \"https://api.github.com/repos/tgstation/tgstation/check-suites/276096\",\r\n \"before\": null,\r\n \"after\": null,\r\n \"pull_requests\": [\r\n\r\n ],\r\n \"app\": {\r\n \"id\": 9880,\r\n \"owner\": {\r\n \"login\": \"Cyberboss\",\r\n \"id\": 8171642,\r\n \"avatar_url\": \"https://avatars3.githubusercontent.com/u/8171642?v=4\",\r\n \"gravatar_id\": \"\",\r\n \"url\": \"https://api.github.com/users/Cyberboss\",\r\n \"html_url\": \"https://github.com/Cyberboss\",\r\n \"followers_url\": \"https://api.github.com/users/Cyberboss/followers\",\r\n \"following_url\": \"https://api.github.com/users/Cyberboss/following{/other_user}\",\r\n \"gists_url\": \"https://api.github.com/users/Cyberboss/gists{/gist_id}\",\r\n \"starred_url\": \"https://api.github.com/users/Cyberboss/starred{/owner}{/repo}\",\r\n \"subscriptions_url\": \"https://api.github.com/users/Cyberboss/subscriptions\",\r\n \"organizations_url\": \"https://api.github.com/users/Cyberboss/orgs\",\r\n \"repos_url\": \"https://api.github.com/users/Cyberboss/repos\",\r\n \"events_url\": \"https://api.github.com/users/Cyberboss/events{/privacy}\",\r\n \"received_events_url\": \"https://api.github.com/users/Cyberboss/received_events\",\r\n \"type\": \"User\",\r\n \"site_admin\": false\r\n },\r\n \"name\": \"MapDiffBot\",\r\n \"description\": \"Creates diff images of BYOND .dmm maps\",\r\n \"external_url\": \"https://github.com/MapDiffBot/MapDiffBot\",\r\n \"html_url\": \"https://github.com/apps/mapdiffbot\",\r\n \"created_at\": 1520618356,\r\n \"updated_at\": 1521225691\r\n },\r\n \"created_at\": \"2018-05-11T05:42:21Z\",\r\n \"updated_at\": \"2018-05-11T13:45:34Z\",\r\n \"unique_check_runs_count\": 1,\r\n \"check_runs_url\": \"https://api.github.com/repos/tgstation/tgstation/check-suites/276096/check-runs\",\r\n \"head_commit\": {\r\n \"id\": \"73955d02043135d48809add98052c2170522158f\",\r\n \"tree_id\": \"ef367b2a31c69d095c45e1b357afb9c78c4b6631\",\r\n \"message\": \"Remove a duplicate pipe in MetaStation maint\",\r\n \"timestamp\": \"2018-05-07T22:36:13-07:00\",\r\n \"author\": {\r\n \"name\": \"Tad Hardesty\",\r\n \"email\": \"tad@platymuus.com\"\r\n },\r\n \"committer\": {\r\n \"name\": \"Tad Hardesty\",\r\n \"email\": \"tad@platymuus.com\"\r\n }\r\n }\r\n },\r\n \"repository\": {\r\n \"id\": 3234987,\r\n \"name\": \"tgstation\",\r\n \"full_name\": \"tgstation/tgstation\",\r\n \"owner\": {\r\n \"login\": \"tgstation\",\r\n \"id\": 1363778,\r\n \"avatar_url\": \"https://avatars2.githubusercontent.com/u/1363778?v=4\",\r\n \"gravatar_id\": \"\",\r\n \"url\": \"https://api.github.com/users/tgstation\",\r\n \"html_url\": \"https://github.com/tgstation\",\r\n \"followers_url\": \"https://api.github.com/users/tgstation/followers\",\r\n \"following_url\": \"https://api.github.com/users/tgstation/following{/other_user}\",\r\n \"gists_url\": \"https://api.github.com/users/tgstation/gists{/gist_id}\",\r\n \"starred_url\": \"https://api.github.com/users/tgstation/starred{/owner}{/repo}\",\r\n \"subscriptions_url\": \"https://api.github.com/users/tgstation/subscriptions\",\r\n \"organizations_url\": \"https://api.github.com/users/tgstation/orgs\",\r\n \"repos_url\": \"https://api.github.com/users/tgstation/repos\",\r\n \"events_url\": \"https://api.github.com/users/tgstation/events{/privacy}\",\r\n \"received_events_url\": \"https://api.github.com/users/tgstation/received_events\",\r\n \"type\": \"Organization\",\r\n \"site_admin\": false\r\n },\r\n \"private\": false,\r\n \"html_url\": \"https://github.com/tgstation/tgstation\",\r\n \"description\": \"the /tg/station branch of SS13\",\r\n \"fork\": false,\r\n \"url\": \"https://api.github.com/repos/tgstation/tgstation\",\r\n \"forks_url\": \"https://api.github.com/repos/tgstation/tgstation/forks\",\r\n \"keys_url\": \"https://api.github.com/repos/tgstation/tgstation/keys{/key_id}\",\r\n \"collaborators_url\": \"https://api.github.com/repos/tgstation/tgstation/collaborators{/collaborator}\",\r\n \"teams_url\": \"https://api.github.com/repos/tgstation/tgstation/teams\",\r\n \"hooks_url\": \"https://api.github.com/repos/tgstation/tgstation/hooks\",\r\n \"issue_events_url\": \"https://api.github.com/repos/tgstation/tgstation/issues/events{/number}\",\r\n \"events_url\": \"https://api.github.com/repos/tgstation/tgstation/events\",\r\n \"assignees_url\": \"https://api.github.com/repos/tgstation/tgstation/assignees{/user}\",\r\n \"branches_url\": \"https://api.github.com/repos/tgstation/tgstation/branches{/branch}\",\r\n \"tags_url\": \"https://api.github.com/repos/tgstation/tgstation/tags\",\r\n \"blobs_url\": \"https://api.github.com/repos/tgstation/tgstation/git/blobs{/sha}\",\r\n \"git_tags_url\": \"https://api.github.com/repos/tgstation/tgstation/git/tags{/sha}\",\r\n \"git_refs_url\": \"https://api.github.com/repos/tgstation/tgstation/git/refs{/sha}\",\r\n \"trees_url\": \"https://api.github.com/repos/tgstation/tgstation/git/trees{/sha}\",\r\n \"statuses_url\": \"https://api.github.com/repos/tgstation/tgstation/statuses/{sha}\",\r\n \"languages_url\": \"https://api.github.com/repos/tgstation/tgstation/languages\",\r\n \"stargazers_url\": \"https://api.github.com/repos/tgstation/tgstation/stargazers\",\r\n \"contributors_url\": \"https://api.github.com/repos/tgstation/tgstation/contributors\",\r\n \"subscribers_url\": \"https://api.github.com/repos/tgstation/tgstation/subscribers\",\r\n \"subscription_url\": \"https://api.github.com/repos/tgstation/tgstation/subscription\",\r\n \"commits_url\": \"https://api.github.com/repos/tgstation/tgstation/commits{/sha}\",\r\n \"git_commits_url\": \"https://api.github.com/repos/tgstation/tgstation/git/commits{/sha}\",\r\n \"comments_url\": \"https://api.github.com/repos/tgstation/tgstation/comments{/number}\",\r\n \"issue_comment_url\": \"https://api.github.com/repos/tgstation/tgstation/issues/comments{/number}\",\r\n \"contents_url\": \"https://api.github.com/repos/tgstation/tgstation/contents/{+path}\",\r\n \"compare_url\": \"https://api.github.com/repos/tgstation/tgstation/compare/{base}...{head}\",\r\n \"merges_url\": \"https://api.github.com/repos/tgstation/tgstation/merges\",\r\n \"archive_url\": \"https://api.github.com/repos/tgstation/tgstation/{archive_format}{/ref}\",\r\n \"downloads_url\": \"https://api.github.com/repos/tgstation/tgstation/downloads\",\r\n \"issues_url\": \"https://api.github.com/repos/tgstation/tgstation/issues{/number}\",\r\n \"pulls_url\": \"https://api.github.com/repos/tgstation/tgstation/pulls{/number}\",\r\n \"milestones_url\": \"https://api.github.com/repos/tgstation/tgstation/milestones{/number}\",\r\n \"notifications_url\": \"https://api.github.com/repos/tgstation/tgstation/notifications{?since,all,participating}\",\r\n \"labels_url\": \"https://api.github.com/repos/tgstation/tgstation/labels{/name}\",\r\n \"releases_url\": \"https://api.github.com/repos/tgstation/tgstation/releases{/id}\",\r\n \"deployments_url\": \"https://api.github.com/repos/tgstation/tgstation/deployments\",\r\n \"created_at\": \"2012-01-21T17:32:47Z\",\r\n \"updated_at\": \"2018-05-11T06:24:11Z\",\r\n \"pushed_at\": \"2018-05-11T12:11:58Z\",\r\n \"git_url\": \"git://github.com/tgstation/tgstation.git\",\r\n \"ssh_url\": \"git@github.com:tgstation/tgstation.git\",\r\n \"clone_url\": \"https://github.com/tgstation/tgstation.git\",\r\n \"svn_url\": \"https://github.com/tgstation/tgstation\",\r\n \"homepage\": \"https://www.tgstation13.org/\",\r\n \"size\": 1126165,\r\n \"stargazers_count\": 515,\r\n \"watchers_count\": 515,\r\n \"language\": \"DM\",\r\n \"has_issues\": true,\r\n \"has_projects\": true,\r\n \"has_downloads\": true,\r\n \"has_wiki\": true,\r\n \"has_pages\": false,\r\n \"forks_count\": 1783,\r\n \"mirror_url\": null,\r\n \"archived\": false,\r\n \"open_issues_count\": 1211,\r\n \"license\": {\r\n \"key\": \"agpl-3.0\",\r\n \"name\": \"GNU Affero General Public License v3.0\",\r\n \"spdx_id\": \"AGPL-3.0\",\r\n \"url\": \"https://api.github.com/licenses/agpl-3.0\"\r\n },\r\n \"forks\": 1783,\r\n \"open_issues\": 1211,\r\n \"watchers\": 515,\r\n \"default_branch\": \"main\"\r\n },\r\n \"organization\": {\r\n \"login\": \"tgstation\",\r\n \"id\": 1363778,\r\n \"url\": \"https://api.github.com/orgs/tgstation\",\r\n \"repos_url\": \"https://api.github.com/orgs/tgstation/repos\",\r\n \"events_url\": \"https://api.github.com/orgs/tgstation/events\",\r\n \"hooks_url\": \"https://api.github.com/orgs/tgstation/hooks\",\r\n \"issues_url\": \"https://api.github.com/orgs/tgstation/issues\",\r\n \"members_url\": \"https://api.github.com/orgs/tgstation/members{/member}\",\r\n \"public_members_url\": \"https://api.github.com/orgs/tgstation/public_members{/member}\",\r\n \"avatar_url\": \"https://avatars2.githubusercontent.com/u/1363778?v=4\",\r\n \"description\": \"\"\r\n },\r\n \"sender\": {\r\n \"login\": \"Cyberboss\",\r\n \"id\": 8171642,\r\n \"avatar_url\": \"https://avatars3.githubusercontent.com/u/8171642?v=4\",\r\n \"gravatar_id\": \"\",\r\n \"url\": \"https://api.github.com/users/Cyberboss\",\r\n \"html_url\": \"https://github.com/Cyberboss\",\r\n \"followers_url\": \"https://api.github.com/users/Cyberboss/followers\",\r\n \"following_url\": \"https://api.github.com/users/Cyberboss/following{/other_user}\",\r\n \"gists_url\": \"https://api.github.com/users/Cyberboss/gists{/gist_id}\",\r\n \"starred_url\": \"https://api.github.com/users/Cyberboss/starred{/owner}{/repo}\",\r\n \"subscriptions_url\": \"https://api.github.com/users/Cyberboss/subscriptions\",\r\n \"organizations_url\": \"https://api.github.com/users/Cyberboss/orgs\",\r\n \"repos_url\": \"https://api.github.com/users/Cyberboss/repos\",\r\n \"events_url\": \"https://api.github.com/users/Cyberboss/events{/privacy}\",\r\n \"received_events_url\": \"https://api.github.com/users/Cyberboss/received_events\",\r\n \"type\": \"User\",\r\n \"site_admin\": false\r\n },\r\n \"installation\": {\r\n \"id\": 103621\r\n }\r\n}"; var serializer = new SimpleJsonSerializer(); diff --git a/Octokit.Tests/Models/MigrationTests.cs b/Octokit.Tests/Models/MigrationTests.cs index c4765a35..0f54c916 100644 --- a/Octokit.Tests/Models/MigrationTests.cs +++ b/Octokit.Tests/Models/MigrationTests.cs @@ -92,7 +92,7 @@ namespace Octokit.Tests.Models ""stargazers_count"": 80, ""watchers_count"": 80, ""size"": 108, - ""default_branch"": ""master"", + ""default_branch"": ""main"", ""open_issues_count"": 0, ""has_issues"": true, ""has_wiki"": true, diff --git a/Octokit.Tests/Models/SearchRepositoryResultTests.cs b/Octokit.Tests/Models/SearchRepositoryResultTests.cs index d7b1a259..e609b004 100644 --- a/Octokit.Tests/Models/SearchRepositoryResultTests.cs +++ b/Octokit.Tests/Models/SearchRepositoryResultTests.cs @@ -39,8 +39,8 @@ public class SearchRepositoryResultTests ""language"": ""Assembly"", ""forks_count"": 0, ""open_issues_count"": 0, - ""master_branch"": ""master"", - ""default_branch"": ""master"", + ""master_branch"": ""main"", + ""default_branch"": ""main"", ""score"": 10.309712 } ] diff --git a/Octokit.Tests/Reactive/ObservableRepositoryContentsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryContentsClientTests.cs index adf1186d..400387eb 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryContentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryContentsClientTests.cs @@ -312,9 +312,9 @@ namespace Octokit.Tests.Reactive connection.Get>(Args.Uri, null, null) .Returns(Task.FromResult(response)); - var contents = await contentsClient.GetAllContentsByRef("fake", "repo", "master", "readme.md").ToList(); + var contents = await contentsClient.GetAllContentsByRef("fake", "repo", GitHubConstants.DefaultBranchName, "readme.md").ToList(); - connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master"), null, null); + connection.Received().Get>(Arg.Is(u => u.ToString() == $"repos/fake/repo/contents/readme.md?ref={GitHubConstants.DefaultBranchName}"), null, null); Assert.Equal(1, contents.Count); } @@ -330,9 +330,9 @@ namespace Octokit.Tests.Reactive connection.Get>(Args.Uri, null, null) .Returns(Task.FromResult(response)); - var contents = await contentsClient.GetAllContentsByRef(1, "master", "readme.md").ToList(); + var contents = await contentsClient.GetAllContentsByRef(1, GitHubConstants.DefaultBranchName, "readme.md").ToList(); - connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/contents/readme.md?ref=master"), null, null); + connection.Received().Get>(Arg.Is(u => u.ToString() == $"repositories/1/contents/readme.md?ref={GitHubConstants.DefaultBranchName}"), null, null); Assert.Equal(1, contents.Count); } @@ -348,9 +348,9 @@ namespace Octokit.Tests.Reactive connection.Get>(Args.Uri, null, null) .Returns(Task.FromResult(response)); - var contents = await contentsClient.GetAllContentsByRef("fake", "repo", "master").ToList(); + var contents = await contentsClient.GetAllContentsByRef("fake", "repo", GitHubConstants.DefaultBranchName).ToList(); - connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/?ref=master"), null, null); + connection.Received().Get>(Arg.Is(u => u.ToString() == $"repos/fake/repo/contents/?ref={GitHubConstants.DefaultBranchName}"), null, null); Assert.Equal(1, contents.Count); } @@ -366,9 +366,9 @@ namespace Octokit.Tests.Reactive connection.Get>(Args.Uri, null, null) .Returns(Task.FromResult(response)); - var contents = await contentsClient.GetAllContentsByRef(1, "master").ToList(); + var contents = await contentsClient.GetAllContentsByRef(1, GitHubConstants.DefaultBranchName).ToList(); - connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/contents/?ref=master"), null, null); + connection.Received().Get>(Arg.Is(u => u.ToString() == $"repositories/1/contents/?ref={GitHubConstants.DefaultBranchName}"), null, null); Assert.Equal(1, contents.Count); } diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index 23369c07..8a77dcd3 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -23,9 +23,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] @@ -41,9 +41,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] @@ -104,9 +104,9 @@ namespace Octokit /// The sub-namespace to get references for /// /// The subNamespace parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task> GetAllForSubNamespace(string owner, string name, string subNamespace); @@ -122,9 +122,9 @@ namespace Octokit /// Options for changing the API response /// /// The subNamespace parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task> GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options); @@ -138,9 +138,9 @@ namespace Octokit /// The sub-namespace to get references for /// /// The subNamespace parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task> GetAllForSubNamespace(long repositoryId, string subNamespace); @@ -155,9 +155,9 @@ namespace Octokit /// Options for changing the API response /// /// The subNamespace parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task> GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options); @@ -172,9 +172,9 @@ namespace Octokit /// The reference to create /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task Create(string owner, string name, NewReference reference); @@ -201,9 +201,9 @@ namespace Octokit /// The updated reference data /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate); @@ -218,9 +218,9 @@ namespace Octokit /// The updated reference data /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate); @@ -235,9 +235,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task Delete(string owner, string name, string reference); @@ -251,9 +251,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// Task Delete(long repositoryId, string reference); } diff --git a/Octokit/Clients/IRepositoryContentsClient.cs b/Octokit/Clients/IRepositoryContentsClient.cs index 698a4427..01770463 100644 --- a/Octokit/Clients/IRepositoryContentsClient.cs +++ b/Octokit/Clients/IRepositoryContentsClient.cs @@ -77,7 +77,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The content path - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] Task> GetAllContentsByRef(string owner, string name, string path, string reference); @@ -101,7 +101,7 @@ namespace Octokit /// /// The Id of the repository /// The content path - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] Task> GetAllContentsByRef(long repositoryId, string path, string reference); @@ -114,7 +114,7 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] Task> GetAllContentsByRef(string owner, string name, string reference); @@ -126,7 +126,7 @@ namespace Octokit /// See the API documentation for more information. /// /// The Id of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) [ExcludeFromPaginationApiOptionsConventionTest("Pagination not supported by GitHub API (tested 29/08/2017)")] Task> GetAllContentsByRef(long repositoryId, string reference); diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index 22b0c098..881d0a9d 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -31,9 +31,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("GET", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task Get(string owner, string name, string reference) @@ -60,9 +60,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("GET", "/repositories/{id}/git/refs/{ref}")] public Task Get(long repositoryId, string reference) @@ -171,9 +171,9 @@ namespace Octokit /// Options for changing the API response /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("GET", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task> GetAllForSubNamespace(string owner, string name, string subNamespace, ApiOptions options) @@ -217,9 +217,9 @@ namespace Octokit /// Options for changing the API response /// /// The subNamespace parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("GET", "/repositories/{id}/git/refs/{ref}")] public Task> GetAllForSubNamespace(long repositoryId, string subNamespace, ApiOptions options) @@ -284,9 +284,9 @@ namespace Octokit /// The updated reference data /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("PATCH", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) @@ -315,9 +315,9 @@ namespace Octokit /// The updated reference data /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("PATCH", "/repositories/{id}/git/refs/{ref}")] public Task Update(long repositoryId, string reference, ReferenceUpdate referenceUpdate) @@ -344,9 +344,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("PATCH", "/repos/{owner}/{repo}/git/refs/{ref}")] public Task Delete(string owner, string name, string reference) @@ -373,9 +373,9 @@ namespace Octokit /// The reference name /// /// The reference parameter supports either the fully-qualified ref - /// (prefixed with "refs/", e.g. "refs/heads/master" or + /// (prefixed with "refs/", e.g. "refs/heads/main" or /// "refs/tags/release-1") or the shortened form (omitting "refs/", e.g. - /// "heads/master" or "tags/release-1") + /// "heads/main" or "tags/release-1") /// [ManualRoute("DELETE", "/repositories/{id}/git/refs/{ref}")] public Task Delete(long repositoryId, string reference) diff --git a/Octokit/Clients/RepositoryContentsClient.cs b/Octokit/Clients/RepositoryContentsClient.cs index e5c7a666..200cc473 100644 --- a/Octokit/Clients/RepositoryContentsClient.cs +++ b/Octokit/Clients/RepositoryContentsClient.cs @@ -124,7 +124,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The content path - /// The name of the commit/branch/tag. Default: the repository�s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository�s default branch (usually main) [ManualRoute("GET", "/repos/{owner}/{repo}/contents/{path}?ref={ref}")] public Task> GetAllContentsByRef(string owner, string name, string path, string reference) { @@ -167,7 +167,7 @@ namespace Octokit /// /// The Id of the repository /// The content path - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) [ManualRoute("GET", "/repositories/{id}/contents/{path}?ref={ref}")] public Task> GetAllContentsByRef(long repositoryId, string path, string reference) { @@ -187,7 +187,7 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository - /// The name of the commit/branch/tag. Default: the repository�s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository�s default branch (usually main) [ManualRoute("GET", "/repos/{owner}/{repo}/contents/{path}?ref={ref}")] public Task> GetAllContentsByRef(string owner, string name, string reference) { @@ -208,7 +208,7 @@ namespace Octokit /// See the API documentation for more information. /// /// The Id of the repository - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) [ManualRoute("GET", "/repositories/{id}/contents/{path}?ref={ref}")] public Task> GetAllContentsByRef(long repositoryId, string reference) { diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 32955feb..4d3a8332 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -2441,7 +2441,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The path of the contents to get - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) /// The for getting the contents of the specified repository and path public static Uri RepositoryContent(string owner, string name, string path, string reference) { @@ -3447,7 +3447,7 @@ namespace Octokit /// /// The Id of the repository /// The path of the contents to get - /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually main) /// The for getting the contents of the specified repository and path public static Uri RepositoryContent(long repositoryId, string path, string reference) { diff --git a/Octokit/Helpers/ReferenceExtensions.cs b/Octokit/Helpers/ReferenceExtensions.cs index 1c4bd887..7fa716ef 100644 --- a/Octokit/Helpers/ReferenceExtensions.cs +++ b/Octokit/Helpers/ReferenceExtensions.cs @@ -41,7 +41,7 @@ namespace Octokit.Helpers /// The owner of the repository. /// The name of the repository. /// The new branch name - [Obsolete("This function is hard-coded to master branch, which is no longer a valid assumption for the base branch. Instead of making a second request to figure out the default branch, this extension method will be removed in a future release. Please check the default branch on the repository and use a different overload")] + [Obsolete("This function is hard-coded to master branch, which is no longer a valid assumption for the base branch. Instead of making a second request to figure out the default branch, this extension method will be removed in a future release. Please check the default branch on the repository and use the overload passing in the default branch name")] public static async Task CreateBranch(this IReferencesClient referencesClient, string owner, string name, string branchName) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); @@ -57,5 +57,29 @@ namespace Octokit.Helpers var newReference = new NewReference("refs/heads/" + branchName, baseBranch.Object.Sha); return await referencesClient.Create(owner, name, newReference).ConfigureAwait(false); } + + /// + /// Creates a branch, based off the default branch. + /// + /// The this method extends + /// The owner of the repository. + /// The name of the repository. + /// The new branch name + /// The repository's default branch name + public static async Task CreateBranch(this IReferencesClient referencesClient, string owner, string name, string branchName, string defaultBranchName) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(branchName, nameof(branchName)); + + if (branchName.StartsWith("refs/heads")) + { + throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The specified branch name '{0}' appears to be a ref name and not a branch name because it starts with the string 'refs/heads'. Either specify just the branch name or use the Create method if you need to specify the full ref name", branchName), "branchName"); + } + + var baseBranch = await referencesClient.Get(owner, name, $"heads/{defaultBranchName}").ConfigureAwait(false); + var newReference = new NewReference("refs/heads/" + branchName, baseBranch.Object.Sha); + return await referencesClient.Create(owner, name, newReference).ConfigureAwait(false); + } } } diff --git a/Octokit/Models/Request/CreateFileRequest.cs b/Octokit/Models/Request/CreateFileRequest.cs index 390fe564..4fc860e2 100644 --- a/Octokit/Models/Request/CreateFileRequest.cs +++ b/Octokit/Models/Request/CreateFileRequest.cs @@ -38,7 +38,7 @@ namespace Octokit public string Message { get; private set; } /// - /// The branch name. If null, this defaults to the default branch which is usually "master". + /// The branch name. If null, this defaults to the default branch which is usually "main". /// public string Branch { get; set; } diff --git a/Octokit/Models/Request/NewReference.cs b/Octokit/Models/Request/NewReference.cs index 95212076..f9bed8b8 100644 --- a/Octokit/Models/Request/NewReference.cs +++ b/Octokit/Models/Request/NewReference.cs @@ -18,7 +18,7 @@ namespace Octokit /// Initializes a new instance of the class. /// /// - /// The name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and + /// The name of the fully qualified reference (ie: refs/heads/main). If it doesn’t start with ‘refs’ and /// have at least two slashes, it will be rejected. /// /// The SHA1 value to set this reference to @@ -32,7 +32,7 @@ namespace Octokit } /// - /// The name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and + /// The name of the fully qualified reference (ie: refs/heads/main). If it doesn’t start with ‘refs’ and /// have at least two slashes, it will be rejected. /// /// diff --git a/Octokit/Models/Request/NewRelease.cs b/Octokit/Models/Request/NewRelease.cs index fee5fe13..23e561d2 100644 --- a/Octokit/Models/Request/NewRelease.cs +++ b/Octokit/Models/Request/NewRelease.cs @@ -33,7 +33,7 @@ namespace Octokit /// /// Specifies the commitish value that determines where the Git tag is created from. Can be any branch or /// commit SHA. Unused if the Git tag already exists. Default: the repository’s default branch - /// (usually master). + /// (usually main). /// /// /// The target commitish. diff --git a/Octokit/Models/Request/ReleaseUpdate.cs b/Octokit/Models/Request/ReleaseUpdate.cs index 6e7cf2dd..64399e78 100644 --- a/Octokit/Models/Request/ReleaseUpdate.cs +++ b/Octokit/Models/Request/ReleaseUpdate.cs @@ -23,7 +23,7 @@ namespace Octokit /// /// Specifies the commitish value that determines where the Git tag is created from. Can be any branch or /// commit SHA. Unused if the Git tag already exists. Default: the repository’s default branch - /// (usually master). + /// (usually main). /// /// /// The target commitish.