public List <JiraProjectVersionSemVerAdapter> JiraProjectVersionsToJiraProjectVersionSemVerAdapters(
            SemanticVersionParser semVerParser,
            IEnumerable <JiraProjectVersion> jiraProjectVersions)
        {
            var versionList = new List <JiraProjectVersionSemVerAdapter>();

            foreach (var version in jiraProjectVersions)
            {
                try
                {
                    versionList.Add(
                        new JiraProjectVersionSemVerAdapter()
                    {
                        JiraProjectVersion = version,
                        SemanticVersion    = semVerParser.ParseVersion(version.name)
                    });
                }
                catch (ArgumentException)
                {
                    //Empty Catch. Invalid versions are not relevant for us
                }
            }

            return(versionList);
        }
        private JiraProjectVersionComparableAdapter <SemanticVersion> CreateSemanticVersion(string version)
        {
            var semanticVersionParser = new SemanticVersionParser();

            return(new JiraProjectVersionComparableAdapter <SemanticVersion> {
                ComparableVersion = semanticVersionParser.ParseVersion(version)
            });
        }
        private List <JiraProjectVersionComparableAdapter <SemanticVersion> > CreateSemanticJiraProjectVersions(params string[] versions)
        {
            var jiraProjectVersionComparableAdapterList = new List <JiraProjectVersionComparableAdapter <SemanticVersion> >();
            var semanticVersionParser = new SemanticVersionParser();

            foreach (var version in versions)
            {
                jiraProjectVersionComparableAdapterList.Add(
                    new JiraProjectVersionComparableAdapter <SemanticVersion>()
                {
                    JiraProjectVersion = new JiraProjectVersion()
                    {
                        name = version
                    },
                    ComparableVersion = version == null ? null : semanticVersionParser.ParseVersion(version)
                });
            }

            return(jiraProjectVersionComparableAdapterList);
        }
Beispiel #4
0
        public void SemVer_WithourPre_ShouldParse()
        {
            string version = "1.2.3";

            Remotion.BuildTools.MSBuildTasks.Jira.SemanticVersioning.SemanticVersion semver = _semanticVersionParser.ParseVersion(version);

            Assert.AreEqual(1, semver.Major);
            Assert.AreEqual(2, semver.Minor);
            Assert.AreEqual(3, semver.Patch);

            Assert.IsNull(semver.Pre);
            Assert.IsNull(semver.PreReleaseCounter);
        }
Beispiel #5
0
        public void ReleaseVersionAndSquashUnreleased(string versionID, string nextVersionID, string projectKey)
        {
            if (versionID != nextVersionID)
            {
                var versions = jiraProjectVersionFinder.GetVersions(projectKey);

                SemanticVersionParser _semanticVersionParser       = new SemanticVersionParser();
                List <JiraProjectVersionSemVerAdapter> versionList = new List <JiraProjectVersionSemVerAdapter>();

                foreach (var version in versions)
                {
                    try
                    {
                        versionList.Add(new JiraProjectVersionSemVerAdapter()
                        {
                            JiraProjectVersion = version,
                            SemanticVersion    = _semanticVersionParser.ParseVersion(version.name)
                        });
                    }
                    catch (ArgumentException)
                    {
                        //Empty Catch. Invalid versions are not interesting for us
                    }
                }

                var currentVersion = versionList.Single(v => v.JiraProjectVersion.id == versionID).JiraProjectVersion;
                var nextVersion    = versionList.Single(v => v.JiraProjectVersion.id == nextVersionID).JiraProjectVersion;

                var orderedVersions     = versionList.OrderBy(x => x.SemanticVersion).ToList();
                var currentVersionIndex = orderedVersions.IndexOf(orderedVersions.Single(x => x.JiraProjectVersion.id == versionID));
                var nextVersionIndex    = orderedVersions.IndexOf(orderedVersions.Single(x => x.JiraProjectVersion.id == nextVersionID));

                //There are versions between the currentVersion and the next version
                if (nextVersionIndex != currentVersionIndex + 1)
                {
                    //We want all Elements "(startVersion, nextVersion)" as we are interested in all versions after the currently to be released Version
                    var toBeSquashedVersions = orderedVersions.Skip(currentVersionIndex + 1).Take(nextVersionIndex - currentVersionIndex - 1).ToList();

                    if (toBeSquashedVersions.Any(IsReleased))
                    {
                        throw new JiraException(
                                  "Version '" + currentVersion.name + "' cannot be released, as there is already one or multiple released version(s) ("
                                  + string.Join(",", toBeSquashedVersions.Where(IsReleased).Select(t => t.JiraProjectVersion.name)) + ") before the next version '"
                                  + nextVersion.name + "'.");
                    }

                    var allClosedIssues = new List <JiraToBeMovedIssue>();

                    foreach (var toBeSquashedVersion in toBeSquashedVersions)
                    {
                        allClosedIssues.AddRange(jiraIssueService.FindAllClosedIssues(toBeSquashedVersion.JiraProjectVersion.id));
                    }

                    if (allClosedIssues.Count != 0)
                    {
                        throw new JiraException(
                                  "Version '" + currentVersion.name + "' cannot be released, as one  or multiple versions contain closed issues ("
                                  + string.Join(", ", allClosedIssues.Select(aci => aci.key)) + ")"
                                  );
                    }

                    foreach (var toBeSquashedVersion in toBeSquashedVersions)
                    {
                        var toBeSquashedJiraProjectVersion = toBeSquashedVersion.JiraProjectVersion;

                        if (toBeSquashedJiraProjectVersion.released == null || toBeSquashedJiraProjectVersion.released == false)
                        {
                            var toBeSquashedVersionID = toBeSquashedJiraProjectVersion.id;

                            var nonClosedIssues = jiraIssueService.FindAllNonClosedIssues(toBeSquashedVersionID);
                            jiraIssueService.MoveIssuesToVersion(nonClosedIssues, toBeSquashedVersionID, nextVersionID);

                            this.DeleteVersion(projectKey, toBeSquashedJiraProjectVersion.name);
                        }
                    }
                }

                ReleaseVersion(versionID, nextVersionID);
            }
        }