コード例 #1
0
        private void CreateFakeJiraIssues()
        {
            // initialize the Random with fixed seed for reproducability
            var random  = new Random(0);
            int issueId = 0;

            foreach (BundleMetainfo bundle in bundleRepo.GetAll())
            {
                int n          = random.Next(4);
                var jiraIssues = new JiraIssueModel[n];
                for (int i = 0; i < n; i++)
                {
                    string resolution = random.Next(2) == 0 ? "Open" : "Resolved";
                    jiraIssues[i] = new JiraIssueModel {
                        Key    = $"JRA-{issueId++}",
                        Fields = new JiraIssueModel.JiraIssueFieldModel {
                            Resolution = new JiraIssueModel.JiraIssueStatusModel {
                                Id = resolution, Name = resolution
                            }
                        }
                    };
                }
                jiraApiService.SetFakeJiraIssues(bundle.BundleId, jiraIssues);
            }
        }
コード例 #2
0
        public static JiraCreateIssueResult CreateIssue(JiraCredentials credential, JiraIssueModel newIssue)
        {
            var DataObj = new ActualJiraIssueModel {
                Fields = newIssue
            };
            var response = JiraUtility.Post <ActualJiraIssueModel, JiraBaseResponseModel>("issue", credential, DataObj, HttpStatusCode.Created);

            return(new JiraCreateIssueResult(response));
        }
コード例 #3
0
        public async static Task Run([ServiceBusTrigger("prupdated", "CheckJiraIssues", Connection = "AzureWebJobsServiceBus")] PRInfo info, [Table("PRIssueMapping")] CloudTable table, ILogger log)
        {
            string PartitionKey = $"{info.Prefix}|{info.PullRequestID}";
            int    records      = 0;
            TableQuery <PRIssueMapping> rangeQuery = new TableQuery <PRIssueMapping>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, PartitionKey));

            foreach (PRIssueMapping issue in await table.ExecuteQuerySegmentedAsync(rangeQuery, null))
            {
                records++;
            }
            HttpClient client    = new HttpClient();
            var        byteArray = Encoding.ASCII.GetBytes($":{Environment.GetEnvironmentVariable("AzureDevOps_Setting", EnvironmentVariableTarget.Process)}");
            string     statusURL = $"{info.BaseURL}/_apis/git/repositories/{info.RepoID}/pullRequests/{info.PullRequestID}/statuses/statuses?api-version=5.1-preview.1";

            Environment.SetEnvironmentVariable("baseURL", info.BaseURL);
            HttpRequestMessage statusChange = new HttpRequestMessage(HttpMethod.Post, statusURL);

            statusChange.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            JiraIssueModel obj;

            if (records == 0)
            {
                obj = new JiraIssueModel()
                {
                    state       = "pending",
                    description = "Click here to select Issues",
                    context     = new Context()
                    {
                        name = "JiraIssues"
                    },
                    targetUrl = $"{Environment.GetEnvironmentVariable("SPAUrl", EnvironmentVariableTarget.Process)}/{info.Prefix}/{info.PullRequestID}/{info.Token}"
                };
            }
            else
            {
                obj = new JiraIssueModel()
                {
                    state       = "succeeded",
                    description = $"Linked to {records} issues",
                    context     = new Context()
                    {
                        name = "JiraIssues"
                    },
                    targetUrl = $"{Environment.GetEnvironmentVariable("SPAUrl", EnvironmentVariableTarget.Process)}/{info.Prefix}/{info.PullRequestID}/{info.Token}"
                };
            }
            dynamic json = JsonConvert.SerializeObject(obj);

            statusChange.Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
            HttpResponseMessage statusResponse = await client.SendAsync(statusChange);

            if (!statusResponse.IsSuccessStatusCode)
            {
                log.LogError("Error!");
            }
        }
コード例 #4
0
        public static BaseJiraResult EditIssue(JiraCredentials credential, JiraIssueModel Issue)
        {
            var DataObj = new ActualJiraIssueModel {
                Fields = Issue
            };
            var response = JiraUtility.Put <ActualJiraIssueModel, JiraEmptyResponseModel>($"issue/{Issue.IssueIdOrKey}", credential, DataObj, HttpStatusCode.NoContent);

            return(new BaseJiraResult {
                ErrorMessage = response.ErrorMessage, Status = response.Status, HttpStatus = response.HttpStatus
            });
        }
コード例 #5
0
        public JiraIssueViewModel() : this
            (
                IsInDesignModeStatic ? (IJiraIssueModelService) new Design.DesignJiraIssueModelService() : null,
                new DialogService()
            )
        {
#if DEBUG
            if (IsInDesignMode)
            {
                JiraIssue = jiraIssueModelService.Read();
            }
#endif
        }
コード例 #6
0
 public void Save(JiraIssueModel LoginInformation)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
ファイル: JiraClient.cs プロジェクト: The-Q/KaitenExporter
        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);
            }
        }
コード例 #8
0
 public JiraIssueViewModel(IJiraIssueModelService JiraIssueModelService, IDialogService DialogService)
 {
     jiraIssueModelService = JiraIssueModelService;
     dialogService         = DialogService;
     JiraIssue             = jiraIssueModelService?.Read();
 }