public void CreateFilingTarget_ThrowsIfUriIsNull
            ()
        {
            Action action = () => FilingTargetFactory.CreateFilingTarget(null);

            action.Should().Throw <ArgumentNullException>();
        }
        public void CreateFilingTarget_CreatesAzureDevOpsFilingTarget()
        {
            const string ProjectUriString = "https://dev.azure.com/myOrg/myProject";

            var filingTarget = FilingTargetFactory.CreateFilingTarget(ProjectUriString);

            filingTarget.Should().BeOfType <AzureDevOpsFilingTarget>();
        }
        public void CreateFilingTarget_CreatesGitHubFilingTarget()
        {
            const string ProjectUriString = "https://github.com/myOrg/myProject";

            var filingTarget = FilingTargetFactory.CreateFilingTarget(ProjectUriString);

            filingTarget.Should().BeOfType <GitHubFilingTarget>();
        }
        public void CreateFilingTarget_ThrowsIfUriIncludesAdditionalPathSegments()
        {
            const string ProjectUriString = "https://github.com/myOrg/myProject/issues";

            Action action = () => FilingTargetFactory.CreateFilingTarget(ProjectUriString);

            action.Should().Throw <ArgumentException>().WithMessage($"*{ProjectUriString}*");
        }
        public void CreateFilingTarget_ThrowsIfUriPatternIsNotRecognized()
        {
            const string ProjectUriString = "https://www.example.com/myOrg/myProject";

            Action action = () => FilingTargetFactory.CreateFilingTarget(ProjectUriString);

            action.Should().Throw <ArgumentException>().WithMessage($"*{ProjectUriString}*");
        }
Esempio n. 6
0
        public int Run(FileWorkItemsOptions options, IFileSystem fileSystem)
        {
            if (!ValidateOptions(options, fileSystem))
            {
                return(FAILURE);
            }

            // For unit tests: allow us to just validate the options and return.
            if (s_validateOptionsOnly)
            {
                return(SUCCESS);
            }

            string projectName = options.ProjectUri.GetProjectName();

            string logFileContents = fileSystem.ReadAllText(options.InputFilePath);

            EnsureValidSarifLogFile(logFileContents, options.InputFilePath);

            FilingTarget filingTarget = FilingTargetFactory.CreateFilingTarget(options.ProjectUriString);
            var          filer        = new WorkItemFiler(filingTarget);

            SarifLog sarifLog = JsonConvert.DeserializeObject <SarifLog>(logFileContents);

            if (options.DataToRemove != null)
            {
                var dataRemovingVisitor = new RemoveOptionalDataVisitor(options.DataToRemove.ToFlags());
                dataRemovingVisitor.Visit(sarifLog);
            }

            for (int runIndex = 0; runIndex < sarifLog.Runs.Count; ++runIndex)
            {
                if (sarifLog.Runs[runIndex]?.Results?.Count > 0)
                {
                    IList <SarifLog> logsToProcess = new List <SarifLog>(new SarifLog[] { sarifLog });

                    if (options.GroupingStrategy != GroupingStrategy.PerRun)
                    {
                        SplittingVisitor visitor = (options.GroupingStrategy == GroupingStrategy.PerRunPerRule
                            ? (SplittingVisitor) new PerRunPerRuleSplittingVisitor()
                            : new PerRunPerTargetPerRuleSplittingVisitor());

                        visitor.VisitRun(sarifLog.Runs[runIndex]);
                        logsToProcess = visitor.SplitSarifLogs;
                    }

                    IList <WorkItemFilingMetadata> workItemMetadata = new List <WorkItemFilingMetadata>(logsToProcess.Count);

                    for (int splitFileIndex = 0; splitFileIndex < logsToProcess.Count; splitFileIndex++)
                    {
                        SarifLog splitLog = logsToProcess[splitFileIndex];
                        workItemMetadata.Add(splitLog.CreateWorkItemFilingMetadata(projectName, options.TemplateFilePath));
                    }

                    try
                    {
                        IEnumerable <WorkItemFilingMetadata> filedWorkItems = filer.FileWorkItems(options.ProjectUri, workItemMetadata, options.PersonalAccessToken).Result;

                        Console.WriteLine($"Created {filedWorkItems.Count()} work items for run {runIndex}.");
                    }
                    catch (Exception ex)
                    {
                        Console.Error.WriteLine(ex);
                    }
                }
            }

            Console.WriteLine($"Writing log with work item Ids to {options.OutputFilePath}.");
            WriteSarifFile <SarifLog>(fileSystem, sarifLog, options.OutputFilePath, (options.PrettyPrint ? Formatting.Indented : Formatting.None));

            return(SUCCESS);
        }