Exemple #1
0
        private void ReadAllFromJira()
        {
            #region Code
            IJiraClient jiraclient = new JiraClient(@"https://seventechnology.jira.com", "andy", "L1verp00l1");

            // =========== GET CURRENT PATH OF SOLUTION
            //string currpath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            //string FilePath = "D:\\aDnan\\Projects\\JiraAddin\\SpecFlowTest\\SpecFlowTest\\Features\\";
            //string TemplatePath = "C:\\deps\\SpecFlow\\ItemTemplates\\SpecFlowFeature\\SpecFlowFeature.vstemplate";


            EnvDTE.Project     project;
            EnvDTE.ProjectItem features;
            EnvDTE.ProjectItem feature;

            //get the project
            project = _applicationObject.Solution.Projects.Item(1);

            string FilePath = project.FullName;
            FilePath = FilePath.Substring(0, FilePath.LastIndexOf('\\')) + "\\Features\\";

            string TemplatePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            TemplatePath = TemplatePath.Substring(0, TemplatePath.LastIndexOf('\\')) + "\\Template\\SpecFlowFeature.vstemplate";


            List <Issue> allissuelist = jiraclient.GetIssues("XPL", "Story").ToList();

            foreach (Issue iss in allissuelist)
            {
                Issue        sissue      = null;
                List <Issue> issuelist   = null;
                string       ParentIssue = iss.key;
                List <Issue> Subtasks    = jiraclient.GetSubTasksOfIssue("XPL", ParentIssue, "Scenario").ToList();

                issuelist = jiraclient.GetIssue("XPL", ParentIssue).ToList();
                if (issuelist.Count > 0)
                {
                    sissue = issuelist[0];
                }



                //add the folders we want
                try
                {
                    features = project.ProjectItems.AddFolder("Features");
                    // add the features folder if its not there
                }
                catch
                {
                    //if it is there allready we need to get it
                    features = project.ProjectItems.Item("Features");
                    //features = _applicationObject.Solution.FindProjectItem("Features");
                }
                try
                {
                    string contents = string.Empty;
                    try
                    {
                        feature = features.ProjectItems.AddFromTemplate(TemplatePath, ParentIssue);
                    }
                    catch (COMException e)
                    {
                        contents = File.ReadAllText(FilePath + ParentIssue + ".feature");
                    }
                    if (File.Exists(FilePath + ParentIssue + ".feature"))
                    {
                        if (Subtasks.Count > 0)
                        {
                            int count = 0;
                            foreach (Issue issue in Subtasks)
                            {
                                if (count == 0)
                                {
                                    string Text = "Feature: " + sissue.key + "\n" + issue.fields.summary + "\n\n" + "Scenario: " + issue.fields.summary + "\n" + "@Story\n" + issue.fields.description + "\n\n";
                                    File.WriteAllText(FilePath + ParentIssue + ".feature", Text);
                                    count++;
                                }
                                else
                                {
                                    string Text = "Scenario: " + issue.fields.summary + "\n" + "@Story\n" + issue.fields.description + "\n\n";
                                    File.AppendAllText(FilePath + ParentIssue + ".feature", Text);
                                }
                            }
                        }
                        else
                        {
                            string Text = "Feature: " + sissue.key + "\n" + sissue.fields.summary + "\n\n" + "Scenario: " + sissue.fields.summary + "\n" + "@Story\n" + sissue.fields.description + "\n\n";
                            File.WriteAllText(FilePath + ParentIssue + ".feature", Text);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                }
            }
            #endregion
        }
Exemple #2
0
        private void WriteToJira()
        {
            #region Code
            // string FilePath = "D:\\aDnan\\Projects\\JiraAddin\\SpecFlowTest\\SpecFlowTest\\Features\\";
            string FileName = GetFileName();
            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }
            EnvDTE.Project project;
            //get the project
            project = _applicationObject.Solution.Projects.Item(1);
            string FilePath = project.FullName;
            FilePath = FilePath.Substring(0, FilePath.LastIndexOf('\\')) + "\\Features\\";

            try
            {
                IJiraClient jiraclient           = new JiraClient(@"https://seventechnology.jira.com", "andy", "L1verp00l1");
                string      contents             = System.IO.File.ReadAllText(FilePath + FileName);
                int         i                    = contents.IndexOf(":");
                int         indexOfFirstLine     = contents.IndexOf("\n");
                int         indexOfFirstScenario = contents.IndexOf("Scenario:");
                string      FeatureName          = contents.Substring(i + 2, (indexOfFirstLine - (i + 2)));
                string      FeatureDescription   = contents.Substring(indexOfFirstLine + 1, (indexOfFirstScenario - (indexOfFirstLine + 1)));

                int count = new Regex("Scenario:").Matches(contents).Count;
                if (count > 1)
                {
                    // Create issue with subtask & empty description on jira.

                    Issue objIssue = jiraclient.CreateIssue("XPL", "Story", FeatureDescription);

                    string        OnlyScenarios = contents.Substring(indexOfFirstScenario);
                    string[]      Seperator     = new string[] { "Scenario:" };
                    List <string> Scenarios     = OnlyScenarios.Split(Seperator, StringSplitOptions.None).ToList();
                    Scenarios.RemoveAt(0);
                    foreach (string Scenario in Scenarios)
                    {
                        int    indexOfStoryTag = Scenario.IndexOf("@Story");
                        string Summary         = Scenario.Substring(1, indexOfStoryTag - 1);
                        Summary = Summary.Remove(Summary.IndexOf("\n"), 1);
                        string Story = Scenario.Substring(indexOfStoryTag + 7);
                        Story = Story.Remove(Story.IndexOf("\n"), 1);
                        try
                        {
                            jiraclient.CreateSubTask("XPL", objIssue.key, "Scenario", Summary, Story);
                        }
                        catch { }
                    }
                }
                else
                {
                    string Scenario = contents.Substring(indexOfFirstScenario + 9);

                    int indexOfStoryTag = Scenario.IndexOf("@Story");

                    string Summary = Scenario.Substring(1, indexOfStoryTag - 1);
                    Summary = Summary.Remove(Summary.IndexOf("\n"), 1);

                    string Story = Scenario.Substring(indexOfStoryTag + 7);
                    Story = Story.Remove(Story.IndexOf("\n"), 1);
                    try
                    {
                        Issue objIssue = jiraclient.CreateIssue("XPL", "Story", Summary, Story);
                    }
                    catch { }
                    // Create issue with description as a scenario in it.
                }
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
            }
            #endregion
        }