Files
octokit.net/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs
Ryan Gribble d166a8c142 Implement changes to Checks API for Annotations models and re-request endpoint (#1857)
* Attempt to handle both old and new annotations models so we support the changes on github.com as well as still support GHE2.14
add Path and AnnotationLevel fields
flag Filename and WarningLevel as deprecated/obsolete
also flag BlobHref as deprecated on NewCheckRunAnnotation
Adjust ctors to handle new and legacy field options

* adjust tests to remove use of obsoleted fields

* fix a couple of other tests using unrelated obsoleted fields

* Mark check suite Request method and request object as obsolete

* Add Rerequest() method to normal and observable clients
Add unit and integration tests

* add StartColumn and EndColumn as optional fields for CheckRunAnnotation response and NewCheckRunAnnotation request

* remove integration tests for Request() method as they no longer work on github.com anyway
2018-09-03 20:52:03 +10:00

463 lines
23 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Octokit.Tests.Integration.Helpers;
using Xunit;
namespace Octokit.Tests.Integration.Reactive
{
public class ObservableCheckRunsClientTests
{
public class TheCreateMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheCreateMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task CreatesCheckRun()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
}
}
[GitHubAppsTest]
public async Task CreatesCheckRunWithRepositoryId()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
}
}
}
public class TheUpdateMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheUpdateMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task UpdatesCheckRun()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Update the check run
var update = new CheckRunUpdate
{
Name = "new-name",
Status = CheckStatus.InProgress
};
var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryOwner, repoContext.RepositoryName, checkRun.Id, update);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
Assert.Equal("new-name", result.Name);
Assert.Equal(CheckStatus.InProgress, result.Status);
}
}
[GitHubAppsTest]
public async Task UpdatesCheckRunWithRepositoryId()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Update the check run
var update = new CheckRunUpdate
{
Name = "new-name",
Status = CheckStatus.InProgress
};
var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryId, checkRun.Id, update);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
Assert.Equal("new-name", result.Name);
Assert.Equal(CheckStatus.InProgress, result.Status);
}
}
}
public class TheGetAllForReferenceMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetAllForReferenceMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsAllCheckRuns()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, featureBranch.Object.Sha, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
[GitHubAppsTest]
public async Task GetsAllCheckRunsWithRepositoryId()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryId, featureBranch.Object.Sha, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
}
public class TheGetAllForCheckSuiteMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetAllForCheckSuiteMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsAllCheckRuns()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryOwner, repoContext.RepositoryName, created.CheckSuite.Id, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
[GitHubAppsTest]
public async Task GetsAllCheckRunsWithRepositoryId()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryId, created.CheckSuite.Id, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
}
public class TheGetMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsCheckRun()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the check
var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id);
// Check result
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
[GitHubAppsTest]
public async Task GetsCheckRunWithRepositoryId()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the check
var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryId, created.Id);
// Check result
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
public class TheGetAllAnnotationsMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetAllAnnotationsMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsAllAnnotations()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress,
Output = new NewCheckRunOutput("title", "summary")
{
Annotations = new[]
{
new NewCheckRunAnnotation("file.txt", 1, 1, CheckAnnotationLevel.Warning, "this is a warning")
}
}
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the annotations
var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id).ToList();
// Check result
Assert.Equal(1, annotations.Count);
Assert.Equal("this is a warning", annotations.First().Message);
Assert.Equal(CheckAnnotationLevel.Warning, annotations.First().AnnotationLevel);
}
}
[GitHubAppsTest]
public async Task GetsAllAnnotationsWithRepositoryId()
{
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 featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress,
Output = new NewCheckRunOutput("title", "summary")
{
Annotations = new[]
{
new NewCheckRunAnnotation("file.txt", 1, 1, CheckAnnotationLevel.Warning, "this is a warning")
}
}
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the annotations
var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryId, created.Id).ToList();
// Check result
Assert.Equal(1, annotations.Count);
Assert.Equal("this is a warning", annotations.First().Message);
Assert.Equal(CheckAnnotationLevel.Warning, annotations.First().AnnotationLevel);
}
}
}
}
}