lvermeulen / Bitbucket.Net

C# client for Atlassian Bitbucket Server
MIT License
32 stars 18 forks source link

Does not handle adding pull request comment that is not tied to a line of source code #11

Closed richardgavel closed 5 years ago

richardgavel commented 5 years ago

I get a 404 when trying to add a pull request comment that is not linked to a specific line of code. This despite being able to do so if I POST to the same URI, with a body of just { text = "comment" }. I imagine it is because the rest of the JSON body is actually being populated with data that does not apply in a global PR comment.

lvermeulen commented 5 years ago

Sorry for the delay in replying. On which call in the library are you seeing this?

richardgavel commented 5 years ago

Sorry for the feedback delay. This is the call. https://github.com/lvermeulen/Bitbucket.Net/blob/a3525006ce394c9af223f991ed638cbba0823e3a/src/Bitbucket.Net/Core/Projects/BitbucketClient.cs#L1236. Even though the invocation supports providing only the comment itself, with the other parameters optional, those nulls will still be made part of the JSON that gets posted instead of non-existent properties.

richardgavel commented 5 years ago

This is the exact code I'm using in a replacement:

        public async Task CreatePullRequestCommentAsync(string projectKey, string repositorySlug, long pullRequestId, string text)
        {
            try
            {
                var requestUri = $"rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments";
                var body = new
                {
                    text
                };

                var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.Default, "application/json");
                var response = await _httpClient.PostAsync(requestUri, content);
                response.EnsureSuccessStatusCode();
            }
            catch (HttpRequestException ex)
            {
                _logger.LogError(ex, "Error creating pull request comment ({Message})", ex.Message);
                throw;
            }
        }
lvermeulen commented 5 years ago

I'm on it.

lvermeulen commented 5 years ago

I will push out a fix hopefully this weekend.

lvermeulen commented 5 years ago

Fixed in release 2.1.6