示例#1
0
        public void ValidateReadJSON()
        {
            var    jira         = new JiraService.Jira("", "", "");
            var    issueSrevice = jira.GetIssueService();
            var    issue        = issueSrevice.GetAsync("").Result;
            string name         = issue.GetValueByPath("$.fields.issuetype.name");

            Assert.IsTrue(name == "Story");
            //
            // TODO: Add test logic here
            //
        }
示例#2
0
        public override TCObject Execute(TCObject objectToExecuteOn, TCAddOnTaskContext taskContext)
        {
            TCFolder            f           = (TCFolder)objectToExecuteOn;
            IEnumerable <Issue> childIssues = f.Search("->SUBPARTS:Issue").Cast <Issue>();

            var config = f.GetJiraConfig();

            if (config == null)
            {
                string url     = taskContext.GetStringValue("Jira Instance URL: ", false);
                string project = taskContext.GetStringValue("Jira Project Key: ", false);
                config = new JiraConfig {
                    baseURL = url, projectKey = project, fieldMaps = new List <FieldMap>()
                };
                f.SaveConfig(config);
            }
            string username, password;

            if (CredentialManager.Instance.Credentials.Any(x => x.BaseURL == config.baseURL))
            {
                Credential credential = CredentialManager.Instance.Credentials.First(x => x.BaseURL == config.baseURL);
                username = credential.Username;
                password = credential.Password;
            }
            else
            {
                username = taskContext.GetStringValue("Jira Username", false);
                password = taskContext.GetStringValue("Jira Password", true);
                CredentialManager.Instance.StoreOrUpdateCredential(new Credential
                {
                    BaseURL     = config.baseURL,
                    Description = "Created by Jira Config",
                    Username    = username,
                    Password    = password
                });
            }

            var jira         = new JiraService.Jira(config.baseURL, username, password);
            var issueService = jira.GetIssueService();

            foreach (var issue in childIssues)
            {
                string storedIssueKey = string.Empty;
                try
                {
                    storedIssueKey = issue.GetAttributeValue(Global.JiraTicket);
                }
                catch (Exception)
                {
                    throw new Exception("Please prepare project for integration (available from context menu at project level) and then try again");
                }
                if (!string.IsNullOrEmpty(storedIssueKey))
                {
                    var jiraIssue = issueService.GetAsync(storedIssueKey).Result;
                    issue.State = jiraIssue.fields.status.name;
                    issue.Name  = jiraIssue.fields.summary;
                }
                else //No existing Jira issue exists
                {
                    string description = issue.Description;
                    if (issue.Links.Any())
                    {
                        var executionLog = issue.Links.First().ExecutionTestCaseLog;
                        description = $"TEST: {executionLog.Name}\r\n{executionLog.AggregatedDescription}";
                    }
                    var newIssue = new JiraService.Issue.Issue
                    {
                        fields = new JiraService.Issue.IssueFields
                        {
                            summary     = issue.Name,
                            description = description,
                            //Create other fields here
                            project = new JiraService.Issue.Field.ProjectField {
                                key = config.projectKey
                            },
                            issuetype = new JiraService.Issue.Field.IssueTypeField {
                                name = "Bug"
                            }
                        }
                    };
                    foreach (var defaultValue in config.defaultValues)
                    {
                        newIssue.SetValueByPath(defaultValue.jiraJsonPath, defaultValue.defaultValue);
                    }
                    JiraService.Issue.Issue createdIssue = issueService.CreateAsync(newIssue).Result;
                    createdIssue = issueService.GetAsync(createdIssue.key).Result; //The created issue only contains a shell, no fields
                    issue.SetAttibuteValue(Global.JiraTicket, createdIssue.key);
                    issue.State = createdIssue.fields.status.name;
                }
            }
            return(objectToExecuteOn);
        }
示例#3
0
        public override TCObject Execute(TCObject requirementSet, TCAddOnTaskContext taskContext)
        {
            RequirementSet rs     = (RequirementSet)requirementSet;
            JiraConfig     config = rs.GetJiraConfig();

            #region Setup
            if (config == null)
            {
                string url      = taskContext.GetStringValue("Jira Instance URL: ", false);
                string jqlValue = taskContext.GetStringValue("JQL Filter for requirements: ", false);
                config = new JiraConfig
                {
                    baseURL   = url,
                    jqlFilter = jqlValue,
                    fieldMaps = new List <FieldMap>()
                    {
                        new FieldMap {
                            direction = JiraService.Configuration.Direction.jira_to_tosca, jiraJsonPath = "$.fields.summary", toscaField = "Name"
                        }
                    }
                };
                rs.SaveConfig(config);
            }
            string username, password;
            if (CredentialManager.Instance.Credentials.Any(x => x.BaseURL == config.baseURL))
            {
                Credential credential = CredentialManager.Instance.Credentials.First(x => x.BaseURL == config.baseURL);
                username = credential.Username;
                password = credential.Password;
            }
            else
            {
                username = taskContext.GetStringValue("Jira Username", false);
                password = taskContext.GetStringValue("Jira Password", true);
                CredentialManager.Instance.StoreOrUpdateCredential(new Credential
                {
                    BaseURL     = config.baseURL,
                    Description = "Created by Jira Config",
                    Username    = username,
                    Password    = password
                });
            }
            #endregion

            var    jira         = new JiraService.Jira(config.baseURL, username, password);
            var    issueService = jira.GetIssueService();
            String startTime    = DateTime.Now.ToString("yyyyMMddHHmmss");
            string jql          = config.jqlFilter;
            JiraService.Issue.Issue[]        issues    = null;
            Task <JiraService.Issue.Issue[]> issueTask = null;
            try
            {
                issueTask = issueService.SearchAsync(jql);
                while (!issueTask.IsCompleted)
                {
                    taskContext.ShowStatusInfo($"Gettign issues for JQL: {jql}");
                    System.Threading.Thread.Sleep(100);
                }
                //order the issues so that subtasks are not created before parent tasks
                issues = issueTask.Result.OrderBy(x => x.fields.project.name).ThenBy(x => x.id).ToArray();
                taskContext.ShowStatusInfo("Creating Requirements");
            }
            catch (Exception e)
            {
                string err = e.Message;
                if (e.InnerException != null)
                {
                    err += "\r\n" + e.InnerException.Message;
                }
                taskContext.ShowErrorMessage($"Error synchronising", err);
                taskContext.ShowStatusInfo($"Error synchronising: {err}");
                return(requirementSet);
            }
            HashSet <string> updatedItems = new HashSet <string>();
            if (issues != null)
            {
                foreach (var issue in issues)
                {
                    var req = CreateOrUpdateRequirement(rs, config, issue);
                    updatedItems.Add(req.UniqueId);
                }

                // Prompt status
                taskContext.ShowMessageBox("Jira Sync", issues.Length.ToString() + " requirements have been synchronised.");
            }
            return(null);
        }
示例#4
0
        public override TCObject Execute(TCObject objectToExecuteOn, TCAddOnTaskContext taskContext)
        {
            TCFolder            f           = (TCFolder)objectToExecuteOn;
            IEnumerable <Issue> childIssues = f.Search("->SUBPARTS:Issue").Cast <Issue>();

            var config = f.GetJiraConfig();

            if (config == null)
            {
                string url     = taskContext.GetStringValue("Jira Instance URL: ", false);
                string project = taskContext.GetStringValue("Jira Project Key: ", false);
                config = new JiraConfig {
                    baseURL = url, projectKey = project, fieldMaps = new List <FieldMap>()
                };
                f.SaveConfig(config);
            }
            string username, password;

            if (CredentialManager.Instance.Credentials.Any(x => x.BaseURL == config.baseURL))
            {
                Credential credential = CredentialManager.Instance.Credentials.First(x => x.BaseURL == config.baseURL);
                username = credential.Username;
                password = credential.Password;
            }
            else
            {
                username = taskContext.GetStringValue("Jira Username", false);
                password = taskContext.GetStringValue("Jira Password", true);
                CredentialManager.Instance.StoreOrUpdateCredential(new Credential
                {
                    BaseURL     = config.baseURL,
                    Description = "Created by Jira Config",
                    Username    = username,
                    Password    = password
                });
            }

            var jira         = new JiraService.Jira(config.baseURL, username, password);
            var issueService = jira.GetIssueService();

            foreach (var issue in childIssues)
            {
                string storedIssueKey = string.Empty;
                try
                {
                    storedIssueKey = issue.GetAttributeValue(Global.JiraTicket);
                }
                catch (Exception)
                {
                    throw new Exception("Please prepare project for integration (available from context menu at project level) and then try again");
                }
                if (!string.IsNullOrEmpty(storedIssueKey))
                {
                    var jiraIssue = issueService.GetAsync(storedIssueKey).Result;
                    issue.State = jiraIssue.fields.status.name;
                    issue.Name  = jiraIssue.fields.summary;
                }
                else //No existing Jira issue exists
                {
                    string description = issue.Description;
                    if (issue.Links.Any())
                    {
                        try
                        {
                            var    executionLog         = issue.Links.First().ExecutionTestCaseLog;
                            string executionTableHeader = $"||Step||Result||Description||Duration(sec)";
                            string executionTable       = null;
                            foreach (ExecutionXTestStepLog logEntry in executionLog.ExecutionSubLogs)
                            {
                                string stepDesc = logEntry.AggregatedDescription;

                                if (logEntry.TestStepValueLogsInRightOrder.Count() > 0)
                                {
                                    stepDesc = null;
                                    foreach (var stepVal in logEntry.TestStepValueLogsInRightOrder)
                                    {
                                        string act = $"{(stepVal.Result == ExecutionResult.Passed ? "(/)" : "(x)")} - {stepVal.DisplayedName} - {stepVal.LogInfo}";
                                        if (stepDesc == null)
                                        {
                                            stepDesc = act;
                                        }
                                        else
                                        {
                                            stepDesc = stepDesc + "\r\n" + act;
                                        }
                                    }
                                }
                                stepDesc = stepDesc.Replace('{', ' ').Replace('}', ' ').Replace('|', ' ').Trim();
                                string entry = $"|{logEntry.DisplayedName} |{(logEntry.Result == ExecutionResult.Passed ? "{color:#14892c}" : "{color:#d04437}") + logEntry.Result + "{color}"} |{stepDesc}|{Math.Round(logEntry.Duration / 1000,2)}s|";
                                if (executionTable == null)
                                {
                                    executionTable = entry;
                                }
                                else
                                {
                                    executionTable += "\r\n" + entry;
                                }
                            }
                            description = $"*TEST*: {executionLog.Name}\r\n*Description*:\r\n{executionTableHeader}\r\n{executionTable}";
                        }
                        catch (Exception)
                        {
                            description = issue.Description;
                        }
                    }
                    var newIssue = new JiraService.Issue.Issue
                    {
                        fields = new JiraService.Issue.IssueFields
                        {
                            summary     = issue.Name,
                            description = description,
                            //Create other fields here
                            project = new JiraService.Issue.Field.ProjectField {
                                key = config.projectKey
                            },
                            issuetype = new JiraService.Issue.Field.IssueTypeField {
                                name = "Bug"
                            }
                        }
                    };
                    foreach (var defaultValue in config.defaultValues)
                    {
                        newIssue.SetValueByPath(defaultValue.jiraJsonPath, defaultValue.defaultValue);
                    }
                    JiraService.Issue.Issue createdIssue = issueService.CreateAsync(newIssue).Result;
                    createdIssue = issueService.GetAsync(createdIssue.key).Result; //The created issue only contains a shell, no fields
                    issue.SetAttibuteValue(Global.JiraTicket, createdIssue.key);
                    issue.State = createdIssue.fields.status.name;
                }
            }
            return(objectToExecuteOn);
        }