public async Task <ActionResult <PostCommentResponseBody> > PostComment(
            string owner,
            string repository,
            string pullRequestId,
            [FromBody] PostCommentRequestBody requestBody)
        {
            var commentId    = _guidGenerator.GenerateString();
            var repositoryId = new RepositoryId(owner, repository);
            var command      = new AddSingleComment
                               (
                pullRequestId: pullRequestId,
                repositoryId: repositoryId.ToString(),
                commentId: commentId,
                author: requestBody.Author,
                text: requestBody.Text
                               );

            var streamName = new PullRequestCommentStreamName(commentId).ToString();
            await _applicationService.ExecuteAsync(streamName, history => _comments.AddSingleComment(history, command));

            return(Created(
                       $"repositories/{repositoryId}/pulls/{pullRequestId}/comments",
                       new PostCommentResponseBody {
                CommentId = commentId
            }
                       ));
        }
        public void DeleteRepository()
        {
            SQLiteHelper oSQLHelper = new SQLiteHelper(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, null);

            if (!oSQLHelper.InitConnection())
            {
                return;
            }

            //Count repositories
            oSQLHelper.SetCommandText("DELETE FROM VFile WHERE Fk_Repository = " + this.RepositoryId);
            oSQLHelper.ExecuteNonQuery();

            oSQLHelper.SetCommandText("DELETE FROM VFolder WHERE Fk_Repository = " + this.RepositoryId);
            oSQLHelper.ExecuteNonQuery();

            oSQLHelper.SetCommandText("DELETE FROM Repository WHERE Id_Repository = " + this.RepositoryId);
            oSQLHelper.ExecuteNonQuery();

            oSQLHelper.Dispose();

            if (RepositoryDeleted != null)
            {
                RepositoryDeleted(this, RepositoryId.ToString());
            }
        }
Esempio n. 3
0
 public void Save()
 {
     System.IO.File.WriteAllText(RepositoryId.ToString() + ".json", JsonConvert.SerializeObject(this, new JsonSerializerSettings()
     {
         TypeNameHandling = TypeNameHandling.Auto,
         Formatting       = Formatting.Indented
     }));
 }
Esempio n. 4
0
        public async Task UpdatePullRequestCommentsReadModelWhenSingleCommentWasAdded()
        {
            //When
            var randomOwner = _guidGenerator.GenerateString();
            var randomRepository = _guidGenerator.GenerateString();
            var repositoryId = new RepositoryId(randomOwner, randomRepository);
            var pullRequestId = _guidGenerator.GenerateString();
            var commentId = _guidGenerator.GenerateString();
            var singleCommentWasAdded = new SingleCommentWasAdded
            {
                OccurredAt = DateTime.UtcNow,
                PullRequestId = pullRequestId,
                RepositoryId = repositoryId.ToString(),
                CommentId = commentId,
                Author = "LoggedUser",
                Text = "Comment text"
            };

            var streamName = $"PullRequestComment-{commentId}";
            await _eventStore.Publish(streamName, singleCommentWasAdded, _eventSerializer);

            //Then
            var getUrl = $"/rest-api/{randomOwner}/{randomRepository}/pulls/{pullRequestId}/comments";
            await AssertionHelper.WaitUntil(async () => (await GetPullRequestComments(getUrl)).Comments.Count > 0);
            var responseBody = await GetPullRequestComments(getUrl);
            responseBody.Comments.Should().HaveCount(1);
            responseBody.Comments.Should().HaveElementAt(
                0,
                new PullRequestComment
                {
                    Author = "LoggedUser",
                    CommentId = commentId,
                    PostedAt = singleCommentWasAdded.OccurredAt,
                    PullRequestId = pullRequestId,
                    Text = "Comment text"
                }
            );
        }
        public async Task PostCommentShouldResultsWithSingleCommentWasAdded()
        {
            //Given
            var randomOwner      = _guidGenerator.GenerateString();
            var randomRepository = _guidGenerator.GenerateString();
            var repositoryId     = new RepositoryId(randomOwner, randomRepository);
            var pullRequestId    = _guidGenerator.GenerateString();

            //When
            var postRequest = new
            {
                Url  = $"/rest-api/{randomOwner}/{randomRepository}/pulls/{pullRequestId}/comments",
                Body = new
                {
                    Text   = "Comment text",
                    Author = "LoggedUser"
                }
            };
            var response = await _client.PostAsync(postRequest.Url, postRequest.Body.ToJson());

            //Then
            var responseBody =
                JsonConvert.DeserializeObject <PostCommentResponseBody>(await response.Content.ReadAsStringAsync());
            var expectedStreamName = $"PullRequestComment-{responseBody.CommentId}";
            var streamLastEvent    = await _eventStore.StreamLastEvent(expectedStreamName, _eventSerializer);

            streamLastEvent.Should().BeEquivalentTo(
                new SingleCommentWasAdded
                (
                    pullRequestId: pullRequestId,
                    repositoryId: repositoryId.ToString(),
                    commentId: responseBody.CommentId,
                    author: "LoggedUser",
                    text: "Comment text",
                    occurredAt: _clock.Now
                )
                );
        }
Esempio n. 6
0
        /// <summary>
        /// Perform per-request authentication processing.
        /// </summary>
        /// <param name="channel">The channel object</param>
        /// <param name="client">The web client that is about to be used to execute the request.  It can't be used by the authentication provider to make requests.</param>
        /// <param name="request">The request that is about to be sent</param>
        /// <param name="resourceUrl">The resource URL (with query string) specified by the client.</param>
        /// <param name="requestSupportsAuthentication">Indicates if the request being processed supports authentication or not.</param>
        /// <remarks>If the request doesn't support authentication, it's a best practice to not provide any authentication information.</remarks>
        void IWebAuthenticationProvider.PreProcessRequest(WebChannel channel, HttpClient client, HttpRequestMessage request, string resourceUrl, bool requestSupportsAuthentication)
        {
            //figure out the effective relative URL.
            string fullUrl = resourceUrl;

            if (client.BaseAddress != null)
            {
                fullUrl = client.BaseAddress + resourceUrl;
            }

            var clientUri = new Uri(fullUrl);

            //we're doing sets not adds to make sure we overwrite any existing value.
            if (requestSupportsAuthentication)
            {
                request.Headers.TryAddWithoutValidation(AuthorizationHeader, AuthorizationPrefix + ": " + CalculateHash(clientUri.PathAndQuery));
                request.Headers.Add(ClientRepositoryHeader, RepositoryId.ToString());
            }
            else
            {
                //remove our repository header.
                request.Headers.Remove(ClientRepositoryHeader);
            }
        }