-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyze.ps1
More file actions
146 lines (107 loc) · 3.71 KB
/
Copy pathAnalyze.ps1
File metadata and controls
146 lines (107 loc) · 3.71 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
clear
#$repoName = "code-examples-csharp"
#$repoSource = "https://github.com/docusign/$repoName.git"
$repoName = "MyCustomerApp"
$repoSource = "https://github.com/neildouek/$repoName.git"
#MyCustomerApp
#extremedevops
#repo-test1
$workingDir = "/Users/neildouek1/Documents/fujitsu/dev/workingdir"
$jsonChecks = "/Users/neildouek1/Documents/fujitsu/dev/GitAnalysis/checks.json"
Import-Module ./Invoke-CloneRepo.ps1
Import-Module ./Remove-Directory.ps1
Import-Module ./Invoke-Check.ps1
RemoveDirectory -Path $workingDir
$dirRepo = $workingDir+"/repo"
$dirData = $workingDir+"/data"
$repoPath = "$dirRepo/$repoName"
RemoveDirectory -Path $dirRepo
mkdir $dirRepo
mkdir $dirData
$dataFileName = $dirData + "/$repoName-data.json"
Set-Location $dirRepo
#
Write-Host "Run Checks"
# Create a parent hashtable for the repository
# Initialize a hashtable with "RepoName"
$repoData = @{
RepoName = "repoSource"
}
# Convert to JSON and save to file
$repoData | ConvertTo-Json -Depth 3 -Compress | Set-Content -Path $dataFileName
# Read the JSON data from file
$jsonData = Get-Content -Raw -Path $jsonChecks | ConvertFrom-Json
$checkTotal =$jsonData.Count
$checkCtr = 0
# Iterate over each item in the JSON array
# Create a parent hashtable for the repository
$repoData = @{
RepoName = "$RepoName"
}
# Convert to JSON and save to file
$repoData | ConvertTo-Json -Depth 3 -Compress | Set-Content -Path $dataFileName
$processedCtr = 0
foreach ($item in $jsonData) {
$checkCtr = $checkCtr + 1
$checkID = $item.CheckID
$checkName = $item.CheckName
$checkDescription = $item.CheckDescription
$checkModule = $item.CheckModule
$checkOutput = $item.CheckOutput
if($checkName -eq "EXIT")
{
break
}
# Perform actions for each item
Write-Host $NewLine
Write-Host "Processing Check ${checkCtr} of ${checkTotal} : ${checkID}: ${checkName}"
Write-Host "--- Description: ${checkDescription}"
Write-Host "--- Module Name ${checkModule}"
#Write-Host
# Call the Invoke-Check function
#Set Up the result hashtable to pass around:
$result = @{
CheckID = $checkID
CheckName = $checkName
CheckDescription = $CheckDescription
CheckModule = $checkModule
Date = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Value = $null
Comment = $Comment
Success = $false
Elapsed = $null
}
$params = @{
RepoSource = $repoSource
RepoPath = $repoPath
DataPath = $dirData
}
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
InvokeCheck -params $params -result $result
$stopwatch.Stop()
$result.Elapsed = $stopwatch.Elapsed.TotalSeconds
# Check if $result is a hashtable
if ($result -is [Hashtable]) {
# Convert hashtable to a JSON string
$result = $result | ConvertTo-Json -Depth 4
$result = $result | ConvertFrom-Json
}
# Display the result
$result
if($null -ne $checkOutput){
#Store as a reference file in data
$checkDataFileName = "$dirData/"+$checkOutput+".json"
$result | ConvertTo-Json -Depth 4 | Set-Content $checkDataFileName
}
else {
#Store in the main file
# Load current data
$currentData = Get-Content -Path $dataFileName | ConvertFrom-Json
# Add new property. Adjust this according to what properties you want to add
$currentData | Add-Member -MemberType NoteProperty -Name $checkID -Value $result
# Now when you call ConvertTo-Json, you won't get escape characters in the output
$currentData | ConvertTo-Json -Depth 4 | Set-Content -Path $dataFileName
}
$processedCtr++
}
Write-Host "That's all folks. Processed $processedCtr item(s)."