Example #1
0
        public override void ExecuteCommand()
        {
            //HACK Must be a better way to do this??
            if (string.IsNullOrEmpty(TeamCityServer))
            {
                HelpCommand.Arguments.Add("teamcity");
                HelpCommand.ExecuteCommand();
                return;
            }

            var sw = new Stopwatch();

            sw.Start();
            Console.WriteLine("Attempting to create graph from TeamCity server: {0}", TeamCityServer);
            var api          = new TeamCityApi(TeamCityServer);
            var buildConfigs = string.IsNullOrEmpty(Project)
                                   ? api.GetBuildTypes().ToList()
                                   : api.GetBuildTypes().Where(b => b.ProjectName.Equals(Project, StringComparison.InvariantCultureIgnoreCase)).ToList();

            Console.WriteLine("Processing {0} build configurations...", buildConfigs.Count());
            foreach (var buildConfig in buildConfigs)
            {
                var details = api.GetBuildTypeDetailsById(buildConfig.Id);

                AddSubscribeDataFromTriggers(buildConfig, details);

                if (!NoPublishStep)
                {
                    AddPublishDataFromSteps(buildConfig, details);
                }


                if (!NoArtifact)
                {
                    AddPublishDataFromArtifacts(buildConfig, api);
                }
            }


            if (NoPackageAsVertex)
            {
                BuildGraphWithPackagesAsLabels(_mappings);
                _simpleGraph.ToDirectedGraphML(_simpleGraph.GetVertexIdentity(), _simpleGraph.GetEdgeIdentity(), (s, n) => n.Label = s, (s, e) => e.Label = s.Tag).WriteXml(_outputFilename);
            }
            else
            {
                BuildGraphWithPackagesAsVertices(_mappings);
                _fancyGraph.ToDirectedGraphML(_fancyGraph.GetVertexIdentity(), _fancyGraph.GetEdgeIdentity(), GetNodeFormat(), GetEdgeFormat()).WriteXml(_outputFilename);
            }

            Console.WriteLine();
            sw.Stop();
            OutputElapsedTime(sw);
            Environment.Exit(0);
        }
        private static IEnumerable <string> GetPackageListFromSteps(BuildType buildConfig, TeamCityApi api)
        {
            var packages = new List <string>();
            //Check for nuget publish steps
            var details = api.GetBuildTypeDetailsById(buildConfig.Id);
            var steps   = details.Steps.Where(s => s.Type.Equals("jb.nuget.publish"));

            foreach (var packageNames in steps.Select(publishStep => GetPackageNames(publishStep.Properties.First(p => p.Name.Equals("nuget.publish.files")).value)))
            {
                packages.AddRange(packageNames);
            }
            return(packages);
        }
        private static IEnumerable<string> GetPackageListFromSteps(BuildType buildConfig, TeamCityApi api)
        {
            var packages = new List<string>();
            //Check for nuget publish steps
            var details = api.GetBuildTypeDetailsById(buildConfig.Id);
            var steps = details.Steps.Where(s => s.Type.Equals("jb.nuget.publish"));

            foreach (var packageNames in steps.Select(publishStep => GetPackageNames(publishStep.Properties.First(p => p.Name.Equals("nuget.publish.files")).value)))
            {
                packages.AddRange(packageNames);
            }
            return packages;
        }
        public override int Run(string[] remainingArguments)
        {
            var api = new TeamCityApi(ServerName);

            ResolveBuildTypeId(api);

            if (string.IsNullOrEmpty(_from))
            {
                var latestSuccesfull = api.GetLatestSuccesfulBuildByBuildType(BuildType);
                if (latestSuccesfull != null)
                {
                    _from = latestSuccesfull.Number;
                }
                else
                {
                    throw new ApplicationException(string.Format("Could not find latest build for build type {0}", BuildType));
                }
            }
            if (string.IsNullOrEmpty(_to))
            {
                var runningBuild = api.GetRunningBuildByBuildType(BuildType).FirstOrDefault();
                if (runningBuild != null)
                {
                    _to = runningBuild.Number;
                }
                else
                {
                    throw new ApplicationException(String.Format("Could not resolve a build number for the running build."));
                }
            }

            var buildWithCommitData       = _referenceBuild ?? BuildType;
            var buildTypeDetails          = api.GetBuildTypeDetailsById(BuildType);
            var referenceBuildTypeDetails = !string.IsNullOrEmpty(_referenceBuild) ? api.GetBuildTypeDetailsById(_referenceBuild) : null;

            //TODO TFS collection data should come from the BuildType/VCS root data from TeamCity...but not for now...
            if (!string.IsNullOrEmpty(_from) && !string.IsNullOrEmpty(_to) && !string.IsNullOrEmpty(buildWithCommitData))
            {
                var builds = api.GetBuildsByBuildType(buildWithCommitData);
                if (builds != null)
                {
                    var buildList = builds as List <Build> ?? builds.ToList();
                    ChangeDetails = api.GetChangeDetailsByBuildTypeAndBuildNumber(buildWithCommitData, _from, _to, buildList).ToList();
                    IssueDetails  = api.GetIssuesByBuildTypeAndBuildRange(buildWithCommitData, _from, _to, buildList).ToList();
                }
            }

            var resolvers = CreateExternalIssueResolvers();


            var issueDetailResolver = new IssueDetailResolver(resolvers);
            var issueDetails        = issueDetailResolver.GetExternalIssueDetails(IssueDetails);

            ChangeManifest.ChangeDetails.AddRange(ChangeDetails);
            ChangeManifest.IssueDetails.AddRange(issueDetails);
            ChangeManifest.Generated                   = DateTime.Now;
            ChangeManifest.FromVersion                 = _from;
            ChangeManifest.ToVersion                   = _to;
            ChangeManifest.BuildConfiguration          = buildTypeDetails;
            ChangeManifest.ReferenceBuildConfiguration = referenceBuildTypeDetails ?? new BuildTypeDetails();


            OutputChanges(CreateOutputRenderers(), new List <Action <string> >()
            {
                Console.Write,
                a =>
                {
                    if (!string.IsNullOrEmpty(OutputFileName))
                    {
                        File.WriteAllText(OutputFileName, a);
                    }
                }
            });
            return(0);
        }
        public override int Run(string[] remainingArguments)
        {
            var api = new TeamCityApi(ServerName);

            ResolveBuildTypeId(api);

            if (string.IsNullOrEmpty(_from))
            {
                var latestSuccesfull = api.GetLatestSuccesfulBuildByBuildType(BuildType);
                if (latestSuccesfull != null)
                    _from = latestSuccesfull.Number;
                else
                    throw new ApplicationException(string.Format("Could not find latest build for build type {0}", BuildType));
            }
            if (string.IsNullOrEmpty(_to))
            {
                var runningBuild = api.GetRunningBuildByBuildType(BuildType).FirstOrDefault();
                if (runningBuild != null)
                    _to = runningBuild.Number;
                else
                    throw new ApplicationException(String.Format("Could not resolve a build number for the running build."));
            }

            var buildWithCommitData = _referenceBuild ?? BuildType;
            var buildTypeDetails = api.GetBuildTypeDetailsById(BuildType);
            var referenceBuildTypeDetails = !string.IsNullOrEmpty(_referenceBuild) ? api.GetBuildTypeDetailsById(_referenceBuild) : null;
            //TODO TFS collection data should come from the BuildType/VCS root data from TeamCity...but not for now...
            if (!string.IsNullOrEmpty(_from) && !string.IsNullOrEmpty(_to) && !string.IsNullOrEmpty(buildWithCommitData))
            {
                var builds = api.GetBuildsByBuildType(buildWithCommitData);
                if (builds != null)
                {
                    var buildList = builds as List<Build> ?? builds.ToList();
                    ChangeDetails = api.GetChangeDetailsByBuildTypeAndBuildNumber(buildWithCommitData, _from, _to, buildList).ToList();
                    IssueDetails = api.GetIssuesByBuildTypeAndBuildRange(buildWithCommitData, _from, _to, buildList).ToList();
                }
            }

            var resolvers = CreateExternalIssueResolvers();

            var issueDetailResolver = new IssueDetailResolver(resolvers);
            var issueDetails = issueDetailResolver.GetExternalIssueDetails(IssueDetails);
            ChangeManifest.ChangeDetails.AddRange(ChangeDetails);
            ChangeManifest.IssueDetails.AddRange(issueDetails);
            ChangeManifest.Generated = DateTime.Now;
            ChangeManifest.FromVersion = _from;
            ChangeManifest.ToVersion = _to;
            ChangeManifest.BuildConfiguration = buildTypeDetails;
            ChangeManifest.ReferenceBuildConfiguration = referenceBuildTypeDetails ?? new BuildTypeDetails();

            OutputChanges(CreateOutputRenderers(),new List<Action<string>>()
                {
                    Console.Write,
                    a =>
                        {
                            if (!string.IsNullOrEmpty(OutputFileName))
                                File.WriteAllText(OutputFileName, a);
                        }
                });
            return 0;
        }