-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.ps1
97 lines (90 loc) · 3.37 KB
/
lint.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Configuration
param (
[string]$FolderToCheck = 'C:\atomsphere-repo\components',
[string]$BoomiAccountId = 'company-ABC1DE',
[string]$RulesFileName = 'BoomiSonarQubeRules.xml'
)
function Run-XPath([xml]$Document, [string]$Xpath) {
return Select-Xml -XPath $xpath -Xml $Document -Namespace @{"bns" = "http://api.platform.boomi.com/"}
}
function Build-Result([string]$RuleId, [string]$Text, [string]$Level, [xml]$Component) {
$artifactLocation = @{"uri"="https://platform.boomi.com/AtomSphere.html#build;accountId=" + $BoomiAccountId + ";components=" + $Component.Result.componentId + "~" + $Component.Result.version}
$physicalLocation = @{"artifactLocation"=$artifactLocation}
$logicalLocations = @(@{ "name"=$Component.Result.name
"fullyQualifiedName"= $Component.Result.folderFullPath + '/' + $Component.Result.name
})
$locations = @(@{ "physicalLocation"=$physicalLocation
"logicalLocations"=$logicalLocations
})
$r = @{
"level" = $Level
"ruleId" = $RuleId
"locations"=$locations
}
if ($Text.Length -gt 0) {
$r.Add("message", @{"text" = $Text})
} else {
$r.Add("message", @{"id" = "default"})
}
return $r
}
function Build-RuleMeta([string]$RuleId, [string]$RuleName, [string]$DefaultMessage) {
return @{
"id" = $RuleId
"name" = $RuleName
"messageStrings"=@{"default"=@{"text" = $DefaultMessage}}
}
}
function Format-RulesMeta([Xml]$Rules){
return ($Rules.profile.rules.rule | %{
$msg = Select-Xml -Xml $_ -XPath "parameters/parameter[key = 'message']/value"
Build-RuleMeta -RuleId $_.key -RuleName $_.name -DefaultMessage $msg
} | ConvertTo-Json -Depth 5
)
}
function Get-Results([string]$FolderToCheck, [xml]$Rules) {
$results = [System.Collections.ArrayList]@()
Get-ChildItem $FolderToCheck -Filter "*.xml" | ForEach-Object {
[Xml]$component = Get-content (join-path $FolderToCheck $_)
if ($component.Result.deleted -ne $true) { # ignore things that are deleted
$Rules.profile.rules.rule | %{
$expression = Select-Xml -Xml $_ -XPath "parameters/parameter[key = 'expression']/value"
$r = Run-XPath -Document $component -Xpath $expression
if ($r) {
$j = Build-Result -RuleId $_.key -Level $_.priority -Component $component
$count = $results.Add($j)
}
}
}
}
return $results
}
function ConvertTo-Sarif([string]$FolderToCheck, [string]$BoomiAccountId, [string]$RulesFileName){
[Xml]$Rules = Get-content $RulesFileName
return @"
{
"version": "2.1.0",
"
"@ + '$' + @"
schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"runs": [
{
"tool": {
"driver": {
"name": "boomi-lint",
"version" : "0.1-beta",
"informationUri":"https://github.com/richard087/boomi-lint",
"rules" :
"@ +
(Format-RulesMeta -Rules $Rules ) + @"
}
},
"results" :
"@ +
( Get-Results -FolderToCheck $FolderToCheck -Rules $Rules | ConvertTo-Json -Depth 5) + @"
}
]
}
"@
}
ConvertTo-Sarif -FolderToCheck $FolderToCheck -BoomiAccountId $BoomiAccountId -RulesFileName $RulesFileName