Esempio n. 1
0
        public async Task <KaitenCardRecord> GetItem(string url)
        {
            if (!TryGetCardId(url, out var id))
            {
                _logger.LogWarning($"Unable to get card id for url ${url}");
                return(KaitenCardRecord.Empty());
            }
            var uri = $"cards/{id}";

            _logger.LogInformation("Requesting card {}", id);
            var request  = new HttpRequestMessage(HttpMethod.Get, uri);
            var client   = _clientFactory.CreateClient("kaiten");
            var response = await client.SendAsync(request);

            _logger.LogDebug($"Got status code {response.StatusCode}");
            if (response.IsSuccessStatusCode)
            {
                var content = await JsonSerializer.DeserializeAsync <KaitenCardRecord>(await response.Content.ReadAsStreamAsync());

                _logger.LogDebug("{}", content);
                content.Link = url;
                return(content);
            }
            return(KaitenCardRecord.Empty());
        }
Esempio n. 2
0
 public static CsvRecord FromKaiten(KaitenCardRecord card)
 {
     return(new CsvRecord(card.Title,
                          String.Format("{0} {1}", card.Link, card.Description)));
 }
Esempio n. 3
0
        public async Task <Either <JiraFailureModel, JiraSuccesCreateModel> > CreateSubTask(KaitenCardRecord kaitenCard)
        {
            var uri = "issue/";

            _logger.LogDebug("Creating issue in Jira");
            var request = new HttpRequestMessage(HttpMethod.Post, uri);
            var issue   = new JiraIssueModel()
            {
                Assignee = new JiraIssueModel.NamedValue()
                {
                    Name = _configuration.UserName
                },
                Description = $"{kaitenCard.Link}\n{kaitenCard.Description}",
                Title       = kaitenCard.Title,
                IssueType   = JiraIssueModel.IssueTypeModel.GetSubtask(),
                Parent      = new JiraIssueModel.ParentModel()
                {
                    Key = _configuration.ParentId
                },
                Priority = JiraIssueModel.PriorityModel.GetMedium(),
                Project  = new JiraIssueModel.ProjectModel()
                {
                    Key = _configuration.ProjectName
                },
                Labels    = _configuration.Labels,
                Componets = _configuration.Components.Select(c => new JiraIssueModel.ComponentModel()
                {
                    Id = c
                })
            };
            var payload = JsonSerializer.Serialize <JiraIssuePayload>(new JiraIssuePayload()
            {
                Issue = issue
            });

            _logger.LogDebug("Sending this request: {0}",
                             JsonSerializer.Serialize <JiraIssueModel>(issue, new JsonSerializerOptions()
            {
                WriteIndented = true
            }));
            var buffer      = Encoding.UTF8.GetBytes(payload);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            request.Content = byteContent;
            var client   = _clientFactory.CreateClient("jira");
            var response = await client.SendAsync(request);

            _logger.LogDebug($"Got status code {response.StatusCode}");
            if (response.IsSuccessStatusCode)
            {
                var streamContent = await response.Content.ReadAsStringAsync();

                var content = JsonSerializer.Deserialize <JiraSuccesCreateModel>(streamContent);
                _logger.LogDebug("{}", content);
                return(content);
            }
            else
            {
                var streamContent = await response.Content.ReadAsStringAsync();

                var content = JsonSerializer.Deserialize <JiraFailureModel>(streamContent);
                _logger.LogDebug("{}", content);
                return(content);
            }
        }