From 913ce8d6e8c956eb3f232c2b7daf120aaa1fa803 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Wed, 9 May 2018 11:42:36 -0400 Subject: [PATCH 01/13] Add CheckRunEventPayload --- .../Response/ActivityPayloads/CheckRunEventPayload.cs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs diff --git a/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs new file mode 100644 index 0000000000..9f0cd3b9d4 --- /dev/null +++ b/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs @@ -0,0 +1,8 @@ +namespace Octokit +{ + public class CheckRunEventPayload : ActivityPayload + { + public string Action { get; protected set; } + public CheckRun CheckRun { get; protected set; } + } +} From d79d0b281a1ecb63eeb3a1352c640ebedad1c67f Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 14 Jul 2018 20:48:46 +1000 Subject: [PATCH 02/13] add CheckRunEventPayload into all the right places --- Octokit.Tests/Clients/EventsClientTests.cs | 1 + Octokit.Tests/Models/CheckRunEventTests.cs | 256 ++++++++++++++++++ Octokit/Http/SimpleJsonSerializer.cs | 2 + .../ActivityPayloads/CheckRunEventPayload.cs | 5 +- 4 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 Octokit.Tests/Models/CheckRunEventTests.cs diff --git a/Octokit.Tests/Clients/EventsClientTests.cs b/Octokit.Tests/Clients/EventsClientTests.cs index 3c9a79d2ac..99a65a7cd4 100644 --- a/Octokit.Tests/Clients/EventsClientTests.cs +++ b/Octokit.Tests/Clients/EventsClientTests.cs @@ -553,6 +553,7 @@ public async Task EnsuresNonNullArguments() private readonly Dictionary _activityTypes = new Dictionary { + {"CheckRunEvent", typeof(CheckRunEventPayload)}, {"CheckSuiteEvent", typeof(CheckSuiteEventPayload)}, {"CommitCommentEvent", typeof(CommitCommentPayload)}, {"ForkEvent", typeof(ForkEventPayload)}, diff --git a/Octokit.Tests/Models/CheckRunEventTests.cs b/Octokit.Tests/Models/CheckRunEventTests.cs new file mode 100644 index 0000000000..1038fda9f1 --- /dev/null +++ b/Octokit.Tests/Models/CheckRunEventTests.cs @@ -0,0 +1,256 @@ +using Octokit.Internal; +using Xunit; + +namespace Octokit.Tests.Models +{ + public class CheckRunEventTests + { + [Fact] + public void CanBeDeserialized() + { + const string json = @"{ + ""action"": ""rerequested"", + ""check_run"": { + ""id"": 4, + ""head_sha"": ""d6fde92930d4715a2b49857d24b940956b26d2d3"", + ""external_id"": """", + ""url"": ""https://api.github.com/repos/github/hello-world/check-runs/4"", + ""html_url"": ""http://github.com/github/hello-world/runs/4"", + ""status"": ""completed"", + ""conclusion"": ""neutral"", + ""started_at"": ""2018-05-04T01:14:52Z"", + ""completed_at"": ""2018-05-04T01:14:52Z"", + ""output"": { + ""title"": ""Report"", + ""summary"": ""It's all good."", + ""text"": ""Minus odio facilis repudiandae. Soluta odit aut amet magni nobis. Et voluptatibus ex dolorem et eum."", + ""annotations_count"": 2, + ""annotations_url"": ""https://api.github.com/repos/github/hello-world/check-runs/4/annotations"" + }, + ""name"": ""randscape"", + ""check_suite"": { + ""id"": 5, + ""head_branch"": ""master"", + ""head_sha"": ""d6fde92930d4715a2b49857d24b940956b26d2d3"", + ""status"": ""completed"", + ""conclusion"": ""neutral"", + ""url"": ""https://api.github.com/repos/github/hello-world/check-suites/5"", + ""before"": ""146e867f55c26428e5f9fade55a9bbf5e95a7912"", + ""after"": ""d6fde92930d4715a2b49857d24b940956b26d2d3"", + ""pull_requests"": [ + + ], + ""app"": { + ""id"": 2, + ""node_id"": ""MDExOkludGVncmF0aW9uMQ=="", + ""owner"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDEyOk9yZ2FuaXphdGlvbjE="", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/github"", + ""html_url"": ""http://github.com/github"", + ""followers_url"": ""https://api.github.com/users/github/followers"", + ""following_url"": ""https://api.github.com/users/github/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/github/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/github/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/github/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/github/orgs"", + ""repos_url"": ""https://api.github.com/users/github/repos"", + ""events_url"": ""https://api.github.com/users/github/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/github/received_events"", + ""type"": ""Organization"", + ""site_admin"": false + }, + ""name"": ""Super Duper"", + ""description"": null, + ""external_url"": ""http://super-duper.example.com"", + ""html_url"": ""http://github.com/apps/super-duper"", + ""created_at"": ""2018-04-25T20:42:10Z"", + ""updated_at"": ""2018-04-25T20:42:10Z"" + }, + ""created_at"": ""2018-05-04T01:14:52Z"", + ""updated_at"": ""2018-05-04T01:14:52Z"" + }, + ""app"": { + ""id"": 2, + ""node_id"": ""MDExOkludGVncmF0aW9uMQ=="", + ""owner"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDEyOk9yZ2FuaXphdGlvbjE="", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/github"", + ""html_url"": ""http://github.com/github"", + ""followers_url"": ""https://api.github.com/users/github/followers"", + ""following_url"": ""https://api.github.com/users/github/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/github/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/github/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/github/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/github/orgs"", + ""repos_url"": ""https://api.github.com/users/github/repos"", + ""events_url"": ""https://api.github.com/users/github/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/github/received_events"", + ""type"": ""Organization"", + ""site_admin"": false + }, + ""name"": ""Super Duper"", + ""description"": null, + ""external_url"": ""http://super-duper.example.com"", + ""html_url"": ""http://github.com/apps/super-duper"", + ""created_at"": ""2018-04-25T20:42:10Z"", + ""updated_at"": ""2018-04-25T20:42:10Z"" + }, + ""pull_requests"": [ + + ] + }, + ""repository"": { + ""id"": 526, + ""node_id"": ""MDEwOlJlcG9zaXRvcnkxMzU0OTMyMzM="", + ""name"": ""hello-world"", + ""full_name"": ""github/hello-world"", + ""owner"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDQ6VXNlcjIxMDMxMDY3"", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/github"", + ""html_url"": ""http://github.com/github"", + ""followers_url"": ""https://api.github.com/users/github/followers"", + ""following_url"": ""https://api.github.com/users/github/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/github/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/github/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/github/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/github/orgs"", + ""repos_url"": ""https://api.github.com/users/github/repos"", + ""events_url"": ""https://api.github.com/users/github/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/github/received_events"", + ""type"": ""Organization"", + ""site_admin"": false + }, + ""private"": false, + ""html_url"": ""http://github.com/github/hello-world"", + ""description"": null, + ""fork"": false, + ""url"": ""https://api.github.com/repos/github/hello-world"", + ""forks_url"": ""https://api.github.com/repos/github/hello-world/forks"", + ""keys_url"": ""https://api.github.com/repos/github/hello-world/keys{/key_id}"", + ""collaborators_url"": ""https://api.github.com/repos/github/hello-world/collaborators{/collaborator}"", + ""teams_url"": ""https://api.github.com/repos/github/hello-world/teams"", + ""hooks_url"": ""https://api.github.com/repos/github/hello-world/hooks"", + ""issue_events_url"": ""https://api.github.com/repos/github/hello-world/issues/events{/number}"", + ""events_url"": ""https://api.github.com/repos/github/hello-world/events"", + ""assignees_url"": ""https://api.github.com/repos/github/hello-world/assignees{/user}"", + ""branches_url"": ""https://api.github.com/repos/github/hello-world/branches{/branch}"", + ""tags_url"": ""https://api.github.com/repos/github/hello-world/tags"", + ""blobs_url"": ""https://api.github.com/repos/github/hello-world/git/blobs{/sha}"", + ""git_tags_url"": ""https://api.github.com/repos/github/hello-world/git/tags{/sha}"", + ""git_refs_url"": ""https://api.github.com/repos/github/hello-world/git/refs{/sha}"", + ""trees_url"": ""https://api.github.com/repos/github/hello-world/git/trees{/sha}"", + ""statuses_url"": ""https://api.github.com/repos/github/hello-world/statuses/{sha}"", + ""languages_url"": ""https://api.github.com/repos/github/hello-world/languages"", + ""stargazers_url"": ""https://api.github.com/repos/github/hello-world/stargazers"", + ""contributors_url"": ""https://api.github.com/repos/github/hello-world/contributors"", + ""subscribers_url"": ""https://api.github.com/repos/github/hello-world/subscribers"", + ""subscription_url"": ""https://api.github.com/repos/github/hello-world/subscription"", + ""commits_url"": ""https://api.github.com/repos/github/hello-world/commits{/sha}"", + ""git_commits_url"": ""https://api.github.com/repos/github/hello-world/git/commits{/sha}"", + ""comments_url"": ""https://api.github.com/repos/github/hello-world/comments{/number}"", + ""issue_comment_url"": ""https://api.github.com/repos/github/hello-world/issues/comments{/number}"", + ""contents_url"": ""https://api.github.com/repos/github/hello-world/contents/{+path}"", + ""compare_url"": ""https://api.github.com/repos/github/hello-world/compare/{base}...{head}"", + ""merges_url"": ""https://api.github.com/repos/github/hello-world/merges"", + ""archive_url"": ""https://api.github.com/repos/github/hello-world/{archive_format}{/ref}"", + ""downloads_url"": ""https://api.github.com/repos/github/hello-world/downloads"", + ""issues_url"": ""https://api.github.com/repos/github/hello-world/issues{/number}"", + ""pulls_url"": ""https://api.github.com/repos/github/hello-world/pulls{/number}"", + ""milestones_url"": ""https://api.github.com/repos/github/hello-world/milestones{/number}"", + ""notifications_url"": ""https://api.github.com/repos/github/hello-world/notifications{?since,all,participating}"", + ""labels_url"": ""https://api.github.com/repos/github/hello-world/labels{/name}"", + ""releases_url"": ""https://api.github.com/repos/github/hello-world/releases{/id}"", + ""deployments_url"": ""https://api.github.com/repos/github/hello-world/deployments"", + ""created_at"": ""2018-04-25T20:42:10Z"", + ""updated_at"": ""2018-04-25T20:43:34Z"", + ""pushed_at"": ""2018-05-04T01:14:47Z"", + ""git_url"": ""git://github.com/github/hello-world.git"", + ""ssh_url"": ""ssh://git@localhost:3035/github/hello-world.git"", + ""clone_url"": ""http://github.com/github/hello-world.git"", + ""svn_url"": ""http://github.com/github/hello-world"", + ""homepage"": null, + ""size"": 0, + ""stargazers_count"": 0, + ""watchers_count"": 0, + ""language"": null, + ""has_issues"": true, + ""has_projects"": true, + ""has_downloads"": true, + ""has_wiki"": true, + ""has_pages"": false, + ""forks_count"": 0, + ""mirror_url"": null, + ""archived"": false, + ""open_issues_count"": 3, + ""license"": null, + ""forks"": 0, + ""open_issues"": 3, + ""watchers"": 0, + ""default_branch"": ""master"" + }, + ""organization"": { + ""login"": ""github"", + ""id"": 340, + ""node_id"": ""MDEyOk9yZ2FuaXphdGlvbjM4MzAyODk5"", + ""url"": ""https://api.github.com/orgs/github"", + ""repos_url"": ""https://api.github.com/orgs/github/repos"", + ""events_url"": ""https://api.github.com/orgs/github/events"", + ""hooks_url"": ""https://api.github.com/orgs/github/hooks"", + ""issues_url"": ""https://api.github.com/orgs/github/issues"", + ""members_url"": ""https://api.github.com/orgs/github/members{/member}"", + ""public_members_url"": ""https://api.github.com/orgs/github/public_members{/member}"", + ""avatar_url"": ""http://alambic.github.com/avatars/u/340?"", + ""description"": ""How people build software."" + }, + ""sender"": { + ""login"": ""octocat"", + ""id"": 5346, + ""node_id"": ""MDQ6VXNlcjIxMDMxMDY3"", + ""avatar_url"": ""http://alambic.github.com/avatars/u/5346?"", + ""gravatar_id"": """", + ""url"": ""https://api.github.com/users/octocat"", + ""html_url"": ""http://github.com/octocat"", + ""followers_url"": ""https://api.github.com/users/octocat/followers"", + ""following_url"": ""https://api.github.com/users/octocat/following{/other_user}"", + ""gists_url"": ""https://api.github.com/users/octocat/gists{/gist_id}"", + ""starred_url"": ""https://api.github.com/users/octocat/starred{/owner}{/repo}"", + ""subscriptions_url"": ""https://api.github.com/users/octocat/subscriptions"", + ""organizations_url"": ""https://api.github.com/users/octocat/orgs"", + ""repos_url"": ""https://api.github.com/users/octocat/repos"", + ""events_url"": ""https://api.github.com/users/octocat/events{/privacy}"", + ""received_events_url"": ""https://api.github.com/users/octocat/received_events"", + ""type"": ""User"", + ""site_admin"": false + }, + ""installation"": { + ""id"": 1 + } +}"; + + var serializer = new SimpleJsonSerializer(); + + var payload = serializer.Deserialize(json); + + Assert.Equal("rerequested", payload.Action); + Assert.Equal("d6fde92930d4715a2b49857d24b940956b26d2d3", payload.CheckRun.HeadSha); + Assert.Equal(4, payload.CheckRun.Id); + Assert.Equal(CheckStatus.Completed, payload.CheckRun.Status); + Assert.Equal(CheckConclusion.Neutral, payload.CheckRun.Conclusion); + Assert.Equal(5, payload.CheckRun.CheckSuite.Id); + Assert.Equal(CheckStatus.Completed, payload.CheckRun.CheckSuite.Status.Value); + Assert.Equal(CheckConclusion.Neutral, payload.CheckRun.CheckSuite.Conclusion); + } + } +} diff --git a/Octokit/Http/SimpleJsonSerializer.cs b/Octokit/Http/SimpleJsonSerializer.cs index 1fd2bc55bc..0e6aa45ba3 100644 --- a/Octokit/Http/SimpleJsonSerializer.cs +++ b/Octokit/Http/SimpleJsonSerializer.cs @@ -206,6 +206,8 @@ private static Type GetPayloadType(string activityType) { switch (activityType) { + case "CheckRunEvent": + return typeof(CheckRunEventPayload); case "CheckSuiteEvent": return typeof(CheckSuiteEventPayload); case "CommitCommentEvent": diff --git a/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs b/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs index 9f0cd3b9d4..a3b76b1a45 100644 --- a/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs +++ b/Octokit/Models/Response/ActivityPayloads/CheckRunEventPayload.cs @@ -1,5 +1,8 @@ -namespace Octokit +using System.Diagnostics; + +namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class CheckRunEventPayload : ActivityPayload { public string Action { get; protected set; } From 3f5c184ce8efd96546aa13ece92559f1fb13ccfa Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 11 Jul 2018 22:55:47 +1000 Subject: [PATCH 03/13] forgot integration tests for RepositoryId methods (+1 squashed commits) Squashed commits: [b2445bf3] Implement Create CheckRun methods for normal and observable clients including unit and integration tests and xmldoc comments --- .../Clients/IObservableCheckRunsClient.cs | 34 ++++++ .../Clients/IObservableChecksClient.cs | 8 ++ .../Clients/ObservableCheckRunsClient.cs | 62 +++++++++++ .../Clients/ObservableChecksClient.cs | 13 +++ .../Clients/CheckRunsClientTests.cs | 67 +++++++++++ .../ObservableCheckRunsClientTests.cs | 70 ++++++++++++ Octokit.Tests/Clients/CheckRunsClientTests.cs | 81 ++++++++++++++ .../ObservableCheckRunsClientTests.cs | 76 +++++++++++++ Octokit/Clients/CheckRunsClient.cs | 55 +++++++++ Octokit/Clients/ChecksClient.cs | 9 ++ Octokit/Clients/ICheckRunsClient.cs | 36 ++++++ Octokit/Clients/IChecksClient.cs | 8 ++ Octokit/Helpers/ApiUrls.cs | 20 ++++ Octokit/Models/Common/CheckStatus.cs | 12 ++ Octokit/Models/Request/CheckRunAction.cs | 39 +++++++ Octokit/Models/Request/CheckRunAnnotation.cs | 70 ++++++++++++ Octokit/Models/Request/CheckRunImage.cs | 37 ++++++ Octokit/Models/Request/CheckRunOutput.cs | 48 ++++++++ Octokit/Models/Request/NewCheckRun.cs | 75 +++++++++++++ Octokit/Models/Response/CheckRun.cs | 105 ++++++++++++++++++ .../Models/Response/CheckRunOutputResponse.cs | 44 ++++++++ 21 files changed, 969 insertions(+) create mode 100644 Octokit.Reactive/Clients/IObservableCheckRunsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableCheckRunsClient.cs create mode 100644 Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs create mode 100644 Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs create mode 100644 Octokit.Tests/Clients/CheckRunsClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs create mode 100644 Octokit/Clients/CheckRunsClient.cs create mode 100644 Octokit/Clients/ICheckRunsClient.cs create mode 100644 Octokit/Models/Request/CheckRunAction.cs create mode 100644 Octokit/Models/Request/CheckRunAnnotation.cs create mode 100644 Octokit/Models/Request/CheckRunImage.cs create mode 100644 Octokit/Models/Request/CheckRunOutput.cs create mode 100644 Octokit/Models/Request/NewCheckRun.cs create mode 100644 Octokit/Models/Response/CheckRun.cs create mode 100644 Octokit/Models/Response/CheckRunOutputResponse.cs diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs new file mode 100644 index 0000000000..3a3e71b108 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -0,0 +1,34 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public interface IObservableCheckRunsClient + { + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + IObservable Create(string owner, string name, NewCheckRun newCheckRun); + + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + IObservable Create(long repositoryId, NewCheckRun newCheckRun); + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableChecksClient.cs b/Octokit.Reactive/Clients/IObservableChecksClient.cs index a5127ae78f..ad64e42214 100644 --- a/Octokit.Reactive/Clients/IObservableChecksClient.cs +++ b/Octokit.Reactive/Clients/IObservableChecksClient.cs @@ -8,6 +8,14 @@ /// public interface IObservableChecksClient { + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + IObservableCheckRunsClient Run { get; } + /// /// A client for GitHub's Check Suites API. /// diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs new file mode 100644 index 0000000000..1255f8778f --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -0,0 +1,62 @@ +using System; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public class ObservableCheckRunsClient : IObservableCheckRunsClient + { + readonly ICheckRunsClient _client; + readonly IConnection _connection; + + /// + /// Initializes a new GitHub Check Runs API client. + /// + /// An used to make the requests + public ObservableCheckRunsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, nameof(client)); + + _client = client.Check.Run; + _connection = client.Connection; + } + + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + public IObservable Create(string owner, string name, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return _client.Create(owner, name, newCheckRun).ToObservable(); + } + + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + public IObservable Create(long repositoryId, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return _client.Create(repositoryId, newCheckRun).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableChecksClient.cs b/Octokit.Reactive/Clients/ObservableChecksClient.cs index 90c4b72dcd..eb3d829f6e 100644 --- a/Octokit.Reactive/Clients/ObservableChecksClient.cs +++ b/Octokit.Reactive/Clients/ObservableChecksClient.cs @@ -8,13 +8,26 @@ /// public class ObservableChecksClient : IObservableChecksClient { + /// + /// Initializes a new GitHub Checks API client. + /// + /// An used to make the requests public ObservableChecksClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); + Run = new ObservableCheckRunsClient(client); Suite = new ObservableCheckSuitesClient(client); } + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public IObservableCheckRunsClient Run { get; private set; } + /// /// A client for GitHub's Check Suites API. /// diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs new file mode 100644 index 0000000000..5ffbc64338 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -0,0 +1,67 @@ +using System.Threading.Tasks; +using Octokit.Tests.Integration.Helpers; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class CheckRunsClientTests + { + public class TheCreateMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheCreateMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = 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); + } + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs new file mode 100644 index 0000000000..ae51ee5e91 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -0,0 +1,70 @@ +using System.Collections.Generic; +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); + } + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs new file mode 100644 index 0000000000..c3c387018c --- /dev/null +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -0,0 +1,81 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class CheckRunsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new CheckRunsClient(null)); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await client.Create("fake", "repo", newCheckRun); + + connection.Received().Post( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs"), + newCheckRun, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await client.Create(1, newCheckRun); + + connection.Received().Post( + Arg.Is(u => u.ToString() == "repositories/1/check-runs"), + newCheckRun, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await Assert.ThrowsAsync(() => client.Create(null, "repo", newCheckRun)); + await Assert.ThrowsAsync(() => client.Create("fake", null, newCheckRun)); + await Assert.ThrowsAsync(() => client.Create("fake", "repo", null)); + + await Assert.ThrowsAsync(() => client.Create(1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + await Assert.ThrowsAsync(() => client.Create("", "repo", newCheckRun)); + await Assert.ThrowsAsync(() => client.Create("fake", "", newCheckRun)); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs new file mode 100644 index 0000000000..22e2b3a82e --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -0,0 +1,76 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class ObservableCheckRunsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableCheckRunsClient(null)); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + client.Create("fake", "repo", newCheckRun); + + gitHubClient.Check.Run.Received().Create("fake", "repo", newCheckRun); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + client.Create(1, newCheckRun); + + gitHubClient.Check.Run.Received().Create(1, newCheckRun); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + Assert.Throws(() => client.Create(null, "repo", newCheckRun)); + Assert.Throws(() => client.Create("fake", null, newCheckRun)); + Assert.Throws(() => client.Create("fake", "repo", null)); + + Assert.Throws(() => client.Create(1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var newCheckRun = new NewCheckRun("status", "123abc") { Status = CheckStatus.Queued }; + + Assert.Throws(() => client.Create("", "repo", newCheckRun)); + Assert.Throws(() => client.Create("fake", "", newCheckRun)); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs new file mode 100644 index 0000000000..0216d86c80 --- /dev/null +++ b/Octokit/Clients/CheckRunsClient.cs @@ -0,0 +1,55 @@ +using System; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public class CheckRunsClient : ApiClient, ICheckRunsClient + { + /// + /// Initializes a new GitHub Check Runs API client. + /// + /// An API connection + public CheckRunsClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + public Task Create(string owner, string name, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return ApiConnection.Post(ApiUrls.CheckRuns(owner, name), newCheckRun, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + public Task Create(long repositoryId, NewCheckRun newCheckRun) + { + Ensure.ArgumentNotNull(newCheckRun, nameof(newCheckRun)); + + return ApiConnection.Post(ApiUrls.CheckRuns(repositoryId), newCheckRun, AcceptHeaders.ChecksApiPreview); + } + } +} diff --git a/Octokit/Clients/ChecksClient.cs b/Octokit/Clients/ChecksClient.cs index 17dcfcb766..08a6ccfbc2 100644 --- a/Octokit/Clients/ChecksClient.cs +++ b/Octokit/Clients/ChecksClient.cs @@ -14,9 +14,18 @@ public class ChecksClient : IChecksClient /// An API connection public ChecksClient(ApiConnection apiConnection) { + Run = new CheckRunsClient(apiConnection); Suite = new CheckSuitesClient(apiConnection); } + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public ICheckRunsClient Run { get; private set; } + /// /// A client for GitHub's Check Suites API. /// diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs new file mode 100644 index 0000000000..33ec8f055d --- /dev/null +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + public interface ICheckRunsClient + { + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Details of the Check Run to create + Task Create(string owner, string name, NewCheckRun newCheckRun); + + /// + /// Creates a new Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// Details of the Check Run to create + Task Create(long repositoryId, NewCheckRun newCheckRun); + + } +} diff --git a/Octokit/Clients/IChecksClient.cs b/Octokit/Clients/IChecksClient.cs index c973bc1e90..a816344a43 100644 --- a/Octokit/Clients/IChecksClient.cs +++ b/Octokit/Clients/IChecksClient.cs @@ -8,6 +8,14 @@ /// public interface IChecksClient { + /// + /// A client for GitHub's Check Runs API. + /// + /// + /// See the Check Runs API documentation for more information. + /// + ICheckRunsClient Run { get; } + /// /// A client for GitHub's Check Suites API. /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index e06d70cefb..960ccd4155 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3830,6 +3830,26 @@ public static Uri RepositoryLicense(long repositoryId) } /// + /// Returns the that handles the check runs for the repository. + /// + /// The Id of the repository + /// The that handles the check runs for the repository. + public static Uri CheckRuns(long repositoryId) + { + return "repositories/{0}/check-runs".FormatUri(repositoryId); + } + + /// + /// Returns the that handles the check runs for the repository. + /// + /// The owner of repo + /// The name of repo + /// The that handles the check runs for the repository. + public static Uri CheckRuns(string owner, string repo) + { + return "repos/{0}/{1}/check-runs".FormatUri(owner, repo); + } + /// Returns the that returns the specified check suite. /// /// The Id of the repository diff --git a/Octokit/Models/Common/CheckStatus.cs b/Octokit/Models/Common/CheckStatus.cs index c940781a23..129da9d687 100644 --- a/Octokit/Models/Common/CheckStatus.cs +++ b/Octokit/Models/Common/CheckStatus.cs @@ -34,4 +34,16 @@ public enum CheckConclusion [Parameter(Value = "action_required")] ActionRequired, } + + public enum CheckWarningLevel + { + [Parameter(Value = "notice")] + Notice, + + [Parameter(Value = "warning")] + Warning, + + [Parameter(Value = "failure")] + Failure, + } } diff --git a/Octokit/Models/Request/CheckRunAction.cs b/Octokit/Models/Request/CheckRunAction.cs new file mode 100644 index 0000000000..f725889798 --- /dev/null +++ b/Octokit/Models/Request/CheckRunAction.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunAction + { + /// + /// Constructs a CheckRunAction request object + /// + /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters. + /// Required. A short explanation of what this action would do. The maximum size is 40 characters. + /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters. + public CheckRunAction(string label, string description, string identifier) + { + Label = label; + Description = description; + Identifier = identifier; + } + + /// + /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters. + /// + public string Label { get; protected set; } + + /// + /// Required. A short explanation of what this action would do. The maximum size is 40 characters. + /// + public string Description { get; protected set; } + + /// + /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters. + /// + public string Identifier { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Label: {0}", Label); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/CheckRunAnnotation.cs b/Octokit/Models/Request/CheckRunAnnotation.cs new file mode 100644 index 0000000000..acea53638b --- /dev/null +++ b/Octokit/Models/Request/CheckRunAnnotation.cs @@ -0,0 +1,70 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunAnnotation + { + /// + /// Constructs a CheckRunAnnotation request object + /// + /// Required. The path of the file to add an annotation to. For example, assets/css/main.css. + /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename. + /// Required. The start line of the annotation. + /// Required. The end line of the annotation. + /// Required. The warning level of the annotation. Can be one of notice, warning, or failure. + /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB. + public CheckRunAnnotation(string filename, string blobHref, int startLine, int endLine, CheckWarningLevel warningLevel, string message) + { + Filename = filename; + BlobHref = blobHref; + StartLine = startLine; + EndLine = endLine; + WarningLevel = warningLevel; + Message = message; + } + + /// + /// Required. The path of the file to add an annotation to. For example, assets/css/main.css. + /// + public string Filename { get; protected set; } + + /// + /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename. + /// + public string BlobHref { get; protected set; } + + /// + /// Required. The start line of the annotation. + /// + public int StartLine { get; protected set; } + + /// + /// Required. The end line of the annotation. + /// + public int EndLine { get; protected set; } + + /// + /// Required. The warning level of the annotation. Can be one of notice, warning, or failure. + /// + public StringEnum WarningLevel { get; protected set; } + + /// + /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB. + /// + public string Message { get; protected set; } + + /// + /// The title that represents the annotation. The maximum size is 255 characters. + /// + public string Title { get; set; } + + /// + /// Details about this annotation. The maximum size is 64 KB. + /// + public string RawDetails { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Title: {0}, Filename: {1}, WarningLevel: {2}", Title ?? "", Filename, WarningLevel.DebuggerDisplay); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/CheckRunImage.cs b/Octokit/Models/Request/CheckRunImage.cs new file mode 100644 index 0000000000..cb9f4c222d --- /dev/null +++ b/Octokit/Models/Request/CheckRunImage.cs @@ -0,0 +1,37 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunImage + { + /// + /// Constructs a CheckRunImage request object + /// + /// Required. The alternative text for the image. + /// Required. The full URL of the image. + public CheckRunImage(string alt, string imageUrl) + { + Alt = alt; + ImageUrl = imageUrl; + } + + /// + /// Required. The alternative text for the image. + /// + public string Alt { get; protected set; } + + /// + /// Required. The full URL of the image. + /// + public string ImageUrl { get; protected set; } + + /// + /// A short image description. + /// + public string Caption { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Alt: {0}, ImageUrl: {1}", Alt, ImageUrl); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/CheckRunOutput.cs b/Octokit/Models/Request/CheckRunOutput.cs new file mode 100644 index 0000000000..fd41ad21de --- /dev/null +++ b/Octokit/Models/Request/CheckRunOutput.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunOutput + { + /// + /// Constructs a CheckRunOutput request object + /// + /// Required. The title of the check run. + /// Required. The summary of the check run. This parameter supports Markdown. + public CheckRunOutput(string title, string summary) + { + Title = title; + Summary = summary; + } + + /// + /// Required. The title of the check run. + /// + public string Title { get; protected set; } + + /// + /// Required. The summary of the check run. This parameter supports Markdown. + /// + public string Summary { get; protected set; } + + /// + /// The details of the check run. This parameter supports Markdown. + /// + public string Text { get; set; } + + /// + /// Adds information from your analysis to specific lines of code. Annotations are visible in GitHub's pull request UI. For details about annotations in the UI, see "About status checks". + /// + public IReadOnlyList Annotations { get; set; } + + /// + /// Adds images to the output displayed in the GitHub pull request UI. + /// + public IReadOnlyList Images { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Title: {0}", Title); + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/NewCheckRun.cs b/Octokit/Models/Request/NewCheckRun.cs new file mode 100644 index 0000000000..fd3e9c06e5 --- /dev/null +++ b/Octokit/Models/Request/NewCheckRun.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class NewCheckRun + { + /// + /// Creates a new Check Run + /// + /// Required. The name of the check. For example, "code-coverage". + /// Required. The SHA of the commit. + public NewCheckRun(string name, string headSha) + { + Name = name; + HeadSha = headSha; + } + + /// + /// Required. The name of the check. For example, "code-coverage". + /// + public string Name { get; private set; } + + /// + /// Required. The SHA of the commit. + /// + public string HeadSha { get; private set; } + + /// + /// The URL of the integrator's site that has the full details of the check. + /// + public string DetailsUrl { get; set; } + + /// + /// A reference for the run on the integrator's system. + /// + public string ExternalId { get; set; } + + /// + /// The current status. Can be one of queued, in_progress, or completed. Default: queued + /// + public StringEnum Status { get; set; } + + /// + /// The time that the check run began + /// + public DateTimeOffset StartedAt { get; set; } + + /// + /// Required if you provide a status of completed. The final conclusion of the check. Can be one of success, failure, neutral, cancelled, timed_out, or action_required. When the conclusion is action_required, additional details should be provided on the site specified by details_url. + /// Note: Providing conclusion will automatically set the status parameter to completed. + /// + public StringEnum? Conclusion { get; set; } + + /// + /// Required if you provide conclusion. The time the check completed. + /// + public DateTimeOffset? CompletedAt { get; set; } + + /// + /// Check runs can accept a variety of data in the output object, including a title and summary and can optionally provide descriptive details about the run. + /// + public CheckRunOutput Output { get; set; } + + /// + /// Possible further actions the integrator can perform, which a user may trigger. Each action includes a label, identifier and description. A maximum of three actions are accepted. + /// + public IReadOnlyList Actions { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Name: {0}, HeadSha: {1}, Status: {2}, Conclusion: {3}", Name, HeadSha, Status, Conclusion); + } +} diff --git a/Octokit/Models/Response/CheckRun.cs b/Octokit/Models/Response/CheckRun.cs new file mode 100644 index 0000000000..8a52a69803 --- /dev/null +++ b/Octokit/Models/Response/CheckRun.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRun + { + public CheckRun() + { + } + + public CheckRun(long id, string headSha, string externalId, string url, string htmlUrl, CheckStatus status, CheckConclusion? conclusion, DateTimeOffset startedAt, DateTimeOffset? completedAt, CheckRunOutputResponse output, string name, CheckSuite checkSuite, GitHubApp app, IReadOnlyList pullRequests) + { + Id = id; + HeadSha = headSha; + ExternalId = externalId; + Url = url; + HtmlUrl = htmlUrl; + Status = status; + Conclusion = conclusion; + StartedAt = startedAt; + CompletedAt = completedAt; + Output = output; + Name = name; + CheckSuite = checkSuite; + App = app; + PullRequests = pullRequests; + } + + /// + /// The Id of this check run + /// + public long Id { get; protected set; } + + /// + /// The commit this check run is associated with + /// + public string HeadSha { get; protected set; } + + /// + /// A reference for the run on the integrator's system. + /// + public string ExternalId { get; protected set; } + + /// + /// The GitHub Api URL of this check run + /// + public string Url { get; protected set; } + + /// + /// The GitHub.com URL of this check run + /// + public string HtmlUrl { get; protected set; } + + /// + /// The check run status + /// + public StringEnum Status { get; protected set; } + + /// + /// The final conclusion of the check + /// + public StringEnum? Conclusion { get; protected set; } + + /// + /// The time that the check run began + /// + public DateTimeOffset StartedAt { get; protected set; } + + /// + /// The time the check run completed + /// + public DateTimeOffset? CompletedAt { get; protected set; } + + /// + /// Descriptive details about the run + /// + public CheckRunOutputResponse Output { get; protected set; } + + /// + /// The name of the check + /// + public string Name { get; protected set; } + + /// + /// The check suite that is associated with this check run + /// + public CheckSuite CheckSuite { get; protected set; } + + /// + /// The GitHub App that is associated with this check run + /// + public GitHubApp App { get; protected set; } + + /// + /// The pull requests that are associated with this check run + /// + public IReadOnlyList PullRequests { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Id: {0}, HeadSha: {1}, Conclusion: {2}", Id, HeadSha, Conclusion); + } +} diff --git a/Octokit/Models/Response/CheckRunOutputResponse.cs b/Octokit/Models/Response/CheckRunOutputResponse.cs new file mode 100644 index 0000000000..20b7cf3fed --- /dev/null +++ b/Octokit/Models/Response/CheckRunOutputResponse.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunOutputResponse + { + public CheckRunOutputResponse() + { + } + + public CheckRunOutputResponse(string title, string summary, string text, long annotationsCount) + { + Title = title; + Summary = summary; + Text = text; + AnnotationsCount = annotationsCount; + } + + /// + /// The title of the check run + /// + public string Title { get; protected set; } + + /// + /// The summary of the check run + /// + public string Summary { get; protected set; } + + /// + /// The details of the check run + /// + public string Text { get; protected set; } + + /// + /// The number of annotations (use ICheckRunsClient.GetAllAnnotations() to load annotations) + /// + public long AnnotationsCount { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Title: {0}", Title); + } +} \ No newline at end of file From 44985a99b16d86fd4b73c59501b9e3da52988a38 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 11 Jul 2018 23:53:37 +1000 Subject: [PATCH 04/13] Implement Update CheckRun method Refactored NewCheckRun to inherit CheckRunUpdate since they share all fields except HeadSha --- .../Clients/IObservableCheckRunsClient.cs | 23 ++++++ .../Clients/ObservableCheckRunsClient.cs | 35 +++++++++ .../Clients/CheckRunsClientTests.cs | 76 +++++++++++++++++++ .../ObservableCheckRunsClientTests.cs | 76 +++++++++++++++++++ Octokit.Tests/Clients/CheckRunsClientTests.cs | 60 +++++++++++++++ .../ObservableCheckRunsClientTests.cs | 54 +++++++++++++ Octokit/Clients/CheckRunsClient.cs | 35 +++++++++ Octokit/Clients/ICheckRunsClient.cs | 22 ++++++ Octokit/Helpers/ApiUrls.cs | 24 ++++++ Octokit/Models/Request/CheckRunUpdate.cs | 68 +++++++++++++++++ Octokit/Models/Request/NewCheckRun.cs | 53 +------------ 11 files changed, 476 insertions(+), 50 deletions(-) create mode 100644 Octokit/Models/Request/CheckRunUpdate.cs diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index 3a3e71b108..c3b9103202 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -30,5 +30,28 @@ public interface IObservableCheckRunsClient /// The Id of the repository /// Details of the Check Run to create IObservable Create(long repositoryId, NewCheckRun newCheckRun); + + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + IObservable Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + IObservable Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index 1255f8778f..9d92a5e1cf 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -58,5 +58,40 @@ public IObservable Create(long repositoryId, NewCheckRun newCheckRun) return _client.Create(repositoryId, newCheckRun).ToObservable(); } + + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + public IObservable Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return _client.Update(owner, name, checkRunId, checkRunUpdate).ToObservable(); + } + + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + public IObservable Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return _client.Update(repositoryId, checkRunId, checkRunUpdate).ToObservable(); + } } } diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 5ffbc64338..8898de8e20 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -63,5 +63,81 @@ public async Task CreatesCheckRunWithRepositoryId() } } } + + public class TheUpdateMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheUpdateMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = 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("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("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); + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs index ae51ee5e91..6f87273390 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -66,5 +66,81 @@ public async Task CreatesCheckRunWithRepositoryId() } } } + + 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("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("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); + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs index c3c387018c..7b9c71c051 100644 --- a/Octokit.Tests/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -77,5 +77,65 @@ public async Task EnsuresNonEmptyArguments() await Assert.ThrowsAsync(() => client.Create("fake", "", newCheckRun)); } } + + public class TheUpdateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await client.Update("fake", "repo", 1, update); + + connection.Received().Patch( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1"), + update, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await client.Update(1, 1, update); + + connection.Received().Patch( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1"), + update, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await Assert.ThrowsAsync(() => client.Update(null, "repo", 1, update)); + await Assert.ThrowsAsync(() => client.Update("fake", null, 1, update)); + await Assert.ThrowsAsync(() => client.Update("fake", "repo", 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + await Assert.ThrowsAsync(() => client.Update("", "repo", 1, update)); + await Assert.ThrowsAsync(() => client.Update("fake", "", 1, update)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs index 22e2b3a82e..1f0af2687f 100644 --- a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -72,5 +72,59 @@ public async Task EnsuresNonEmptyArguments() Assert.Throws(() => client.Create("fake", "", newCheckRun)); } } + + public class TheUpdateMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + client.Update("fake", "repo", 1, update); + + gitHubClient.Check.Run.Received().Update("fake", "repo", 1, update); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + client.Update(1, 1, update); + + gitHubClient.Check.Run.Received().Update(1, 1, update); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + Assert.Throws(() => client.Update(null, "repo", 1, update)); + Assert.Throws(() => client.Update("fake", null, 1, update)); + Assert.Throws(() => client.Update("fake", "repo", 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var update = new CheckRunUpdate("status") { Status = CheckStatus.InProgress }; + + Assert.Throws(() => client.Update("", "repo", 1, update)); + Assert.Throws(() => client.Update("fake", "", 1, update)); + } + } } } \ No newline at end of file diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index 0216d86c80..b04b6df225 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -51,5 +51,40 @@ public Task Create(long repositoryId, NewCheckRun newCheckRun) return ApiConnection.Post(ApiUrls.CheckRuns(repositoryId), newCheckRun, AcceptHeaders.ChecksApiPreview); } + + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + public Task Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return ApiConnection.Patch(ApiUrls.CheckRun(owner, name, checkRunId), checkRunUpdate, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + public Task Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate) + { + Ensure.ArgumentNotNull(checkRunUpdate, nameof(checkRunUpdate)); + + return ApiConnection.Patch(ApiUrls.CheckRun(repositoryId, checkRunId), checkRunUpdate, AcceptHeaders.ChecksApiPreview); + } } } diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index 33ec8f055d..72029e19ca 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -32,5 +32,27 @@ public interface ICheckRunsClient /// Details of the Check Run to create Task Create(long repositoryId, NewCheckRun newCheckRun); + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// The updates to the check run + Task Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Updates a Check Run + /// + /// + /// See the Check Runs API documentation for more information. + /// + /// The Id of the repository + /// The Id of the check run + /// The updates to the check run + Task Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 960ccd4155..5cb48c9a21 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3829,6 +3829,29 @@ public static Uri RepositoryLicense(long repositoryId) return "repositories/{0}/license".FormatUri(repositoryId); } + /// + /// Returns the that returns the specified check run. + /// + /// The Id of the repository + /// The check run Id + /// The that returns the specified check run. + public static Uri CheckRun(long repositoryId, long id) + { + return "repositories/{0}/check-runs/{1}".FormatUri(repositoryId, id); + } + + /// + /// Returns the that returns the specified check run. + /// + /// The owner of repo + /// The name of repo + /// The check run Id + /// The that returns the specified check run. + public static Uri CheckRun(string owner, string repo, long id) + { + return "repos/{0}/{1}/check-runs/{2}".FormatUri(owner, repo, id); + } + /// /// Returns the that handles the check runs for the repository. /// @@ -3850,6 +3873,7 @@ public static Uri CheckRuns(string owner, string repo) return "repos/{0}/{1}/check-runs".FormatUri(owner, repo); } + /// /// Returns the that returns the specified check suite. /// /// The Id of the repository diff --git a/Octokit/Models/Request/CheckRunUpdate.cs b/Octokit/Models/Request/CheckRunUpdate.cs new file mode 100644 index 0000000000..bea17fea61 --- /dev/null +++ b/Octokit/Models/Request/CheckRunUpdate.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunUpdate + { + /// + /// Creates a new Check Run + /// + /// Required. The name of the check. For example, "code-coverage". + public CheckRunUpdate(string name) + { + Name = name; + } + + /// + /// Required. The name of the check. For example, "code-coverage". + /// + public string Name { get; private set; } + + /// + /// The URL of the integrator's site that has the full details of the check. + /// + public string DetailsUrl { get; set; } + + /// + /// A reference for the run on the integrator's system. + /// + public string ExternalId { get; set; } + + /// + /// The current status. Can be one of queued, in_progress, or completed. Default: queued + /// + public StringEnum Status { get; set; } + + /// + /// The time that the check run began + /// + public DateTimeOffset StartedAt { get; set; } + + /// + /// Required if you provide a status of completed. The final conclusion of the check. Can be one of success, failure, neutral, cancelled, timed_out, or action_required. When the conclusion is action_required, additional details should be provided on the site specified by details_url. + /// Note: Providing conclusion will automatically set the status parameter to completed. + /// + public StringEnum? Conclusion { get; set; } + + /// + /// Required if you provide conclusion. The time the check completed. + /// + public DateTimeOffset? CompletedAt { get; set; } + + /// + /// Check runs can accept a variety of data in the output object, including a title and summary and can optionally provide descriptive details about the run. + /// + public CheckRunOutput Output { get; set; } + + /// + /// Possible further actions the integrator can perform, which a user may trigger. Each action includes a label, identifier and description. A maximum of three actions are accepted. + /// + public IReadOnlyList Actions { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Name: {0}, Status: {1}, Conclusion: {2}", Name, Status, Conclusion); + } +} diff --git a/Octokit/Models/Request/NewCheckRun.cs b/Octokit/Models/Request/NewCheckRun.cs index fd3e9c06e5..0900e7b4df 100644 --- a/Octokit/Models/Request/NewCheckRun.cs +++ b/Octokit/Models/Request/NewCheckRun.cs @@ -6,70 +6,23 @@ namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class NewCheckRun + public class NewCheckRun : CheckRunUpdate { /// /// Creates a new Check Run /// /// Required. The name of the check. For example, "code-coverage". /// Required. The SHA of the commit. - public NewCheckRun(string name, string headSha) + public NewCheckRun(string name, string headSha) : base(name) { - Name = name; HeadSha = headSha; } - /// - /// Required. The name of the check. For example, "code-coverage". - /// - public string Name { get; private set; } - /// /// Required. The SHA of the commit. /// public string HeadSha { get; private set; } - /// - /// The URL of the integrator's site that has the full details of the check. - /// - public string DetailsUrl { get; set; } - - /// - /// A reference for the run on the integrator's system. - /// - public string ExternalId { get; set; } - - /// - /// The current status. Can be one of queued, in_progress, or completed. Default: queued - /// - public StringEnum Status { get; set; } - - /// - /// The time that the check run began - /// - public DateTimeOffset StartedAt { get; set; } - - /// - /// Required if you provide a status of completed. The final conclusion of the check. Can be one of success, failure, neutral, cancelled, timed_out, or action_required. When the conclusion is action_required, additional details should be provided on the site specified by details_url. - /// Note: Providing conclusion will automatically set the status parameter to completed. - /// - public StringEnum? Conclusion { get; set; } - - /// - /// Required if you provide conclusion. The time the check completed. - /// - public DateTimeOffset? CompletedAt { get; set; } - - /// - /// Check runs can accept a variety of data in the output object, including a title and summary and can optionally provide descriptive details about the run. - /// - public CheckRunOutput Output { get; set; } - - /// - /// Possible further actions the integrator can perform, which a user may trigger. Each action includes a label, identifier and description. A maximum of three actions are accepted. - /// - public IReadOnlyList Actions { get; set; } - - internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Name: {0}, HeadSha: {1}, Status: {2}, Conclusion: {3}", Name, HeadSha, Status, Conclusion); + internal new string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Name: {0}, HeadSha: {1}, Status: {2}, Conclusion: {3}", Name, HeadSha, Status, Conclusion); } } From 1123d54d861a5012798a361854374f0f47367a5d Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 13 Jul 2018 22:45:51 +1000 Subject: [PATCH 05/13] Implement GetAllForReference method --- .../Clients/IObservableCheckRunsClient.cs | 51 +++++ .../Clients/ObservableCheckRunsClient.cs | 94 ++++++++++ .../Clients/CheckRunsClientTests.cs | 84 +++++++++ .../ObservableCheckRunsClientTests.cs | 84 +++++++++ Octokit.Tests/Clients/CheckRunsClientTests.cs | 176 ++++++++++++++++++ .../ObservableCheckRunsClientTests.cs | 176 ++++++++++++++++++ .../ObservableCheckSuitesClientTests.cs | 1 - Octokit/Clients/CheckRunsClient.cs | 103 ++++++++++ Octokit/Clients/ICheckRunsClient.cs | 51 +++++ Octokit/Helpers/ApiUrls.cs | 23 +++ Octokit/Models/Request/CheckRunRequest.cs | 54 ++++++ Octokit/Models/Response/CheckRunsResponse.cs | 32 ++++ 12 files changed, 928 insertions(+), 1 deletion(-) create mode 100644 Octokit/Models/Request/CheckRunRequest.cs create mode 100644 Octokit/Models/Response/CheckRunsResponse.cs diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index c3b9103202..a2912fbc2e 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -53,5 +53,56 @@ public interface IObservableCheckRunsClient /// The Id of the check run /// The updates to the check run IObservable Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + IObservable GetAllForReference(string owner, string name, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + IObservable GetAllForReference(long repositoryId, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index 9d92a5e1cf..bcbdc0124b 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -1,5 +1,6 @@ using System; using System.Reactive.Threading.Tasks; +using Octokit.Reactive.Internal; namespace Octokit.Reactive { @@ -93,5 +94,98 @@ public IObservable Update(long repositoryId, long checkRunId, CheckRun return _client.Update(repositoryId, checkRunId, checkRunUpdate).ToObservable(); } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public IObservable GetAllForReference(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(owner, name, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public IObservable GetAllForReference(long repositoryId, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(repositoryId, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(owner, name, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(repositoryId, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForReference(owner, name, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForReference(repositoryId, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } } } diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 8898de8e20..0150f4fe81 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -139,5 +139,89 @@ public async Task UpdatesCheckRunWithRepositoryId() } } } + + public class TheGetAllForReferenceMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetAllForReferenceMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = 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); + } + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs index 6f87273390..235d7f208a 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -142,5 +142,89 @@ public async Task UpdatesCheckRunWithRepositoryId() } } } + + 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); + } + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs index 7b9c71c051..109aa65107 100644 --- a/Octokit.Tests/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using Xunit; @@ -137,5 +138,180 @@ public async Task EnsuresNonEmptyArguments() await Assert.ThrowsAsync(() => client.Update("fake", "", 1, update)); } } + + public class TheGetAllForReferenceMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForReference("fake", "repo", "ref"); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForReference(1, "ref"); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForReference("fake", "repo", "ref", request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForReference(1, "ref", request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForReference("fake", "repo", "ref", request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForReference(1, "ref", request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForReference(null, "repo", "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", null, "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(null, "repo", "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", null, "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", null, request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "ref", null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(null, "repo", "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", null, "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", null, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "ref", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "ref", request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, null, request)); + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "ref", null)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, null, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "ref", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "ref", request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForReference("", "repo", "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "", "ref")); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "")); + + await Assert.ThrowsAsync(() => client.GetAllForReference("", "repo", "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "", "ref", request)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "", request)); + + await Assert.ThrowsAsync(() => client.GetAllForReference("", "repo", "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "", "ref", request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForReference("fake", "repo", "", request, ApiOptions.None)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "")); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "", request)); + + await Assert.ThrowsAsync(() => client.GetAllForReference(1, "", request, ApiOptions.None)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs index 1f0af2687f..6896e9a77e 100644 --- a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; @@ -126,5 +127,180 @@ public async Task EnsuresNonEmptyArguments() Assert.Throws(() => client.Update("fake", "", 1, update)); } } + + public class TheGetAllForReferenceMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForReference("fake", "repo", "ref"); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForReference(1, "ref"); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForReference("fake", "repo", "ref", request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForReference(1, "ref", request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForReference("fake", "repo", "ref", request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForReference(1, "ref", request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForReference(null, "repo", "ref")); + Assert.Throws(() => client.GetAllForReference("fake", null, "ref")); + Assert.Throws(() => client.GetAllForReference("fake", "repo", null)); + + Assert.Throws(() => client.GetAllForReference(null, "repo", "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", null, "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", null, request)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", null)); + + Assert.Throws(() => client.GetAllForReference(null, "repo", "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", null, "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", null, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", request, null)); + + Assert.Throws(() => client.GetAllForReference(1, null)); + + Assert.Throws(() => client.GetAllForReference(1, null, request)); + Assert.Throws(() => client.GetAllForReference(1, "ref", null)); + + Assert.Throws(() => client.GetAllForReference(1, null, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference(1, "ref", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference(1, "ref", request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForReference("", "repo", "ref")); + Assert.Throws(() => client.GetAllForReference("fake", "", "ref")); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "")); + + Assert.Throws(() => client.GetAllForReference("", "repo", "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", "", "ref", request)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "", request)); + + Assert.Throws(() => client.GetAllForReference("", "repo", "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "", "ref", request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForReference("fake", "repo", "", request, ApiOptions.None)); + + Assert.Throws(() => client.GetAllForReference(1, "")); + + Assert.Throws(() => client.GetAllForReference(1, "", request)); + + Assert.Throws(() => client.GetAllForReference(1, "", request, ApiOptions.None)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs index fd76da6edf..b274e740e6 100644 --- a/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index b04b6df225..99e4f6e7ae 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; namespace Octokit @@ -86,5 +88,106 @@ public Task Update(long repositoryId, long checkRunId, CheckRunUpdate return ApiConnection.Patch(ApiUrls.CheckRun(repositoryId, checkRunId), checkRunUpdate, AcceptHeaders.ChecksApiPreview); } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public Task GetAllForReference(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(owner, name, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + public Task GetAllForReference(long repositoryId, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + + return GetAllForReference(repositoryId, reference, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(owner, name, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + public Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForReference(repositoryId, reference, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForReference(owner, name, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForReference(repositoryId, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } } } diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index 72029e19ca..2d9f4c85e2 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -54,5 +54,56 @@ public interface ICheckRunsClient /// The Id of the check run /// The updates to the check run Task Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + Task GetAllForReference(string owner, string name, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + Task GetAllForReference(long repositoryId, string reference); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The owner of the repository + /// The name of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// + /// The Id of the repository + /// The commit reference (can be a SHA, branch name, or a tag name) + /// Details to filter the request, such as by check name + /// Options to change the API response + Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 5cb48c9a21..15cf2672ca 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3873,6 +3873,29 @@ public static Uri CheckRuns(string owner, string repo) return "repos/{0}/{1}/check-runs".FormatUri(owner, repo); } + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The Id of the repository + /// The git reference + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForReference(long repositoryId, string reference) + { + return "repositories/{0}/commits/{1}/check-runs".FormatUri(repositoryId, reference); + } + + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The owner of repo + /// The name of repo + /// The git reference + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForReference(string owner, string repo, string reference) + { + return "repos/{0}/{1}/commits/{2}/check-runs".FormatUri(owner, repo, reference); + } + /// /// Returns the that returns the specified check suite. /// diff --git a/Octokit/Models/Request/CheckRunRequest.cs b/Octokit/Models/Request/CheckRunRequest.cs new file mode 100644 index 0000000000..f117d3f09e --- /dev/null +++ b/Octokit/Models/Request/CheckRunRequest.cs @@ -0,0 +1,54 @@ +using System.Diagnostics; +using System.Globalization; +using Octokit.Internal; + +namespace Octokit +{ + /// + /// Details to filter a check suite request, such as by App Id or check run name + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunRequest : RequestParameters + { + /// + /// Returns check runs with the specified name. + /// + [Parameter(Key = "check_name")] + public string CheckName { get; set; } + + /// + /// Returns check runs with the specified status. Can be one of queued, in_progress, or completed. + /// + [Parameter(Key = "status")] + public StringEnum? Status { get; set; } + + /// + /// Filters check runs by their completed_at timestamp. Can be one of latest (returning the most recent check runs) or all. Default: latest + /// + [Parameter(Key = "filter")] + public StringEnum? Filter { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "CheckName: {0}, Status: {1}", CheckName, Status); + } + + public enum CheckStatusFilter + { + [Parameter(Value = "queued")] + Queued, + + [Parameter(Value = "in_progress")] + InProgress, + + [Parameter(Value = "completed")] + Completed, + } + + public enum CheckRunCompletedAtFilter + { + [Parameter(Value = "latest")] + Latest, + + [Parameter(Value = "all")] + All + } +} diff --git a/Octokit/Models/Response/CheckRunsResponse.cs b/Octokit/Models/Response/CheckRunsResponse.cs new file mode 100644 index 0000000000..46e3167750 --- /dev/null +++ b/Octokit/Models/Response/CheckRunsResponse.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunsResponse + { + public CheckRunsResponse() + { + } + + public CheckRunsResponse(int totalCount, IReadOnlyList checkRuns) + { + TotalCount = totalCount; + CheckRuns = checkRuns; + } + + /// + /// The total number of check suites that match the request filter + /// + public int TotalCount { get; protected set; } + + /// + /// The retrieved check suites + /// + public IReadOnlyList CheckRuns { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "TotalCount: {0}, CheckRuns: {1}", TotalCount, CheckRuns.Count); + } +} From d3fd29eda6cef73f51ff16b6f93fffc27fa66a35 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Fri, 13 Jul 2018 23:10:09 +1000 Subject: [PATCH 06/13] Implement GetAllForCheckSuite method --- .../Clients/IObservableCheckRunsClient.cs | 51 ++++++ .../Clients/ObservableCheckRunsClient.cs | 86 ++++++++++ .../Clients/CheckRunsClientTests.cs | 85 ++++++++++ .../ObservableCheckRunsClientTests.cs | 84 +++++++++ Octokit.Tests/Clients/CheckRunsClientTests.cs | 159 ++++++++++++++++++ .../ObservableCheckRunsClientTests.cs | 159 ++++++++++++++++++ Octokit/Clients/CheckRunsClient.cs | 94 +++++++++++ Octokit/Clients/ICheckRunsClient.cs | 51 ++++++ Octokit/Helpers/ApiUrls.cs | 23 +++ 9 files changed, 792 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index a2912fbc2e..c0a567b861 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -104,5 +104,56 @@ public interface IObservableCheckRunsClient /// Details to filter the request, such as by check name /// Options to change the API response IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index bcbdc0124b..bf92517d4f 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -187,5 +187,91 @@ public IObservable GetAllForReference(long repositoryId, stri return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForReference(repositoryId, reference), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + public IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + public IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId) + { + return GetAllForCheckSuite(repositoryId, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(repositoryId, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForCheckSuite(owner, name, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); + } } } diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 0150f4fe81..8dd8323c1e 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -223,5 +223,90 @@ public async Task GetsAllCheckRunsWithRepositoryId() } } } + + public class TheGetAllForCheckSuiteMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetAllForCheckSuiteMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = 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); + } + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs index 235d7f208a..6dfd13cf28 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -226,5 +226,89 @@ public async Task GetsAllCheckRunsWithRepositoryId() } } } + + 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); + } + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs index 109aa65107..8d155323a5 100644 --- a/Octokit.Tests/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -313,5 +313,164 @@ public async Task EnsuresNonEmptyArguments() await Assert.ThrowsAsync(() => client.GetAllForReference(1, "", request, ApiOptions.None)); } } + + public class TheGetAllForCheckSuiteMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForCheckSuite("fake", "repo", 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllForCheckSuite(1, 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForCheckSuite("fake", "repo", 1, request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + await client.GetAllForCheckSuite(1, 1, request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForCheckSuite("fake", "repo", 1, request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllForCheckSuite(1, 1, request, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(null, "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(null, "repo", 1, request)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", null, 1, request)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "repo", 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(null, "repo", 1, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", null, 1, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "repo", 1, null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "repo", 1, request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(1, 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(1, 1, null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite(1, 1, request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var request = new CheckRunRequest { CheckName = "build" }; + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("", "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "", 1)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("", "repo", 1, request)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "", 1, request)); + + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("", "repo", 1, request, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs index 6896e9a77e..73a4a327ff 100644 --- a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -302,5 +302,164 @@ public async Task EnsuresNonEmptyArguments() Assert.Throws(() => client.GetAllForReference(1, "", request, ApiOptions.None)); } } + + public class TheGetAllForCheckSuiteMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForCheckSuite("fake", "repo", 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllForCheckSuite(1, 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequest() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForCheckSuite("fake", "repo", 1, request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + + client.GetAllForCheckSuite(1, 1, request); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptions() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForCheckSuite("fake", "repo", 1, request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build", Filter = CheckRunCompletedAtFilter.Latest, Status = CheckStatusFilter.InProgress }; + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllForCheckSuite(1, 1, request, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), + Arg.Is>(x => + x["check_name"] == "build" + && x["status"] == "in_progress" + && x["filter"] == "latest"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForCheckSuite(null, "repo", 1)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", null, 1)); + + Assert.Throws(() => client.GetAllForCheckSuite(null, "repo", 1, request)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", null, 1, request)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "repo", 1, null)); + + Assert.Throws(() => client.GetAllForCheckSuite(null, "repo", 1, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", null, 1, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "repo", 1, null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "repo", 1, request, null)); + + Assert.Throws(() => client.GetAllForCheckSuite(1, 1, null)); + + Assert.Throws(() => client.GetAllForCheckSuite(1, 1, null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite(1, 1, request, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + var request = new CheckRunRequest { CheckName = "build" }; + + Assert.Throws(() => client.GetAllForCheckSuite("", "repo", 1)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "", 1)); + + Assert.Throws(() => client.GetAllForCheckSuite("", "repo", 1, request)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "", 1, request)); + + Assert.Throws(() => client.GetAllForCheckSuite("", "repo", 1, request, ApiOptions.None)); + Assert.Throws(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None)); + } + } } } \ No newline at end of file diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index 99e4f6e7ae..da99f1ce42 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -189,5 +189,99 @@ public async Task GetAllForReference(long repositoryId, strin results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.CheckRuns).ToList()); } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + public Task GetAllForCheckSuite(string owner, string name, long checkSuiteId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + public Task GetAllForCheckSuite(long repositoryId, long checkSuiteId) + { + return GetAllForCheckSuite(repositoryId, checkSuiteId, new CheckRunRequest(), ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(owner, name, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + public Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + + return GetAllForCheckSuite(repositoryId, checkSuiteId, checkRunRequest, ApiOptions.None); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForCheckSuite(owner, name, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + public async Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options) + { + Ensure.ArgumentNotNull(checkRunRequest, nameof(checkRunRequest)); + Ensure.ArgumentNotNull(options, nameof(options)); + + var results = await ApiConnection.GetAll(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options).ConfigureAwait(false); + + return new CheckRunsResponse( + results.Count > 0 ? results.Max(x => x.TotalCount) : 0, + results.SelectMany(x => x.CheckRuns).ToList()); + } } } diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index 2d9f4c85e2..c2534a735c 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -105,5 +105,56 @@ public interface ICheckRunsClient /// Details to filter the request, such as by check name /// Options to change the API response Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + Task GetAllForCheckSuite(string owner, string name, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + Task GetAllForCheckSuite(long repositoryId, long checkSuiteId); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Lists check runs for a check suite using its Id. + /// + /// The Id of the repository + /// The Id of the check suite + /// Details to filter the request, such as by check name + /// Options to change the API response + Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 15cf2672ca..8e042a171a 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3896,6 +3896,29 @@ public static Uri CheckRunsForReference(string owner, string repo, string refere return "repos/{0}/{1}/commits/{2}/check-runs".FormatUri(owner, repo, reference); } + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The Id of the repository + /// The Id of the check suite + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForCheckSuite(long repositoryId, long checkSuiteId) + { + return "repositories/{0}/check-suites/{1}/check-runs".FormatUri(repositoryId, checkSuiteId); + } + + /// + /// Returns the that lists the check runs for the specified reference. + /// + /// The owner of repo + /// The name of repo + /// The Id of the check suite + /// The that returns the check runs for the specified reference. + public static Uri CheckRunsForCheckSuite(string owner, string repo, long checkSuiteId) + { + return "repos/{0}/{1}/check-suites/{2}/check-runs".FormatUri(owner, repo, checkSuiteId); + } + /// /// Returns the that returns the specified check suite. /// From 7a59df500cbc9c2eaaa0ffe5c370f5f272966d8a Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 14 Jul 2018 19:51:19 +1000 Subject: [PATCH 07/13] Implement Get method --- .../Clients/IObservableCheckRunsClient.cs | 15 +++++ .../Clients/ObservableCheckRunsClient.cs | 24 +++++++ .../Clients/CheckRunsClientTests.cs | 66 +++++++++++++++++++ .../ObservableCheckRunsClientTests.cs | 66 +++++++++++++++++++ Octokit.Tests/Clients/CheckRunsClientTests.cs | 51 ++++++++++++++ .../ObservableCheckRunsClientTests.cs | 45 +++++++++++++ Octokit/Clients/CheckRunsClient.cs | 24 +++++++ Octokit/Clients/ICheckRunsClient.cs | 15 +++++ 8 files changed, 306 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index c0a567b861..6ec0c8ec2e 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -155,5 +155,20 @@ public interface IObservableCheckRunsClient /// Details to filter the request, such as by check name /// Options to change the API response IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + IObservable Get(string owner, string name, long checkRunId); + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + IObservable Get(long repositoryId, long checkRunId); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index bf92517d4f..e156c57595 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -273,5 +273,29 @@ public IObservable GetAllForCheckSuite(long repositoryId, lon return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunsForCheckSuite(repositoryId, checkSuiteId), checkRunRequest.ToParametersDictionary(), AcceptHeaders.ChecksApiPreview, options); } + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public IObservable Get(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return _client.Get(owner, name, checkRunId).ToObservable(); + } + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + public IObservable Get(long repositoryId, long checkRunId) + { + return _client.Get(repositoryId, checkRunId).ToObservable(); + } } } diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 8dd8323c1e..06ae17cd5e 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -307,6 +307,72 @@ public async Task GetsAllCheckRunsWithRepositoryId() } } } + + public class TheGetMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = 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); + } + } + } } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs index 6dfd13cf28..af65c81155 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -310,5 +310,71 @@ public async Task GetsAllCheckRunsWithRepositoryId() } } } + + 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); + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs index 8d155323a5..a1b5f8672b 100644 --- a/Octokit.Tests/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -472,5 +472,56 @@ public async Task EnsuresNonEmptyArguments() await Assert.ThrowsAsync(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None)); } } + + public class TheGetMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.Get("fake", "repo", 1); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1"), + null, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.Get(1, 1); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1"), + null, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.Get(null, "repo", 1)); + await Assert.ThrowsAsync(() => client.Get("fake", null, 1)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.Get("", "repo", 1)); + await Assert.ThrowsAsync(() => client.Get("fake", "", 1)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs index 73a4a327ff..608bcda7b0 100644 --- a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -461,5 +461,50 @@ public async Task EnsuresNonEmptyArguments() Assert.Throws(() => client.GetAllForCheckSuite("fake", "", 1, request, ApiOptions.None)); } } + + public class TheGetMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.Get("fake", "repo", 1); + + gitHubClient.Check.Run.Received().Get("fake", "repo", 1); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.Get(1, 1); + + gitHubClient.Check.Run.Received().Get(1, 1); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.Get(null, "repo", 1)); + Assert.Throws(() => client.Get("fake", null, 1)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.Get("", "repo", 1)); + Assert.Throws(() => client.Get("fake", "", 1)); + } + } } } \ No newline at end of file diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index da99f1ce42..593ee24fdc 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -283,5 +283,29 @@ public async Task GetAllForCheckSuite(long repositoryId, long results.Count > 0 ? results.Max(x => x.TotalCount) : 0, results.SelectMany(x => x.CheckRuns).ToList()); } + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public Task Get(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return ApiConnection.Get(ApiUrls.CheckRun(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview); + } + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + public Task Get(long repositoryId, long checkRunId) + { + return ApiConnection.Get(ApiUrls.CheckRun(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview); + } } } diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index c2534a735c..92494bfa14 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -156,5 +156,20 @@ public interface ICheckRunsClient /// Details to filter the request, such as by check name /// Options to change the API response Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); + + /// + /// Gets a single check run using its Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + Task Get(string owner, string name, long checkRunId); + + /// + /// Gets a single check run using its Id. + /// + /// The Id of the repository + /// The Id of the check run + Task Get(long repositoryId, long checkRunId); } } From 7989cca53ab1effc70466ab3fe794d70f1d18295 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 14 Jul 2018 19:49:56 +1000 Subject: [PATCH 08/13] tweak XmlDoc to match github documentation --- .../Clients/IObservableCheckRunsClient.cs | 8 ++++---- Octokit.Reactive/Clients/ObservableCheckRunsClient.cs | 8 ++++---- .../Clients/CheckRunsClientTests.cs | 2 +- Octokit/Clients/CheckRunsClient.cs | 9 ++++----- Octokit/Clients/ICheckRunsClient.cs | 11 +++++------ 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index 6ec0c8ec2e..1d8f4822fd 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -11,7 +11,7 @@ namespace Octokit.Reactive public interface IObservableCheckRunsClient { /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -22,7 +22,7 @@ public interface IObservableCheckRunsClient IObservable Create(string owner, string name, NewCheckRun newCheckRun); /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -32,7 +32,7 @@ public interface IObservableCheckRunsClient IObservable Create(long repositoryId, NewCheckRun newCheckRun); /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -44,7 +44,7 @@ public interface IObservableCheckRunsClient IObservable Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index e156c57595..ccc29c7081 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -28,7 +28,7 @@ public ObservableCheckRunsClient(IGitHubClient client) } /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -46,7 +46,7 @@ public IObservable Create(string owner, string name, NewCheckRun newCh } /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -61,7 +61,7 @@ public IObservable Create(long repositoryId, NewCheckRun newCheckRun) } /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -80,7 +80,7 @@ public IObservable Update(string owner, string name, long checkRunId, } /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 06ae17cd5e..cedbd16b54 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -259,7 +259,7 @@ public async Task GetsAllCheckRuns() CheckName = "name", Status = CheckStatusFilter.InProgress }; - + var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryOwner, repoContext.RepositoryName, created.CheckSuite.Id, request); // Check result diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index 593ee24fdc..dd62b8c093 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -22,7 +21,7 @@ public CheckRunsClient(IApiConnection apiConnection) : base(apiConnection) } /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -40,7 +39,7 @@ public Task Create(string owner, string name, NewCheckRun newCheckRun) } /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -55,7 +54,7 @@ public Task Create(long repositoryId, NewCheckRun newCheckRun) } /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -74,7 +73,7 @@ public Task Update(string owner, string name, long checkRunId, CheckRu } /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index 92494bfa14..253e1fa0dc 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Octokit { @@ -12,7 +11,7 @@ namespace Octokit public interface ICheckRunsClient { /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -23,7 +22,7 @@ public interface ICheckRunsClient Task Create(string owner, string name, NewCheckRun newCheckRun); /// - /// Creates a new Check Run + /// Creates a new check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -33,7 +32,7 @@ public interface ICheckRunsClient Task Create(long repositoryId, NewCheckRun newCheckRun); /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. @@ -45,7 +44,7 @@ public interface ICheckRunsClient Task Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); /// - /// Updates a Check Run + /// Updates a check run for a specific commit in a repository. /// /// /// See the Check Runs API documentation for more information. From 845d532e832af79a3e96e73e6d072bae9b10ed0c Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 14 Jul 2018 22:20:15 +1000 Subject: [PATCH 09/13] Implement GetAllAnnotations Moved CheckRunAnnotation model from Request to Common and added a parameterless ctor, since it is now a response model as well as a request model --- .../Clients/IObservableCheckRunsClient.cs | 33 ++++ .../Clients/ObservableCheckRunsClient.cs | 54 ++++++ .../Clients/CheckRunsClientTests.cs | 172 +++++++++++++----- .../ObservableCheckRunsClientTests.cs | 81 +++++++++ Octokit.Tests/Clients/CheckRunsClientTests.cs | 120 +++++++++++- .../ObservableCheckRunsClientTests.cs | 128 ++++++++++++- Octokit/Clients/CheckRunsClient.cs | 55 ++++++ Octokit/Clients/ICheckRunsClient.cs | 36 +++- Octokit/Helpers/ApiUrls.cs | 23 +++ .../{Request => Common}/CheckRunAnnotation.cs | 6 +- 10 files changed, 645 insertions(+), 63 deletions(-) rename Octokit/Models/{Request => Common}/CheckRunAnnotation.cs (94%) diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index 1d8f4822fd..75a635f057 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -170,5 +170,38 @@ public interface IObservableCheckRunsClient /// The Id of the repository /// The Id of the check run IObservable Get(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + IObservable GetAllAnnotations(string owner, string name, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// + IObservable GetAllAnnotations(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + IObservable GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + IObservable GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index ccc29c7081..d1f47b3d29 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -297,5 +297,59 @@ public IObservable Get(long repositoryId, long checkRunId) { return _client.Get(repositoryId, checkRunId).ToObservable(); } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public IObservable GetAllAnnotations(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllAnnotations(owner, name, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// + public IObservable GetAllAnnotations(long repositoryId, long checkRunId) + { + return GetAllAnnotations(repositoryId, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + public IObservable GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunAnnotations(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + public IObservable GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.CheckRunAnnotations(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } } } diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index cedbd16b54..597935f69f 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Octokit.Tests.Integration.Helpers; using Xunit; @@ -307,70 +309,150 @@ public async Task GetsAllCheckRunsWithRepositoryId() } } } + } + + public class TheGetMethod + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; - public class TheGetMethod + public TheGetMethod() { - IGitHubClient _github; - IGitHubClient _githubAppInstallation; + _github = Helper.GetAuthenticatedClient(); - public TheGetMethod() + // Authenticate as a GitHubApp Installation + _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + } + + [GitHubAppsTest] + public async Task GetsCheckRun() + { + using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { - _github = Helper.GetAuthenticatedClient(); + // 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); - // Authenticate as a GitHubApp Installation - _githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName); + // 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 GetsCheckRun() + [GitHubAppsTest] + public async Task GetsCheckRunWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { - 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) { - // 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"); + Status = CheckStatus.InProgress + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); - // Create a check run for the feature branch - var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) + // 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 + { + IGitHubClient _github; + IGitHubClient _githubAppInstallation; + + public TheGetAllAnnotationsMethod() + { + _github = Helper.GetAuthenticatedClient(); + + // Authenticate as a GitHubApp Installation + _githubAppInstallation = 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 CheckRunOutput("title", "summary") { - Status = CheckStatus.InProgress - }; - var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun); + Annotations = new[] + { + new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + } + } + }; + 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); + // Get the annotations + var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(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); - } + // Check result + Assert.Equal(1, annotations.Count); + Assert.Equal("this is a warning", annotations.First().Message); + Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel); } + } - [GitHubAppsTest] - public async Task GetsCheckRunWithRepositoryId() + [GitHubAppsTest] + public async Task GetsAllAnnotationsWithRepositoryId() + { + using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true })) { - 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 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) + // Create a check run for the feature branch + var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) + { + Status = CheckStatus.InProgress, + Output = new CheckRunOutput("title", "summary") { - Status = CheckStatus.InProgress - }; - var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); + Annotations = new[] + { + new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + } + } + }; + var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun); - // Get the check - var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryId, created.Id); + // Get the annotations + var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryId, created.Id); - // Check result - Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha); - Assert.Equal("name", checkRun.Name); - Assert.Equal(CheckStatus.InProgress, checkRun.Status); - } + // Check result + Assert.Equal(1, annotations.Count); + Assert.Equal("this is a warning", annotations.First().Message); + Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel); } } } diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs index af65c81155..6d275b74e3 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Reactive.Linq; using System.Threading.Tasks; using Octokit.Reactive; @@ -376,5 +377,85 @@ public async Task GetsCheckRunWithRepositoryId() } } } + + 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 CheckRunOutput("title", "summary") + { + Annotations = new[] + { + new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.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(CheckWarningLevel.Warning, annotations.First().WarningLevel); + } + } + + [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 CheckRunOutput("title", "summary") + { + Annotations = new[] + { + new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.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(CheckWarningLevel.Warning, annotations.First().WarningLevel); + } + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/CheckRunsClientTests.cs b/Octokit.Tests/Clients/CheckRunsClientTests.cs index a1b5f8672b..546c9da4e4 100644 --- a/Octokit.Tests/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests/Clients/CheckRunsClientTests.cs @@ -184,7 +184,8 @@ public async Task RequestsCorrectUrlWithRequest() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -204,7 +205,8 @@ public async Task RequestsCorrectUrlWithRequestWithRepositoryId() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -225,7 +227,8 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -246,7 +249,8 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -359,7 +363,8 @@ public async Task RequestsCorrectUrlWithRequest() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -379,7 +384,8 @@ public async Task RequestsCorrectUrlWithRequestWithRepositoryId() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -400,7 +406,8 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -421,7 +428,8 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() connection.Received().GetAll( Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json", @@ -523,5 +531,101 @@ public async Task EnsuresNonEmptyArguments() await Assert.ThrowsAsync(() => client.Get("fake", "", 1)); } } + + public class TheGetAllAnnotationsMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllAnnotations("fake", "repo", 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await client.GetAllAnnotations(1, 1); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllAnnotations("fake", "repo", 1, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + var options = new ApiOptions { PageSize = 1 }; + + await client.GetAllAnnotations(1, 1, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + null, + "application/vnd.github.antiope-preview+json", + options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations(null, "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations(null, "repo", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", null, 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", "repo", 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations(1, 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new CheckRunsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations("", "repo", 1)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", "", 1)); + + await Assert.ThrowsAsync(() => client.GetAllAnnotations("", "repo", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllAnnotations("fake", "", 1, ApiOptions.None)); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs index 608bcda7b0..8391353e4e 100644 --- a/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCheckRunsClientTests.cs @@ -174,7 +174,8 @@ public async Task RequestsCorrectUrlWithRequest() connection.Received().Get>( Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -194,7 +195,8 @@ public async Task RequestsCorrectUrlWithRequestWithRepositoryId() connection.Received().Get>( Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -215,7 +217,9 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions() connection.Received().Get>( Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -236,7 +240,9 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() connection.Received().Get>( Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -349,7 +355,8 @@ public async Task RequestsCorrectUrlWithRequest() connection.Received().Get>( Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -369,7 +376,8 @@ public async Task RequestsCorrectUrlWithRequestWithRepositoryId() connection.Received().Get>( Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 3 + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -390,7 +398,9 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptions() connection.Received().Get>( Arg.Is(u => u.ToString() == "repos/fake/repo/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -411,7 +421,9 @@ public async Task RequestsCorrectUrlWithRequestWithApiOptionsWithRepositoryId() connection.Received().Get>( Arg.Is(u => u.ToString() == "repositories/1/check-suites/1/check-runs"), Arg.Is>(x => - x["check_name"] == "build" + x.Count == 4 + && x["per_page"] == "1" + && x["check_name"] == "build" && x["status"] == "in_progress" && x["filter"] == "latest"), "application/vnd.github.antiope-preview+json"); @@ -506,5 +518,105 @@ public async Task EnsuresNonEmptyArguments() Assert.Throws(() => client.Get("fake", "", 1)); } } + + public class TheGetAllAnnotationsMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllAnnotations("fake", "repo", 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + client.GetAllAnnotations(1, 1); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + Args.EmptyDictionary, + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllAnnotations("fake", "repo", 1, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repos/fake/repo/check-runs/1/annotations"), + Arg.Is>(x => + x.Count == 1 + && x["per_page"] == "1"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableCheckRunsClient(gitHubClient); + + var options = new ApiOptions { PageSize = 1 }; + + client.GetAllAnnotations(1, 1, options); + + connection.Received().Get>( + Arg.Is(u => u.ToString() == "repositories/1/check-runs/1/annotations"), + Arg.Is>(x => + x.Count == 1 + && x["per_page"] == "1"), + "application/vnd.github.antiope-preview+json"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.GetAllAnnotations(null, "repo", 1)); + Assert.Throws(() => client.GetAllAnnotations("fake", null, 1)); + + Assert.Throws(() => client.GetAllAnnotations(null, "repo", 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllAnnotations("fake", null, 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllAnnotations("fake", "repo", 1, null)); + + Assert.Throws(() => client.GetAllAnnotations(1, 1, null)); + } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var gitHubClient = Substitute.For(); + var client = new ObservableCheckRunsClient(gitHubClient); + + Assert.Throws(() => client.GetAllAnnotations("", "repo", 1)); + Assert.Throws(() => client.GetAllAnnotations("fake", "", 1)); + + Assert.Throws(() => client.GetAllAnnotations("", "repo", 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllAnnotations("fake", "", 1, ApiOptions.None)); + } + } } } \ No newline at end of file diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index dd62b8c093..bfed35edd1 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -306,5 +307,59 @@ public Task Get(long repositoryId, long checkRunId) { return ApiConnection.Get(ApiUrls.CheckRun(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview); } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + public Task> GetAllAnnotations(string owner, string name, long checkRunId) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + + return GetAllAnnotations(owner, name, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// + public Task> GetAllAnnotations(long repositoryId, long checkRunId) + { + return GetAllAnnotations(repositoryId, checkRunId, ApiOptions.None); + } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + public Task> GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.CheckRunAnnotations(owner, name, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + public Task> GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.CheckRunAnnotations(repositoryId, checkRunId), null, AcceptHeaders.ChecksApiPreview, options); + } } } diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index 253e1fa0dc..c52be32050 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Octokit { @@ -170,5 +171,38 @@ public interface ICheckRunsClient /// The Id of the repository /// The Id of the check run Task Get(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + Task> GetAllAnnotations(string owner, string name, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// + Task> GetAllAnnotations(long repositoryId, long checkRunId); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The owner of the repository + /// The name of the repository + /// The Id of the check run + /// Options to change the API response + Task> GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options); + + /// + /// Lists annotations for a check run using the check run Id. + /// + /// The Id of the repository + /// The Id of the check run + /// Options to change the API response + Task> GetAllAnnotations(long repositoryId, long checkRunId, ApiOptions options); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 8e042a171a..c7c8d3179b 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -3919,6 +3919,29 @@ public static Uri CheckRunsForCheckSuite(string owner, string repo, long checkSu return "repos/{0}/{1}/check-suites/{2}/check-runs".FormatUri(owner, repo, checkSuiteId); } + /// + /// Returns the that lists the annotations for the specified check run. + /// + /// The Id of the repository + /// The Id of the check run + /// The that returns the annotations for the specified check run. + public static Uri CheckRunAnnotations(long repositoryId, long checkRunId) + { + return "repositories/{0}/check-runs/{1}/annotations".FormatUri(repositoryId, checkRunId); + } + + /// + /// Returns the that lists the annotations for the specified check run. + /// + /// The owner of repo + /// The name of repo + /// The Id of the check run + /// The that returns the annotations for the specified check run. + public static Uri CheckRunAnnotations(string owner, string repo, long checkRunId) + { + return "repos/{0}/{1}/check-runs/{2}/annotations".FormatUri(owner, repo, checkRunId); + } + /// /// Returns the that returns the specified check suite. /// diff --git a/Octokit/Models/Request/CheckRunAnnotation.cs b/Octokit/Models/Common/CheckRunAnnotation.cs similarity index 94% rename from Octokit/Models/Request/CheckRunAnnotation.cs rename to Octokit/Models/Common/CheckRunAnnotation.cs index acea53638b..65eac0df5f 100644 --- a/Octokit/Models/Request/CheckRunAnnotation.cs +++ b/Octokit/Models/Common/CheckRunAnnotation.cs @@ -6,6 +6,10 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class CheckRunAnnotation { + public CheckRunAnnotation() + { + } + /// /// Constructs a CheckRunAnnotation request object /// @@ -65,6 +69,6 @@ public CheckRunAnnotation(string filename, string blobHref, int startLine, int e /// public string RawDetails { get; set; } - internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Title: {0}, Filename: {1}, WarningLevel: {2}", Title ?? "", Filename, WarningLevel.DebuggerDisplay); + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Filename: {0}, StartLine: {1}, WarningLevel: {2}", Filename, StartLine, WarningLevel.DebuggerDisplay); } } \ No newline at end of file From 6e92edbfa93a3a5c766c18aa3b31c1b1454d7d7d Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 14 Jul 2018 22:39:27 +1000 Subject: [PATCH 10/13] Split common CheckRunAnnotation model into separate response and request models due to different field and ctor requirements Rename other CheckRun request sub classes to be consistent with NewCheckRunAnnotation (eg NewCheckRunOutput, NewCheckRunImage, etc) --- .../Clients/CheckRunsClientTests.cs | 8 +-- .../ObservableCheckRunsClientTests.cs | 8 +-- Octokit/Models/Request/CheckRunUpdate.cs | 4 +- ...CheckRunAction.cs => NewCheckRunAction.cs} | 4 +- .../NewCheckRunAnnotation.cs} | 10 +-- .../{CheckRunImage.cs => NewCheckRunImage.cs} | 4 +- ...CheckRunOutput.cs => NewCheckRunOutput.cs} | 8 +-- Octokit/Models/Response/CheckRunAnnotation.cs | 61 +++++++++++++++++++ 8 files changed, 82 insertions(+), 25 deletions(-) rename Octokit/Models/Request/{CheckRunAction.cs => NewCheckRunAction.cs} (92%) rename Octokit/Models/{Common/CheckRunAnnotation.cs => Request/NewCheckRunAnnotation.cs} (91%) rename Octokit/Models/Request/{CheckRunImage.cs => NewCheckRunImage.cs} (91%) rename Octokit/Models/Request/{CheckRunOutput.cs => NewCheckRunOutput.cs} (86%) create mode 100644 Octokit/Models/Response/CheckRunAnnotation.cs diff --git a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs index 597935f69f..7adaf503e3 100644 --- a/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CheckRunsClientTests.cs @@ -403,11 +403,11 @@ public async Task GetsAllAnnotations() var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) { Status = CheckStatus.InProgress, - Output = new CheckRunOutput("title", "summary") + Output = new NewCheckRunOutput("title", "summary") { Annotations = new[] { - new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") } } }; @@ -436,11 +436,11 @@ public async Task GetsAllAnnotationsWithRepositoryId() var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) { Status = CheckStatus.InProgress, - Output = new CheckRunOutput("title", "summary") + Output = new NewCheckRunOutput("title", "summary") { Annotations = new[] { - new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") } } }; diff --git a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs index 6d275b74e3..7c8352c45f 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs @@ -404,11 +404,11 @@ public async Task GetsAllAnnotations() var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) { Status = CheckStatus.InProgress, - Output = new CheckRunOutput("title", "summary") + Output = new NewCheckRunOutput("title", "summary") { Annotations = new[] { - new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") } } }; @@ -437,11 +437,11 @@ public async Task GetsAllAnnotationsWithRepositoryId() var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha) { Status = CheckStatus.InProgress, - Output = new CheckRunOutput("title", "summary") + Output = new NewCheckRunOutput("title", "summary") { Annotations = new[] { - new CheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") + new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning") } } }; diff --git a/Octokit/Models/Request/CheckRunUpdate.cs b/Octokit/Models/Request/CheckRunUpdate.cs index bea17fea61..b42ca3cd01 100644 --- a/Octokit/Models/Request/CheckRunUpdate.cs +++ b/Octokit/Models/Request/CheckRunUpdate.cs @@ -56,12 +56,12 @@ public CheckRunUpdate(string name) /// /// Check runs can accept a variety of data in the output object, including a title and summary and can optionally provide descriptive details about the run. /// - public CheckRunOutput Output { get; set; } + public NewCheckRunOutput Output { get; set; } /// /// Possible further actions the integrator can perform, which a user may trigger. Each action includes a label, identifier and description. A maximum of three actions are accepted. /// - public IReadOnlyList Actions { get; set; } + public IReadOnlyList Actions { get; set; } internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Name: {0}, Status: {1}, Conclusion: {2}", Name, Status, Conclusion); } diff --git a/Octokit/Models/Request/CheckRunAction.cs b/Octokit/Models/Request/NewCheckRunAction.cs similarity index 92% rename from Octokit/Models/Request/CheckRunAction.cs rename to Octokit/Models/Request/NewCheckRunAction.cs index f725889798..ff75c39848 100644 --- a/Octokit/Models/Request/CheckRunAction.cs +++ b/Octokit/Models/Request/NewCheckRunAction.cs @@ -4,7 +4,7 @@ namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class CheckRunAction + public class NewCheckRunAction { /// /// Constructs a CheckRunAction request object @@ -12,7 +12,7 @@ public class CheckRunAction /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters. /// Required. A short explanation of what this action would do. The maximum size is 40 characters. /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters. - public CheckRunAction(string label, string description, string identifier) + public NewCheckRunAction(string label, string description, string identifier) { Label = label; Description = description; diff --git a/Octokit/Models/Common/CheckRunAnnotation.cs b/Octokit/Models/Request/NewCheckRunAnnotation.cs similarity index 91% rename from Octokit/Models/Common/CheckRunAnnotation.cs rename to Octokit/Models/Request/NewCheckRunAnnotation.cs index 65eac0df5f..86ff26c221 100644 --- a/Octokit/Models/Common/CheckRunAnnotation.cs +++ b/Octokit/Models/Request/NewCheckRunAnnotation.cs @@ -4,14 +4,10 @@ namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class CheckRunAnnotation + public class NewCheckRunAnnotation { - public CheckRunAnnotation() - { - } - /// - /// Constructs a CheckRunAnnotation request object + /// Constructs a CheckRunCreateAnnotation request object /// /// Required. The path of the file to add an annotation to. For example, assets/css/main.css. /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename. @@ -19,7 +15,7 @@ public CheckRunAnnotation() /// Required. The end line of the annotation. /// Required. The warning level of the annotation. Can be one of notice, warning, or failure. /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB. - public CheckRunAnnotation(string filename, string blobHref, int startLine, int endLine, CheckWarningLevel warningLevel, string message) + public NewCheckRunAnnotation(string filename, string blobHref, int startLine, int endLine, CheckWarningLevel warningLevel, string message) { Filename = filename; BlobHref = blobHref; diff --git a/Octokit/Models/Request/CheckRunImage.cs b/Octokit/Models/Request/NewCheckRunImage.cs similarity index 91% rename from Octokit/Models/Request/CheckRunImage.cs rename to Octokit/Models/Request/NewCheckRunImage.cs index cb9f4c222d..90d793f243 100644 --- a/Octokit/Models/Request/CheckRunImage.cs +++ b/Octokit/Models/Request/NewCheckRunImage.cs @@ -4,14 +4,14 @@ namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class CheckRunImage + public class NewCheckRunImage { /// /// Constructs a CheckRunImage request object /// /// Required. The alternative text for the image. /// Required. The full URL of the image. - public CheckRunImage(string alt, string imageUrl) + public NewCheckRunImage(string alt, string imageUrl) { Alt = alt; ImageUrl = imageUrl; diff --git a/Octokit/Models/Request/CheckRunOutput.cs b/Octokit/Models/Request/NewCheckRunOutput.cs similarity index 86% rename from Octokit/Models/Request/CheckRunOutput.cs rename to Octokit/Models/Request/NewCheckRunOutput.cs index fd41ad21de..d7899ee237 100644 --- a/Octokit/Models/Request/CheckRunOutput.cs +++ b/Octokit/Models/Request/NewCheckRunOutput.cs @@ -5,14 +5,14 @@ namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class CheckRunOutput + public class NewCheckRunOutput { /// /// Constructs a CheckRunOutput request object /// /// Required. The title of the check run. /// Required. The summary of the check run. This parameter supports Markdown. - public CheckRunOutput(string title, string summary) + public NewCheckRunOutput(string title, string summary) { Title = title; Summary = summary; @@ -36,12 +36,12 @@ public CheckRunOutput(string title, string summary) /// /// Adds information from your analysis to specific lines of code. Annotations are visible in GitHub's pull request UI. For details about annotations in the UI, see "About status checks". /// - public IReadOnlyList Annotations { get; set; } + public IReadOnlyList Annotations { get; set; } /// /// Adds images to the output displayed in the GitHub pull request UI. /// - public IReadOnlyList Images { get; set; } + public IReadOnlyList Images { get; set; } internal string DebuggerDisplay => string.Format(CultureInfo.CurrentCulture, "Title: {0}", Title); } diff --git a/Octokit/Models/Response/CheckRunAnnotation.cs b/Octokit/Models/Response/CheckRunAnnotation.cs new file mode 100644 index 0000000000..f74ae0b780 --- /dev/null +++ b/Octokit/Models/Response/CheckRunAnnotation.cs @@ -0,0 +1,61 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CheckRunAnnotation + { + public CheckRunAnnotation() + { + } + + public CheckRunAnnotation(string filename, string blobHref, int startLine, int endLine, CheckWarningLevel warningLevel, string message, string title, string rawDetails) + { + Filename = filename; + BlobHref = blobHref; + StartLine = startLine; + EndLine = endLine; + WarningLevel = warningLevel; + Message = message; + RawDetails = rawDetails; + } + + /// + /// The path of the file the annotation refers to. For example, assets/css/main.css. + /// + public string Filename { get; protected set; } + + /// + /// The file's full blob URL. + /// + public string BlobHref { get; protected set; } + + /// + /// The start line of the annotation. + /// + public int StartLine { get; protected set; } + + /// + /// The end line of the annotation. + /// + public int EndLine { get; protected set; } + + /// + /// The warning level of the annotation. Can be one of notice, warning, or failure. + /// + public StringEnum WarningLevel { get; protected set; } + + /// + /// A short description of the feedback for these lines of code. + /// + public string Message { get; protected set; } + + /// + /// Details about this annotation. + /// + public string RawDetails { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Filename: {0}, StartLine: {1}, WarningLevel: {2}", Filename, StartLine, WarningLevel.DebuggerDisplay); + } +} \ No newline at end of file From 5370c7f664dfa18d2ba0a8f92d85febd50aa9814 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Tue, 17 Jul 2018 20:25:18 +1000 Subject: [PATCH 11/13] add title field back into CheckRunAnnotation --- Octokit/Models/Response/CheckRunAnnotation.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Octokit/Models/Response/CheckRunAnnotation.cs b/Octokit/Models/Response/CheckRunAnnotation.cs index f74ae0b780..3409f57659 100644 --- a/Octokit/Models/Response/CheckRunAnnotation.cs +++ b/Octokit/Models/Response/CheckRunAnnotation.cs @@ -18,6 +18,7 @@ public CheckRunAnnotation(string filename, string blobHref, int startLine, int e EndLine = endLine; WarningLevel = warningLevel; Message = message; + Title = title; RawDetails = rawDetails; } @@ -51,6 +52,11 @@ public CheckRunAnnotation(string filename, string blobHref, int startLine, int e /// public string Message { get; protected set; } + /// + /// The title that represents the annotation. + /// + public string Title { get; set; } + /// /// Details about this annotation. /// From 80ed690fe654c9f5201259be89e714b1c801270b Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 18 Jul 2018 20:17:14 +1000 Subject: [PATCH 12/13] fix up XmlDocs --- .../Clients/IObservableCheckRunsClient.cs | 100 +++++++++++++---- .../Clients/ObservableCheckRunsClient.cs | 102 +++++++++++++----- Octokit/Clients/CheckRunsClient.cs | 102 +++++++++++++----- Octokit/Clients/ICheckRunsClient.cs | 100 +++++++++++++---- Octokit/Clients/ICheckSuitesClient.cs | 2 +- Octokit/Clients/IChecksClient.cs | 6 +- Octokit/Models/Request/NewCheckRun.cs | 6 +- Octokit/Models/Request/NewCheckRunAction.cs | 12 +-- .../Models/Request/NewCheckRunAnnotation.cs | 28 ++--- Octokit/Models/Request/NewCheckRunImage.cs | 10 +- Octokit/Models/Request/NewCheckRunOutput.cs | 14 +-- Octokit/Models/Request/NewCheckSuite.cs | 4 +- Octokit/Models/Response/CheckRun.cs | 10 +- Octokit/Models/Response/CheckRunAnnotation.cs | 14 +-- .../Models/Response/CheckRunOutputResponse.cs | 2 +- Octokit/Models/Response/CheckRunsResponse.cs | 4 +- Octokit/Models/Response/CheckSuite.cs | 22 ++-- 17 files changed, 377 insertions(+), 161 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs index 75a635f057..9980baf349 100644 --- a/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCheckRunsClient.cs @@ -3,7 +3,7 @@ namespace Octokit.Reactive { /// - /// A client for GitHub's Check Runs API. + /// A client for GitHub's Check Runs API /// /// /// See the Check Runs API documentation for more information. @@ -11,7 +11,7 @@ namespace Octokit.Reactive public interface IObservableCheckRunsClient { /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -22,7 +22,7 @@ public interface IObservableCheckRunsClient IObservable Create(string owner, string name, NewCheckRun newCheckRun); /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -32,7 +32,7 @@ public interface IObservableCheckRunsClient IObservable Create(long repositoryId, NewCheckRun newCheckRun); /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -44,7 +44,7 @@ public interface IObservableCheckRunsClient IObservable Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -55,23 +55,32 @@ public interface IObservableCheckRunsClient IObservable Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) IObservable GetAllForReference(string owner, string name, string reference); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) IObservable GetAllForReference(long repositoryId, string reference); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -79,16 +88,22 @@ public interface IObservableCheckRunsClient IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -97,8 +112,11 @@ public interface IObservableCheckRunsClient IObservable GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name @@ -106,23 +124,32 @@ public interface IObservableCheckRunsClient IObservable GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -130,16 +157,22 @@ public interface IObservableCheckRunsClient IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -148,8 +181,11 @@ public interface IObservableCheckRunsClient IObservable GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name @@ -157,39 +193,54 @@ public interface IObservableCheckRunsClient IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run IObservable Get(string owner, string name, long checkRunId); /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run IObservable Get(long repositoryId, long checkRunId); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run IObservable GetAllAnnotations(string owner, string name, long checkRunId); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// IObservable GetAllAnnotations(long repositoryId, long checkRunId); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -197,8 +248,11 @@ public interface IObservableCheckRunsClient IObservable GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// Options to change the API response diff --git a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs index d1f47b3d29..ee5ebb5f03 100644 --- a/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCheckRunsClient.cs @@ -5,7 +5,7 @@ namespace Octokit.Reactive { /// - /// A client for GitHub's Check Runs API. + /// A client for GitHub's Check Runs API /// /// /// See the Check Runs API documentation for more information. @@ -16,7 +16,7 @@ public class ObservableCheckRunsClient : IObservableCheckRunsClient readonly IConnection _connection; /// - /// Initializes a new GitHub Check Runs API client. + /// Initializes a new GitHub Check Runs API client /// /// An used to make the requests public ObservableCheckRunsClient(IGitHubClient client) @@ -28,7 +28,7 @@ public ObservableCheckRunsClient(IGitHubClient client) } /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -46,7 +46,7 @@ public IObservable Create(string owner, string name, NewCheckRun newCh } /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -61,7 +61,7 @@ public IObservable Create(long repositoryId, NewCheckRun newCheckRun) } /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -80,7 +80,7 @@ public IObservable Update(string owner, string name, long checkRunId, } /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -96,8 +96,11 @@ public IObservable Update(long repositoryId, long checkRunId, CheckRun } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -111,8 +114,11 @@ public IObservable GetAllForReference(string owner, string na } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) public IObservable GetAllForReference(long repositoryId, string reference) @@ -123,8 +129,11 @@ public IObservable GetAllForReference(long repositoryId, stri } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -140,8 +149,11 @@ public IObservable GetAllForReference(string owner, string na } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name @@ -154,8 +166,11 @@ public IObservable GetAllForReference(long repositoryId, stri } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -173,8 +188,11 @@ public IObservable GetAllForReference(string owner, string na } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name @@ -189,8 +207,11 @@ public IObservable GetAllForReference(long repositoryId, stri } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -203,8 +224,11 @@ public IObservable GetAllForCheckSuite(string owner, string n } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite public IObservable GetAllForCheckSuite(long repositoryId, long checkSuiteId) @@ -213,8 +237,11 @@ public IObservable GetAllForCheckSuite(long repositoryId, lon } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -229,8 +256,11 @@ public IObservable GetAllForCheckSuite(string owner, string n } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name @@ -242,8 +272,11 @@ public IObservable GetAllForCheckSuite(long repositoryId, lon } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -260,8 +293,11 @@ public IObservable GetAllForCheckSuite(string owner, string n } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name @@ -275,8 +311,11 @@ public IObservable GetAllForCheckSuite(long repositoryId, lon } /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -289,8 +328,11 @@ public IObservable Get(string owner, string name, long checkRunId) } /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run public IObservable Get(long repositoryId, long checkRunId) @@ -299,8 +341,11 @@ public IObservable Get(long repositoryId, long checkRunId) } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -313,8 +358,11 @@ public IObservable GetAllAnnotations(string owner, string na } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// @@ -324,8 +372,11 @@ public IObservable GetAllAnnotations(long repositoryId, long } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -340,8 +391,11 @@ public IObservable GetAllAnnotations(string owner, string na } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// Options to change the API response diff --git a/Octokit/Clients/CheckRunsClient.cs b/Octokit/Clients/CheckRunsClient.cs index bfed35edd1..2bbae335a0 100644 --- a/Octokit/Clients/CheckRunsClient.cs +++ b/Octokit/Clients/CheckRunsClient.cs @@ -6,7 +6,7 @@ namespace Octokit { /// - /// A client for GitHub's Check Runs API. + /// A client for GitHub's Check Runs API /// /// /// See the Check Runs API documentation for more information. @@ -14,7 +14,7 @@ namespace Octokit public class CheckRunsClient : ApiClient, ICheckRunsClient { /// - /// Initializes a new GitHub Check Runs API client. + /// Initializes a new GitHub Check Runs API client /// /// An API connection public CheckRunsClient(IApiConnection apiConnection) : base(apiConnection) @@ -22,7 +22,7 @@ public CheckRunsClient(IApiConnection apiConnection) : base(apiConnection) } /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -40,7 +40,7 @@ public Task Create(string owner, string name, NewCheckRun newCheckRun) } /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -55,7 +55,7 @@ public Task Create(long repositoryId, NewCheckRun newCheckRun) } /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -74,7 +74,7 @@ public Task Update(string owner, string name, long checkRunId, CheckRu } /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -90,8 +90,11 @@ public Task Update(long repositoryId, long checkRunId, CheckRunUpdate } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -105,8 +108,11 @@ public Task GetAllForReference(string owner, string name, str } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) public Task GetAllForReference(long repositoryId, string reference) @@ -117,8 +123,11 @@ public Task GetAllForReference(long repositoryId, string refe } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -134,8 +143,11 @@ public Task GetAllForReference(string owner, string name, str } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name @@ -148,8 +160,11 @@ public Task GetAllForReference(long repositoryId, string refe } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -171,8 +186,11 @@ public async Task GetAllForReference(string owner, string nam } /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name @@ -191,8 +209,11 @@ public async Task GetAllForReference(long repositoryId, strin } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -205,8 +226,11 @@ public Task GetAllForCheckSuite(string owner, string name, lo } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite public Task GetAllForCheckSuite(long repositoryId, long checkSuiteId) @@ -215,8 +239,11 @@ public Task GetAllForCheckSuite(long repositoryId, long check } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -231,8 +258,11 @@ public Task GetAllForCheckSuite(string owner, string name, lo } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name @@ -244,8 +274,11 @@ public Task GetAllForCheckSuite(long repositoryId, long check } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -266,8 +299,11 @@ public async Task GetAllForCheckSuite(string owner, string na } /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name @@ -285,8 +321,11 @@ public async Task GetAllForCheckSuite(long repositoryId, long } /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -299,8 +338,11 @@ public Task Get(string owner, string name, long checkRunId) } /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run public Task Get(long repositoryId, long checkRunId) @@ -309,8 +351,11 @@ public Task Get(long repositoryId, long checkRunId) } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -323,8 +368,11 @@ public Task> GetAllAnnotations(string owner, s } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// @@ -334,8 +382,11 @@ public Task> GetAllAnnotations(long repository } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -350,8 +401,11 @@ public Task> GetAllAnnotations(string owner, s } /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// Options to change the API response diff --git a/Octokit/Clients/ICheckRunsClient.cs b/Octokit/Clients/ICheckRunsClient.cs index c52be32050..2a70b810b6 100644 --- a/Octokit/Clients/ICheckRunsClient.cs +++ b/Octokit/Clients/ICheckRunsClient.cs @@ -4,7 +4,7 @@ namespace Octokit { /// - /// A client for GitHub's Check Runs API. + /// A client for GitHub's Check Runs API /// /// /// See the Check Runs API documentation for more information. @@ -12,7 +12,7 @@ namespace Octokit public interface ICheckRunsClient { /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -23,7 +23,7 @@ public interface ICheckRunsClient Task Create(string owner, string name, NewCheckRun newCheckRun); /// - /// Creates a new check run for a specific commit in a repository. + /// Creates a new check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -33,7 +33,7 @@ public interface ICheckRunsClient Task Create(long repositoryId, NewCheckRun newCheckRun); /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -45,7 +45,7 @@ public interface ICheckRunsClient Task Update(string owner, string name, long checkRunId, CheckRunUpdate checkRunUpdate); /// - /// Updates a check run for a specific commit in a repository. + /// Updates a check run for a specific commit in a repository /// /// /// See the Check Runs API documentation for more information. @@ -56,23 +56,32 @@ public interface ICheckRunsClient Task Update(long repositoryId, long checkRunId, CheckRunUpdate checkRunUpdate); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) Task GetAllForReference(string owner, string name, string reference); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) Task GetAllForReference(long repositoryId, string reference); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -80,16 +89,22 @@ public interface ICheckRunsClient Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The commit reference (can be a SHA, branch name, or a tag name) @@ -98,8 +113,11 @@ public interface ICheckRunsClient Task GetAllForReference(string owner, string name, string reference, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name. + /// Lists check runs for a commit ref. The ref can be a SHA, branch name, or a tag name /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The commit reference (can be a SHA, branch name, or a tag name) /// Details to filter the request, such as by check name @@ -107,23 +125,32 @@ public interface ICheckRunsClient Task GetAllForReference(long repositoryId, string reference, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite Task GetAllForCheckSuite(string owner, string name, long checkSuiteId); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite Task GetAllForCheckSuite(long repositoryId, long checkSuiteId); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -131,16 +158,22 @@ public interface ICheckRunsClient Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check suite @@ -149,8 +182,11 @@ public interface ICheckRunsClient Task GetAllForCheckSuite(string owner, string name, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Lists check runs for a check suite using its Id. + /// Lists check runs for a check suite using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check suite /// Details to filter the request, such as by check name @@ -158,39 +194,54 @@ public interface ICheckRunsClient Task GetAllForCheckSuite(long repositoryId, long checkSuiteId, CheckRunRequest checkRunRequest, ApiOptions options); /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run Task Get(string owner, string name, long checkRunId); /// - /// Gets a single check run using its Id. + /// Gets a single check run using its Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run Task Get(long repositoryId, long checkRunId); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run Task> GetAllAnnotations(string owner, string name, long checkRunId); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// Task> GetAllAnnotations(long repositoryId, long checkRunId); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The owner of the repository /// The name of the repository /// The Id of the check run @@ -198,8 +249,11 @@ public interface ICheckRunsClient Task> GetAllAnnotations(string owner, string name, long checkRunId, ApiOptions options); /// - /// Lists annotations for a check run using the check run Id. + /// Lists annotations for a check run using the check run Id /// + /// + /// See the Check Runs API documentation for more information. + /// /// The Id of the repository /// The Id of the check run /// Options to change the API response diff --git a/Octokit/Clients/ICheckSuitesClient.cs b/Octokit/Clients/ICheckSuitesClient.cs index 1e35b8190f..836920938b 100644 --- a/Octokit/Clients/ICheckSuitesClient.cs +++ b/Octokit/Clients/ICheckSuitesClient.cs @@ -3,7 +3,7 @@ namespace Octokit { /// - /// A client for GitHub's Check Suites API. + /// A client for GitHub's Check Suites API /// /// /// See the Check Suites API documentation for more information. diff --git a/Octokit/Clients/IChecksClient.cs b/Octokit/Clients/IChecksClient.cs index a816344a43..cf6401e3df 100644 --- a/Octokit/Clients/IChecksClient.cs +++ b/Octokit/Clients/IChecksClient.cs @@ -1,7 +1,7 @@ namespace Octokit { /// - /// A client for GitHub's Checks API. + /// A client for GitHub's Checks API /// /// /// See the Checks API documentation for more information. @@ -9,7 +9,7 @@ public interface IChecksClient { /// - /// A client for GitHub's Check Runs API. + /// A client for GitHub's Check Runs API /// /// /// See the Check Runs API documentation for more information. @@ -17,7 +17,7 @@ public interface IChecksClient ICheckRunsClient Run { get; } /// - /// A client for GitHub's Check Suites API. + /// A client for GitHub's Check Suites API /// /// /// See the Check Suites API documentation for more information. diff --git a/Octokit/Models/Request/NewCheckRun.cs b/Octokit/Models/Request/NewCheckRun.cs index 0900e7b4df..6828a32c3e 100644 --- a/Octokit/Models/Request/NewCheckRun.cs +++ b/Octokit/Models/Request/NewCheckRun.cs @@ -11,15 +11,15 @@ public class NewCheckRun : CheckRunUpdate /// /// Creates a new Check Run /// - /// Required. The name of the check. For example, "code-coverage". - /// Required. The SHA of the commit. + /// Required. The name of the check. For example, "code-coverage" + /// Required. The SHA of the commit public NewCheckRun(string name, string headSha) : base(name) { HeadSha = headSha; } /// - /// Required. The SHA of the commit. + /// Required. The SHA of the commit /// public string HeadSha { get; private set; } diff --git a/Octokit/Models/Request/NewCheckRunAction.cs b/Octokit/Models/Request/NewCheckRunAction.cs index ff75c39848..fcbc21989f 100644 --- a/Octokit/Models/Request/NewCheckRunAction.cs +++ b/Octokit/Models/Request/NewCheckRunAction.cs @@ -9,9 +9,9 @@ public class NewCheckRunAction /// /// Constructs a CheckRunAction request object /// - /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters. - /// Required. A short explanation of what this action would do. The maximum size is 40 characters. - /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters. + /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters + /// Required. A short explanation of what this action would do. The maximum size is 40 characters + /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters public NewCheckRunAction(string label, string description, string identifier) { Label = label; @@ -20,17 +20,17 @@ public NewCheckRunAction(string label, string description, string identifier) } /// - /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters. + /// Required. The text to be displayed on a button in the web UI. The maximum size is 20 characters /// public string Label { get; protected set; } /// - /// Required. A short explanation of what this action would do. The maximum size is 40 characters. + /// Required. A short explanation of what this action would do. The maximum size is 40 characters /// public string Description { get; protected set; } /// - /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters. + /// Required. A reference for the action on the integrator's system. The maximum size is 20 characters /// public string Identifier { get; protected set; } diff --git a/Octokit/Models/Request/NewCheckRunAnnotation.cs b/Octokit/Models/Request/NewCheckRunAnnotation.cs index 86ff26c221..3b0eced38b 100644 --- a/Octokit/Models/Request/NewCheckRunAnnotation.cs +++ b/Octokit/Models/Request/NewCheckRunAnnotation.cs @@ -9,12 +9,12 @@ public class NewCheckRunAnnotation /// /// Constructs a CheckRunCreateAnnotation request object /// - /// Required. The path of the file to add an annotation to. For example, assets/css/main.css. - /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename. - /// Required. The start line of the annotation. - /// Required. The end line of the annotation. - /// Required. The warning level of the annotation. Can be one of notice, warning, or failure. - /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB. + /// Required. The path of the file to add an annotation to. For example, assets/css/main.css + /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename + /// Required. The start line of the annotation + /// Required. The end line of the annotation + /// Required. The warning level of the annotation. Can be one of notice, warning, or failure + /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB public NewCheckRunAnnotation(string filename, string blobHref, int startLine, int endLine, CheckWarningLevel warningLevel, string message) { Filename = filename; @@ -26,42 +26,42 @@ public NewCheckRunAnnotation(string filename, string blobHref, int startLine, in } /// - /// Required. The path of the file to add an annotation to. For example, assets/css/main.css. + /// Required. The path of the file to add an annotation to. For example, assets/css/main.css /// public string Filename { get; protected set; } /// - /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename. + /// Required. The file's full blob URL. You can find the blob_href in the response of the Get a single commit endpoint, by reading the blob_url from an element of the files array. You can also construct the blob URL from the head_sha, the repository, and the filename: https://github.com/:owner/:repo/blob/:head_sha/:filename /// public string BlobHref { get; protected set; } /// - /// Required. The start line of the annotation. + /// Required. The start line of the annotation /// public int StartLine { get; protected set; } /// - /// Required. The end line of the annotation. + /// Required. The end line of the annotation /// public int EndLine { get; protected set; } /// - /// Required. The warning level of the annotation. Can be one of notice, warning, or failure. + /// Required. The warning level of the annotation. Can be one of notice, warning, or failure /// public StringEnum WarningLevel { get; protected set; } /// - /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB. + /// Required. A short description of the feedback for these lines of code. The maximum size is 64 KB /// public string Message { get; protected set; } /// - /// The title that represents the annotation. The maximum size is 255 characters. + /// The title that represents the annotation. The maximum size is 255 characters /// public string Title { get; set; } /// - /// Details about this annotation. The maximum size is 64 KB. + /// Details about this annotation. The maximum size is 64 KB /// public string RawDetails { get; set; } diff --git a/Octokit/Models/Request/NewCheckRunImage.cs b/Octokit/Models/Request/NewCheckRunImage.cs index 90d793f243..ee5acd1b1c 100644 --- a/Octokit/Models/Request/NewCheckRunImage.cs +++ b/Octokit/Models/Request/NewCheckRunImage.cs @@ -9,8 +9,8 @@ public class NewCheckRunImage /// /// Constructs a CheckRunImage request object /// - /// Required. The alternative text for the image. - /// Required. The full URL of the image. + /// Required. The alternative text for the image + /// Required. The full URL of the image public NewCheckRunImage(string alt, string imageUrl) { Alt = alt; @@ -18,17 +18,17 @@ public NewCheckRunImage(string alt, string imageUrl) } /// - /// Required. The alternative text for the image. + /// Required. The alternative text for the image /// public string Alt { get; protected set; } /// - /// Required. The full URL of the image. + /// Required. The full URL of the image /// public string ImageUrl { get; protected set; } /// - /// A short image description. + /// A short image description /// public string Caption { get; set; } diff --git a/Octokit/Models/Request/NewCheckRunOutput.cs b/Octokit/Models/Request/NewCheckRunOutput.cs index d7899ee237..071227bb98 100644 --- a/Octokit/Models/Request/NewCheckRunOutput.cs +++ b/Octokit/Models/Request/NewCheckRunOutput.cs @@ -10,8 +10,8 @@ public class NewCheckRunOutput /// /// Constructs a CheckRunOutput request object /// - /// Required. The title of the check run. - /// Required. The summary of the check run. This parameter supports Markdown. + /// Required. The title of the check run + /// Required. The summary of the check run. This parameter supports Markdown public NewCheckRunOutput(string title, string summary) { Title = title; @@ -19,27 +19,27 @@ public NewCheckRunOutput(string title, string summary) } /// - /// Required. The title of the check run. + /// Required. The title of the check run /// public string Title { get; protected set; } /// - /// Required. The summary of the check run. This parameter supports Markdown. + /// Required. The summary of the check run. This parameter supports Markdown /// public string Summary { get; protected set; } /// - /// The details of the check run. This parameter supports Markdown. + /// The details of the check run. This parameter supports Markdown /// public string Text { get; set; } /// - /// Adds information from your analysis to specific lines of code. Annotations are visible in GitHub's pull request UI. For details about annotations in the UI, see "About status checks". + /// Adds information from your analysis to specific lines of code. Annotations are visible in GitHub's pull request UI. For details about annotations in the UI, see "About status checks" /// public IReadOnlyList Annotations { get; set; } /// - /// Adds images to the output displayed in the GitHub pull request UI. + /// Adds images to the output displayed in the GitHub pull request UI /// public IReadOnlyList Images { get; set; } diff --git a/Octokit/Models/Request/NewCheckSuite.cs b/Octokit/Models/Request/NewCheckSuite.cs index d841b37ef5..e4590db615 100644 --- a/Octokit/Models/Request/NewCheckSuite.cs +++ b/Octokit/Models/Request/NewCheckSuite.cs @@ -9,14 +9,14 @@ public class NewCheckSuite /// /// Creates a new Check Suite /// - /// Required. The sha of the head commit. + /// Required. The sha of the head commit public NewCheckSuite(string headSha) { HeadSha = headSha; } /// - /// Required. The sha of the head commit. + /// Required. The sha of the head commit /// public string HeadSha { get; private set; } diff --git a/Octokit/Models/Response/CheckRun.cs b/Octokit/Models/Response/CheckRun.cs index 8a52a69803..6642e61a1b 100644 --- a/Octokit/Models/Response/CheckRun.cs +++ b/Octokit/Models/Response/CheckRun.cs @@ -31,27 +31,27 @@ public CheckRun(long id, string headSha, string externalId, string url, string h } /// - /// The Id of this check run + /// The Id of the check run /// public long Id { get; protected set; } /// - /// The commit this check run is associated with + /// The SHA of the commit the check run is associated with /// public string HeadSha { get; protected set; } /// - /// A reference for the run on the integrator's system. + /// A reference for the run on the integrator's system /// public string ExternalId { get; protected set; } /// - /// The GitHub Api URL of this check run + /// The GitHub Api URL of the check run /// public string Url { get; protected set; } /// - /// The GitHub.com URL of this check run + /// The GitHub.com URL of the check run /// public string HtmlUrl { get; protected set; } diff --git a/Octokit/Models/Response/CheckRunAnnotation.cs b/Octokit/Models/Response/CheckRunAnnotation.cs index f74ae0b780..447f8f9086 100644 --- a/Octokit/Models/Response/CheckRunAnnotation.cs +++ b/Octokit/Models/Response/CheckRunAnnotation.cs @@ -22,37 +22,37 @@ public CheckRunAnnotation(string filename, string blobHref, int startLine, int e } /// - /// The path of the file the annotation refers to. For example, assets/css/main.css. + /// The path of the file the annotation refers to /// public string Filename { get; protected set; } /// - /// The file's full blob URL. + /// The file's full blob URL /// public string BlobHref { get; protected set; } /// - /// The start line of the annotation. + /// The start line of the annotation /// public int StartLine { get; protected set; } /// - /// The end line of the annotation. + /// The end line of the annotation /// public int EndLine { get; protected set; } /// - /// The warning level of the annotation. Can be one of notice, warning, or failure. + /// The warning level of the annotation. Can be one of notice, warning, or failure /// public StringEnum WarningLevel { get; protected set; } /// - /// A short description of the feedback for these lines of code. + /// A short description of the feedback for these lines of code /// public string Message { get; protected set; } /// - /// Details about this annotation. + /// Details about this annotation /// public string RawDetails { get; protected set; } diff --git a/Octokit/Models/Response/CheckRunOutputResponse.cs b/Octokit/Models/Response/CheckRunOutputResponse.cs index 20b7cf3fed..7503ff9b55 100644 --- a/Octokit/Models/Response/CheckRunOutputResponse.cs +++ b/Octokit/Models/Response/CheckRunOutputResponse.cs @@ -35,7 +35,7 @@ public CheckRunOutputResponse(string title, string summary, string text, long an public string Text { get; protected set; } /// - /// The number of annotations (use ICheckRunsClient.GetAllAnnotations() to load annotations) + /// The number of annotation entries for the check run (use to get annotation details) /// public long AnnotationsCount { get; protected set; } diff --git a/Octokit/Models/Response/CheckRunsResponse.cs b/Octokit/Models/Response/CheckRunsResponse.cs index 46e3167750..ffdc26e116 100644 --- a/Octokit/Models/Response/CheckRunsResponse.cs +++ b/Octokit/Models/Response/CheckRunsResponse.cs @@ -18,12 +18,12 @@ public CheckRunsResponse(int totalCount, IReadOnlyList checkRuns) } /// - /// The total number of check suites that match the request filter + /// The total number of check runs that match the request filter /// public int TotalCount { get; protected set; } /// - /// The retrieved check suites + /// The retrieved check runs /// public IReadOnlyList CheckRuns { get; protected set; } diff --git a/Octokit/Models/Response/CheckSuite.cs b/Octokit/Models/Response/CheckSuite.cs index d2eac05171..ecfdb3ce95 100644 --- a/Octokit/Models/Response/CheckSuite.cs +++ b/Octokit/Models/Response/CheckSuite.cs @@ -27,57 +27,57 @@ public CheckSuite(long id, string headBranch, string headSha, CheckStatus status } /// - /// The Id of this check suite + /// The Id of the check suite /// public long Id { get; protected set; } /// - /// The head branch of the commit this check suite is associated with + /// The branch the check suite is associated with /// public string HeadBranch { get; protected set; } /// - /// The commit this check suite is associated with + /// The SHA of the head commit in the push that created the check suite /// public string HeadSha { get; protected set; } /// - /// The summarized status of the check runs included in this check suite + /// The summarized status of the check runs included in the check suite /// public StringEnum Status { get; protected set; } /// - /// The summarized conclusion of the check runs included in this check suite + /// The summarized conclusion of the check runs included in the check suite /// public StringEnum? Conclusion { get; protected set; } /// - /// The GitHub Api URL of this check suite + /// The GitHub Api URL of the check suite /// public string Url { get; protected set; } /// - /// The hash of the commit prior to the HeadSha + /// The hash of the commit prior to the push that created the check suite /// public string Before { get; protected set; } /// - /// The hash of the commit after the HeadSha + /// The hash of the commit after the push that created the check suite (or HeadSha if no later commits exist) /// public string After { get; protected set; } /// - /// The pull requests that are associated with the check suite (via the HeadSha) + /// The pull requests that are associated with the check suite /// public IReadOnlyList PullRequests { get; protected set; } /// - /// The GitHub App that is associated with this check suite + /// The GitHub App for the check suite /// public GitHubApp App { get; protected set; } /// - /// The repository that is associated with this check suite + /// The repository for the check suite /// public Repository Repository { get; protected set; } From 6630ec847410d7d02176b5bca970dd0b27ee3ac7 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Thu, 19 Jul 2018 07:47:02 +1000 Subject: [PATCH 13/13] fix mutable response property - hooray for convention tests! --- Octokit/Models/Response/CheckRunAnnotation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Models/Response/CheckRunAnnotation.cs b/Octokit/Models/Response/CheckRunAnnotation.cs index 600f876efd..790b155076 100644 --- a/Octokit/Models/Response/CheckRunAnnotation.cs +++ b/Octokit/Models/Response/CheckRunAnnotation.cs @@ -55,7 +55,7 @@ public CheckRunAnnotation(string filename, string blobHref, int startLine, int e /// /// The title that represents the annotation /// - public string Title { get; set; } + public string Title { get; protected set; } /// /// Details about this annotation