public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentException>(() => client.Create("", "name", "sha", new NewCommitStatus())); await Assert.ThrowsAsync <ArgumentException>(() => client.Create("owner", "", "sha", new NewCommitStatus())); await Assert.ThrowsAsync <ArgumentException>(() => client.Create("owner", "name", "", new NewCommitStatus())); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create(null, "name", "sha", new NewCommitStatus())); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create("owner", null, "sha", new NewCommitStatus())); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create("owner", "name", null, new NewCommitStatus())); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Create("owner", "name", "sha", null)); }
public void PostsToTheCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new CommitStatusClient(connection); client.Create("owner", "repo", "sha", new NewCommitStatus { State = CommitState.Success }); connection.Received().Post<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/statuses/sha"), Arg.Is<NewCommitStatus>(s => s.State == CommitState.Success)); }
public async Task WriteCommitStatusAsync(PullRequestContext context, CommitState state, string description) { var client = new CommitStatusClient(new ApiConnection(context.GithubConnection)); var status = new NewCommitStatus { State = state, Description = description, Context = _settingsProvider.Settings.StatusContext }; await client.Create(context.Payload.Repository.Id, context.Payload.PullRequest.Head.Sha, status); }
public void PostsToTheCorrectUrl() { var connection = Substitute.For <IApiConnection>(); var client = new CommitStatusClient(connection); client.Create("owner", "repo", "sha", new NewCommitStatus { State = CommitState.Success }); connection.Received().Post <CommitStatus>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/repo/statuses/sha"), Arg.Is <NewCommitStatus>(s => s.State == CommitState.Success)); }
public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For<IApiConnection>()); await AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "name", "", new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", null, new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", "sha", null)); }
public static GitHubStatusResult GitHubStatus(this ICakeContext context, string userName, string apiToken, string owner, string repository, string reference, GitHubStatusSettings settings) { #if DEBUG if (!Debugger.IsAttached) { Debugger.Launch(); } #endif settings = settings ?? new GitHubStatusSettings(); var connection = CreateApiConnection(userName, apiToken); try { var commitStatus = new NewCommitStatus { Description = settings.Description, Context = settings.Context, TargetUrl = settings.TargetUrl }; switch (settings.State) { case GitHubStatusState.Success: commitStatus.State = CommitState.Success; break; case GitHubStatusState.Pending: commitStatus.State = CommitState.Pending; break; case GitHubStatusState.Failure: commitStatus.State = CommitState.Failure; break; case GitHubStatusState.Error: commitStatus.State = CommitState.Error; break; } var commitStatusClient = new CommitStatusClient(connection); var createStatusTask = commitStatusClient.Create(owner, repository, reference, commitStatus); createStatusTask.Wait(); var taskResult = createStatusTask.Result; var result = new GitHubStatusResult { Id = taskResult.Id.ToString(), Url = taskResult.Url, State = taskResult.State.ToString() }; return(result); } catch (Exception ex) { do { context.Log.Error(ex.Message); } while ((ex = ex.InnerException) != null); throw new Exception("Failed to create status."); } }