Skip to content

Commit 5381b83

Browse files
committed
adding SARIF compare tool
1 parent 4cc2367 commit 5381b83

File tree

3 files changed

+230
-17
lines changed

3 files changed

+230
-17
lines changed

src/CodeQLToolkit.Features/Bundle/Commands/BundleCommandFeature.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodeQLToolkit.Shared.Utils;
1+
using CodeQLToolkit.Features.Bundle.Commands.Targets;
2+
using CodeQLToolkit.Shared.Utils;
23
using System;
34
using System.Collections.Generic;
45
using System.CommandLine;
@@ -35,29 +36,33 @@ public void Register(Command parentCommand)
3536

3637

3738
var runCommand = new Command("run", "Functions pertaining running bundle commands.");
38-
parentCommand.Add(runCommand);
3939

40-
//var checkQueryQueriesCommand = new Command("check-queries", "Checks the query metadata for the specified language.");
4140

42-
//var languageOption = new Option<string>("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray());
41+
var validateIntegrationTestsCommand = new Command("validate-integration-tests", "Validates the results of an integration test using a semantic diff.");
42+
var expectedOption = new Option<string>("--expected", "The SARIF file containing the expected results.") { IsRequired = true };
43+
var actualOption = new Option<string>("--actual", "The SARIF file containing the actual results.") { IsRequired = true };
44+
45+
validateIntegrationTestsCommand.Add(expectedOption);
46+
validateIntegrationTestsCommand.Add(actualOption);
4347

44-
//checkQueryQueriesCommand.Add(languageOption);
48+
runCommand.Add(validateIntegrationTestsCommand);
49+
50+
parentCommand.Add(runCommand);
4551

46-
//runCommand.Add(checkQueryQueriesCommand);
4752

53+
validateIntegrationTestsCommand.SetHandler((basePath, expected, actual) =>
54+
{
55+
Log<BundleCommandFeature>.G().LogInformation("Executing validate-integration-tests command...");
4856

49-
//checkQueryQueriesCommand.SetHandler((language, basePath, prettyPrint) =>
50-
//{
51-
// Log<BundleCommandFeature>.G().LogInformation("Executing check-query-metadata command...");
57+
new ValidateIntegrationTestResults()
58+
{
59+
Base = basePath,
60+
Expected = expected,
61+
Actual = actual
5262

53-
// new CheckQueriesCommandTarget()
54-
// {
55-
// Base = basePath,
56-
// Language = language,
57-
// PrettyPrint = prettyPrint,
58-
// }.Run();
63+
}.Run();
5964

60-
//}, languageOption, Globals.BasePathOption, prettyPrintOption);
65+
},Globals.BasePathOption, expectedOption, actualOption);
6166
}
6267

6368
public int Run()

src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<Folder Include="Bundle\Commands\Targets\" />
1514
<Folder Include="Bundle\Lifecycle\Targets\Actions\" />
1615
<Folder Include="Bundle\Models\" />
1716
<Folder Include="Pack\" />
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CodeQLToolkit.Shared.Types
8+
{
9+
public class SARIFResult
10+
{
11+
public Run[] runs { get; set; }
12+
public string schema { get; set; }
13+
public string version { get; set; }
14+
15+
public string? RawSARIF { get; set; }
16+
}
17+
18+
public class Run
19+
{
20+
public Artifact[] artifacts { get; set; }
21+
public Automationdetails automationDetails { get; set; }
22+
public Conversion conversion { get; set; }
23+
public Result[] results { get; set; }
24+
public Tool1 tool { get; set; }
25+
public Versioncontrolprovenance[] versionControlProvenance { get; set; }
26+
}
27+
28+
public class Automationdetails
29+
{
30+
public string id { get; set; }
31+
}
32+
33+
public class Conversion
34+
{
35+
public Tool tool { get; set; }
36+
}
37+
38+
public class Tool
39+
{
40+
public Driver driver { get; set; }
41+
}
42+
43+
public class Driver
44+
{
45+
public string name { get; set; }
46+
}
47+
48+
public class Tool1
49+
{
50+
public Driver1 driver { get; set; }
51+
public Extension[] extensions { get; set; }
52+
}
53+
54+
public class Driver1
55+
{
56+
public string name { get; set; }
57+
public string semanticVersion { get; set; }
58+
}
59+
60+
public class Extension
61+
{
62+
public string name { get; set; }
63+
public string semanticVersion { get; set; }
64+
public Rule[] rules { get; set; }
65+
}
66+
67+
public class Rule
68+
{
69+
public Defaultconfiguration defaultConfiguration { get; set; }
70+
public Fulldescription fullDescription { get; set; }
71+
public Help help { get; set; }
72+
public string id { get; set; }
73+
public string name { get; set; }
74+
public Properties properties { get; set; }
75+
public Shortdescription shortDescription { get; set; }
76+
}
77+
78+
public class Defaultconfiguration
79+
{
80+
public string level { get; set; }
81+
}
82+
83+
public class Fulldescription
84+
{
85+
public string text { get; set; }
86+
}
87+
88+
public class Help
89+
{
90+
public string markdown { get; set; }
91+
public string text { get; set; }
92+
}
93+
94+
public class Properties
95+
{
96+
public string precision { get; set; }
97+
public string queryURI { get; set; }
98+
public string securityseverity { get; set; }
99+
public string[] tags { get; set; }
100+
}
101+
102+
public class Shortdescription
103+
{
104+
public string text { get; set; }
105+
}
106+
107+
public class Artifact
108+
{
109+
public Location location { get; set; }
110+
}
111+
112+
public class Location
113+
{
114+
public int index { get; set; }
115+
public string uri { get; set; }
116+
}
117+
118+
public class Result
119+
{
120+
public string correlationGuid { get; set; }
121+
public string level { get; set; }
122+
123+
public Location1[] locations { get; set; }
124+
125+
public string LocationsString()
126+
{
127+
128+
List<string> _locations = new List<string>();
129+
130+
foreach (var location in locations)
131+
{
132+
_locations.Add(location.ToString());
133+
}
134+
135+
return string.Join(", ", _locations);
136+
137+
}
138+
public Message message { get; set; }
139+
public Partialfingerprints partialFingerprints { get; set; }
140+
public Properties1 properties { get; set; }
141+
public Rule1 rule { get; set; }
142+
public string ruleId { get; set; }
143+
}
144+
145+
public class Message
146+
{
147+
public string text { get; set; }
148+
}
149+
150+
public class Partialfingerprints
151+
{
152+
public string primaryLocationLineHash { get; set; }
153+
}
154+
155+
public class Properties1
156+
{
157+
public int githubalertNumber { get; set; }
158+
public string githubalertUrl { get; set; }
159+
}
160+
161+
public class Rule1
162+
{
163+
public string id { get; set; }
164+
public Toolcomponent toolComponent { get; set; }
165+
public int index { get; set; }
166+
}
167+
168+
public class Toolcomponent
169+
{
170+
public int index { get; set; }
171+
}
172+
173+
public class Location1
174+
{
175+
public Physicallocation physicalLocation { get; set; }
176+
177+
public override string ToString()
178+
{
179+
return $"{physicalLocation.artifactLocation.uri}:{physicalLocation.region.startLine}:{physicalLocation.region.startColumn}-{physicalLocation.region.endLine}:{physicalLocation.region.endColumn}";
180+
}
181+
}
182+
183+
public class Physicallocation
184+
{
185+
public Artifactlocation artifactLocation { get; set; }
186+
public Region region { get; set; }
187+
}
188+
189+
public class Artifactlocation
190+
{
191+
public int index { get; set; }
192+
public string uri { get; set; }
193+
}
194+
195+
public class Region
196+
{
197+
public int endColumn { get; set; }
198+
public int endLine { get; set; }
199+
public int startColumn { get; set; }
200+
public int startLine { get; set; }
201+
}
202+
203+
public class Versioncontrolprovenance
204+
{
205+
public string branch { get; set; }
206+
public string repositoryUri { get; set; }
207+
public string revisionId { get; set; }
208+
}
209+
}

0 commit comments

Comments
 (0)