From 093a286f7f2498929be795d8220ad0020d0c4532 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Tue, 23 Feb 2021 21:52:57 -0300 Subject: [PATCH] Fixing AzureDevops title maxLength (#2292) * Fixing AzureDevops title maxLength * Adding releasehistory and updating tests * Update ReleaseHistory.md Co-authored-by: Michael C. Fanning --- src/ReleaseHistory.md | 3 +++ src/Sarif.WorkItems/SarifWorkItemsExtensions.cs | 10 +++++----- .../SarifWorkItemExtensionsTests.cs | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index 12ed899a8..83b778e34 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -1,5 +1,8 @@ # SARIF Package Release History (SDK, Driver, Converters, and Multitool) +* FEATURE: `ConstructMultilineContextSnippet` will retrieve a few character after/before to prevent entire file when the file is one line only. [#2288](https://github.com/microsoft/sarif-sdk/pull/2288) +* BUGFIX: Fix AzureDevOps title maxLength. [#2292](https://github.com/microsoft/sarif-sdk/pull/2292) + ## **v2.4.1** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.4.1) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.4.1) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.4.1) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.4.1) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/2.4.1) * BREAKING: Move `transform` functionality into `rewrite` and delete redundant `transform` command. [#2252](https://github.com/microsoft/sarif-sdk/pull/2252) * FEATURE: kind, level, insert, and remove options can now be added to from environment variables. [#2273](https://github.com/microsoft/sarif-sdk/pull/2273) diff --git a/src/Sarif.WorkItems/SarifWorkItemsExtensions.cs b/src/Sarif.WorkItems/SarifWorkItemsExtensions.cs index 807033ce0..80961891c 100644 --- a/src/Sarif.WorkItems/SarifWorkItemsExtensions.cs +++ b/src/Sarif.WorkItems/SarifWorkItemsExtensions.cs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; namespace Microsoft.CodeAnalysis.Sarif.WorkItems { @@ -24,7 +24,7 @@ public static bool ShouldBeFiled(this Result result) // // Open: a sound analysis is 'open' indicating that the analysis requires // more configuration or other data in order to produce a determination. - // + // // Review: an open item which can't be automated, i.e., which requires a // manual review to resolve. return result.Kind == ResultKind.Fail || @@ -34,7 +34,7 @@ public static bool ShouldBeFiled(this Result result) // Designations which are not appropriate for filing: // // Pass: the scan target explicitly passed analysis. - // + // // Not applicable: analysis was skipped because it was not // relevant to the scan target. // @@ -82,9 +82,9 @@ public static string CreateWorkItemTitle(this Run run) firstResult.Level.ToString() + "]: " + fullRuleId; - // In ADO, the title cannot be longer than 256 characters + // In ADO, the title cannot be longer than 255 characters const string ellipsis = "..."; - const int maxChars = 256; + const int maxChars = 255; int remainingChars = maxChars - titlePrefix.Length - 6; // " ({0})".Length == 6 // We encapsulate logical names in apostrophes to help indicate they are a symbol diff --git a/src/Test.UnitTests.Sarif.WorkItems/SarifWorkItemExtensionsTests.cs b/src/Test.UnitTests.Sarif.WorkItems/SarifWorkItemExtensionsTests.cs index 810d7b372..e0c173b4b 100644 --- a/src/Test.UnitTests.Sarif.WorkItems/SarifWorkItemExtensionsTests.cs +++ b/src/Test.UnitTests.Sarif.WorkItems/SarifWorkItemExtensionsTests.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel; using System.Text; using FluentAssertions; @@ -60,7 +60,7 @@ public void SarifWorkItemExtensions_CreateWorkItemTitle_HandlesSingleResultWithR [Fact] public void SarifWorkItemExtensions_CreateWorkItemTitle_LongTitleFromUrl() { - int maxLength = 256; + int maxLength = 255; string ruleId = "TestRuleId"; string expectedTemplate = "[aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:Warning]: TestRuleId: Test Rule (in al...)"; string expected = $":Warning]: TestRuleId: Test Rule (in al" + new string('a', maxLength - expectedTemplate.Length) + "...)"; @@ -97,7 +97,7 @@ public void SarifWorkItemExtensions_CreateWorkItemTitle_LongTitleFromLogicalLoca run.Results.Add(result); // A logical location longer than 128 char is truncated with ellipses - int maxLength = 256; + int maxLength = 255; string expectedTemplate = "[aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:Warning]: TestRuleId: Test Rule (in 'll...')"; string expected = $":Warning]: TestRuleId: Test Rule (in 'll" + new string('b', maxLength - expectedTemplate.Length) + "...')"; result.Locations[0].LogicalLocation.FullyQualifiedName = "ll" + new string('b', 1024);