Exemple #1
0
        public static IssueCreateDto CreateDto(string projectName, string priority, string title, List <string> descriptionLines)
        {
            var issueCreateDto = new IssueCreateDto();

            issueCreateDto.fields         = new Fields();
            issueCreateDto.fields.project = new Project()
            {
                key = projectName,
            };

            issueCreateDto.fields.issuetype = new Issuetype()
            {
                name = "Bug",
            };

            issueCreateDto.fields.summary  = title;
            issueCreateDto.fields.priority = new Priority()
            {
                name = priority,
            };

            issueCreateDto.fields.description = new Description()
            {
                version = 1,
                type    = "doc",
                content = new List <Content>()
                {
                    new Content()
                    {
                        type    = "paragraph",
                        content = new List <Content2>(),
                    },
                },
            };

            foreach (var currentLine in descriptionLines)
            {
                issueCreateDto.fields.description.content.First().content.Add(new Content2()
                {
                    type = "text", text = currentLine
                });
                issueCreateDto.fields.description.content.First().content.Add(new Content2()
                {
                    type = "text", text = Environment.NewLine
                });
            }

            return(issueCreateDto);
        }
Exemple #2
0
        public static IssueCreateResponse CreateBug(string title, List <string> summaryLines, List <string> filesToUpload = null)
        {
            string defaultPriority = ConfigurationService.GetSection <JiraBugReportingSettings>().DefaultPriority;

            var issueCreateDto = IssueCreateDto.CreateDto(_projectName, defaultPriority, title, summaryLines);

            var createRequest = new RestRequest("rest/api/3/issue", Method.POST);

            createRequest.AddHeader("Authorization", $"Basic {_token}");
            createRequest.RequestFormat = DataFormat.Json;
            createRequest.AddJsonBody(issueCreateDto);

            IssueCreateResponse result = default;

            try
            {
                result = _restClient.Execute <IssueCreateResponse>(createRequest)?.Data;

                if (filesToUpload != null && filesToUpload.Any())
                {
                    foreach (var fileToUpload in filesToUpload)
                    {
                        var attachFileRequest = new RestRequest($"rest/api/2/issue/{result.key}/attachments", Method.POST);
                        attachFileRequest.AddHeader("Authorization", $"Basic {_token}");
                        attachFileRequest.AddHeader("X-Atlassian-Token", "no-check");
                        attachFileRequest.RequestFormat = DataFormat.Json;
                        attachFileRequest.AddFile("file", fileToUpload);

                        var attachResult = _restClient.Execute(attachFileRequest);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(result);
        }