public async Task <DiscussionDto> AddDiscussion(CreateDiscussionDto createDiscussionDto, string body)
        {
            this.IsPending = true;
            try
            {
                if (this.SelectedProjectId == null)
                {
                    throw new InvalidOperationException("SelectedProjectId is null");
                }

                if (this.SelectedMergeRequestInternalId == null)
                {
                    throw new InvalidOperationException("SelectedMergeRequestInternalId is null");
                }

                using (var client = new GitLabClient(this.GitOptions))
                {
                    return(await client.AddDiscussion(this.GitOptions.SelectedProjectId.Value, this.SelectedMergeRequestInternalId.Value, createDiscussionDto, body));
                }
            }
            catch (Exception ex)
            {
                this.errorService.AddError(ex);
                return(null);
            }
            finally
            {
                this.IsPending = false;
            }
        }
Beispiel #2
0
        private async void ExecuteNewDiscussion(object obj)
        {
            var position = new PositionDto
            {
                PositionType = "text",
                BaseSha      = this.mergeRequest.DiffRefs.BaseSha,
                StartSha     = this.mergeRequest.DiffRefs.StartSha,
                HeadSha      = this.mergeRequest.DiffRefs.HeadSha,
                NewPath      = this.change.NewPath,
                OldPath      = this.change.OldPath,
                NewLine      = this.NumberInSourceFile,
                OldLine      = this.NumberInTargetFile
            };

            var createDiscussionDto = new CreateDiscussionDto {
                Position = position
            };
            var dissDto = await this.service.AddDiscussion(createDiscussionDto, this.NewDiscussionText);

            var dissVm = new DiscussionViewModel(dissDto, this.service);

            this.Discussions.Add(dissVm);
            this.NewDiscussionText = string.Empty;
        }
        public async Task <DiscussionDto> AddDiscussion(long projectId, long mergeRequestInternalId, CreateDiscussionDto createDiscussionDto, string body)
        {
            var uri      = $"{this.gitOptions.ApiUrl}/projects/{projectId}/merge_requests/{mergeRequestInternalId}/discussions?body={body}";
            var content  = JsonConvert.SerializeObject(createDiscussionDto, this.settings);
            var response = await client.PostAsync(uri, new StringContent(content, Encoding.UTF8, "application/json"));

            var responseAsString = await response.Content.ReadAsStringAsync();

            var discussion = JsonHelper.Deserialize <DiscussionDto>(responseAsString);

            return(discussion);
        }