public async Task CanListReactions() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, comment); Assert.NotNull(result); var confusedReaction = new NewReaction(ReactionType.Confused); var firstReaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, confusedReaction); var rocketReaction = new NewReaction(ReactionType.Rocket); var secondReaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, rocketReaction); var reactions = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id); Assert.NotEmpty(reactions); Assert.Equal(firstReaction.Id, reactions[0].Id); Assert.Equal(firstReaction.Content, reactions[0].Content); Assert.Equal(secondReaction.Id, reactions[1].Id); Assert.Equal(secondReaction.Content, reactions[1].Content); }
public async Task CanDeleteCommentWithRepositoryId() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.Repository.Id, commit.Sha, comment); Assert.NotNull(result); var retrievedBefore = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); Assert.NotNull(retrievedBefore); await _github.Repository.Comment.Delete(_context.Repository.Id, result.Id); var notFound = false; try { await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); } catch (NotFoundException) { notFound = true; } Assert.True(notFound); }
/// <summary> /// Creates a new Commit Comment for a specified Commit. /// </summary> /// <param name="repositoryId">The ID of the repository</param> /// <param name="sha">The sha reference of commit</param> /// <param name="newCommitComment">The new comment to add to the commit</param> /// <remarks>http://developer.github.com/v3/repos/comments/#create-a-commit-comment</remarks> public IObservable <CommitComment> Create(int repositoryId, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); return(_client.Create(repositoryId, sha, newCommitComment).ToObservable()); }
public async Task ReturnsCorrectCountOfReactionsWithoutStart() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, comment); Assert.NotNull(result); var newReaction = new NewReaction(ReactionType.Confused); var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); var options = new ApiOptions { PageSize = 1, PageCount = 1 }; var reactions = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id, options); Assert.Equal(1, reactions.Count); Assert.Equal(reaction.Id, reactions[0].Id); Assert.Equal(reaction.Content, reactions[0].Content); }
public async Task ReturnsCorrectCountOfReactionsWithStartWithRepositoryId() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, comment); Assert.NotNull(result); var reactions = new List <Reaction>(); var reactionsContent = new[] { ReactionType.Confused, ReactionType.Hooray }; for (var i = 0; i < 2; i++) { var newReaction = new NewReaction(reactionsContent[i]); var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction); reactions.Add(reaction); } var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 2 }; var reactionsInfo = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, options); Assert.Equal(1, reactionsInfo.Count); Assert.Equal(reactions.Last().Id, reactionsInfo[0].Id); Assert.Equal(reactions.Last().Content, reactionsInfo[0].Content); }
public async Task CanGetReactionPayload() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.Repository.Id, commit.Sha, comment); foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) { var newReaction = new NewReaction(reactionType); var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); Assert.IsType <Reaction>(reaction); Assert.Equal(reactionType, reaction.Content); Assert.Equal(result.User.Id, reaction.User.Id); } var retrieved = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id); Assert.True(retrieved.Id > 0); Assert.Equal(6, retrieved.Reactions.TotalCount); Assert.Equal(1, retrieved.Reactions.Plus1); Assert.Equal(1, retrieved.Reactions.Hooray); Assert.Equal(1, retrieved.Reactions.Heart); Assert.Equal(1, retrieved.Reactions.Laugh); Assert.Equal(1, retrieved.Reactions.Confused); Assert.Equal(1, retrieved.Reactions.Minus1); }
/// <summary> /// Creates a new Commit Comment for a specified Commit. /// </summary> /// <remarks>http://developer.github.com/v3/repos/comments/#create-a-commit-comment</remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="sha">The sha reference of commit</param> /// <param name="newCommitComment">The new comment to add to the commit</param> /// <returns></returns> public IObservable<CommitComment> Create(string owner, string name, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); return _client.Create(owner, name, sha, newCommitComment).ToObservable(); }
public void PostsToCorrectUrl() { NewCommitComment newComment = new NewCommitComment("body"); var connection = Substitute.For <IApiConnection>(); var client = new RepositoryCommentsClient(connection); client.Create("fake", "repo", "sha", newComment); connection.Received().Post <CommitComment>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/comments"), Arg.Any <object>()); }
public async Task PostsToCorrectUrlWithRepositoryId() { var newComment = new NewCommitComment("body"); var connection = Substitute.For <IApiConnection>(); var client = new RepositoryCommentsClient(connection); await client.Create(1, "sha", newComment); connection.Received().Post <CommitComment>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/commits/sha/comments"), Arg.Any <object>()); }
public void PostsToCorrectUrlWithRepositoryId() { var newComment = new NewCommitComment("body"); var githubClient = Substitute.For <IGitHubClient>(); var client = new ObservableRepositoryCommentsClient(githubClient); client.Create(1, "sha", newComment); githubClient.Repository.Comment.Received().Create(1, "sha", newComment); }
public ChangesetDiffViewModel(ISessionService sessionService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { var comments = new ReactiveList <CommitComment>(); Comments = comments.CreateDerivedCollection( x => new FileDiffCommentViewModel(x.User.Login, x.User.AvatarUrl, x.Body, x.Position ?? 0)); var gotoCreateCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var cmd = new NewCommitComment(s) { Path = Filename, Position = SelectedPatchLine.Item1 }; var comment = await sessionService.GitHubClient.Repository.RepositoryComments.Create(Username, Repository, Branch, cmd); _commentCreatedObservable.OnNext(comment); comments.Add(comment); }, alertDialogFactory); NavigateTo(vm); }); GoToCommentCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.SelectedPatchLine).Select(x => x != null), sender => { var sheet = actionMenuFactory.Create(); sheet.AddButton(string.Format("Add Comment on Line {0}", SelectedPatchLine.Item2), gotoCreateCommentCommand); return(sheet.Show(sender)); }); _patch = this.WhenAnyValue(x => x.CommitFile) .IsNotNull().Select(x => x.Patch).ToProperty(this, x => x.Patch); this.WhenAnyValue(x => x.Filename).Subscribe(x => { if (string.IsNullOrEmpty(x)) { Title = "Diff"; } else { _actualFilename = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1); Title = _actualFilename; } }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { sessionService.GitHubClient.Repository.RepositoryComments.GetAllForCommit(Username, Repository, Branch) .ToBackground(x => comments.Reset(x.Where(y => string.Equals(y.Path, Filename)))); var commits = await sessionService.GitHubClient.Repository.Commits.Get(Username, Repository, Branch); CommitFile = commits.Files.FirstOrDefault(x => string.Equals(x.Filename, Filename, StringComparison.Ordinal)); }); }
public async Task CanCreateCommentWithRepositoryId() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.Repository.Id, commit.Sha, comment); Assert.NotNull(result); var retrieved = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); Assert.NotNull(retrieved); }
public async Task CanCreateReactionWithRepositoryId() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, comment); Assert.NotNull(result); var newReaction = new NewReaction(ReactionType.Confused); var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction); Assert.IsType <Reaction>(reaction); Assert.Equal(ReactionType.Confused, reaction.Content); Assert.Equal(result.User.Id, reaction.User.Id); }
/// <inheritdoc/> protected override async Task <object> CallGitHubApi(DialogContext dc, Octokit.GitHubClient gitHubClient, CancellationToken cancellationToken = default(CancellationToken)) { if (Owner != null && Name != null && Sha != null && NewCommitComment != null) { var ownerValue = Owner.GetValue(dc.State); var nameValue = Name.GetValue(dc.State); var shaValue = Sha.GetValue(dc.State); var newCommitCommentValue = NewCommitComment.GetValue(dc.State); return(await gitHubClient.Repository.Comment.Create(ownerValue, nameValue, shaValue, newCommitCommentValue).ConfigureAwait(false)); } if (RepositoryId != null && Sha != null && NewCommitComment != null) { var repositoryIdValue = RepositoryId.GetValue(dc.State); var shaValue = Sha.GetValue(dc.State); var newCommitCommentValue = NewCommitComment.GetValue(dc.State); return(await gitHubClient.Repository.Comment.Create((Int64)repositoryIdValue, shaValue, newCommitCommentValue).ConfigureAwait(false)); } throw new ArgumentNullException("Required [sha,newCommitComment] arguments missing for GitHubClient.Repository.Comment.Create"); }
public async Task CanDeleteComment() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, comment); Assert.NotNull(result); var retrievedBefore = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id); Assert.NotNull(retrievedBefore); await _github.Repository.Comment.Delete(_context.RepositoryOwner, _context.RepositoryName, result.Id); var retrievedAfter = await _github.Repository.Comment.Get(_context.RepositoryOwner, _context.RepositoryName, result.Id); Assert.Null(retrievedAfter); }
public async Task CanUpdateCommentWithRepositoryId() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.Repository.Id, commit.Sha, comment); Assert.NotNull(result); var retrievedBefore = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); Assert.NotNull(retrievedBefore); await _github.Repository.Comment.Update(_context.Repository.Id, result.Id, "new comment"); var retrievedAfter = await _github.Repository.Comment.Get(_context.Repository.Id, result.Id); Assert.Equal("new comment", retrievedAfter.Body); }
public async Task ReturnsDistinctReactionsBasedOnStartPageWithRepositoryId() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, comment); Assert.NotNull(result); var reactionsContent = new[] { ReactionType.Confused, ReactionType.Hooray }; for (var i = 0; i < 2; i++) { var newReaction = new NewReaction(reactionsContent[i]); var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction); } var startOptions = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; var firstPage = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, startOptions); var skipStartOptions = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; var secondPage = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id, skipStartOptions); Assert.Equal(1, firstPage.Count); Assert.Equal(1, secondPage.Count); Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); Assert.NotEqual(firstPage[0].Content, secondPage[0].Content); }
public async Task CanCreateReaction() { var commit = await SetupCommitForRepository(_github); var comment = new NewCommitComment("test"); var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, comment); Assert.NotNull(result); foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType))) { var newReaction = new NewReaction(reactionType); var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction); Assert.IsType <Reaction>(reaction); Assert.Equal(reactionType, reaction.Content); Assert.Equal(result.User.Id, reaction.User.Id); } }
/// <summary> /// Creates a new Commit Comment for a specified Commit. /// </summary> /// <remarks>http://developer.github.com/v3/repos/comments/#create-a-commit-comment</remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="sha">The sha reference of commit</param> /// <param name="newCommitComment">The new comment to add to the commit</param> /// <returns></returns> public IObservable <CommitComment> Create(string owner, string name, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); return(_client.Create(owner, name, sha, newCommitComment).ToObservable()); }
/// <summary> /// Creates a new Commit Comment for a specified Commit. /// </summary> /// <param name="repositoryId">The ID of the repository</param> /// <param name="sha">The sha reference of commit</param> /// <param name="newCommitComment">The new comment to add to the commit</param> /// <remarks>http://developer.github.com/v3/repos/comments/#create-a-commit-comment</remarks> public IObservable<CommitComment> Create(int repositoryId, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); return _client.Create(repositoryId, sha, newCommitComment).ToObservable(); }
public void PostsToCorrectUrlWithRepositoryId() { var newComment = new NewCommitComment("body"); var githubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryCommentsClient(githubClient); client.Create(1, "sha", newComment); githubClient.Repository.Comment.Received().Create(1, "sha", newComment); }