Skip to content

Commit 1f08baf

Browse files
committed
Excluded README files
1 parent 2375d97 commit 1f08baf

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

tools/ImportExamples.ps1

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,20 @@ function Get-Files {
8282

8383
#Extract command over here
8484
$Command = [System.IO.Path]::GetFileNameWithoutExtension($File)
85-
#Extract URI path
86-
$CommandDetails = Find-MgGraphCommand -Command $Command
87-
if ($CommandDetails) {
88-
foreach ($CommandDetail in $CommandDetails) {
89-
$ApiPath = $CommandDetail.URI
90-
$Method = $CommandDetails.Method
91-
Get-ExternalDocsUrl -GraphProfile $GraphProfile -UriPath $ApiPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method.Trim() -Module $Module
85+
if ($Command -ine "README") {
86+
#Extract URI path
87+
$CommandDetails = Find-MgGraphCommand -Command $Command
88+
if ($CommandDetails) {
89+
foreach ($CommandDetail in $CommandDetails) {
90+
$ApiPath = $CommandDetail.URI
91+
$Method = $CommandDetails.Method
92+
Get-ExternalDocsUrl -GraphProfile $GraphProfile -UriPath $ApiPath -Command $Command -OpenApiContent $OpenApiContent -GraphProfilePath $GraphProfilePath -Method $Method.Trim() -Module $Module
93+
}
9294
}
93-
}
94-
else {
95-
#Clear any content in that file as long as its not a readme file
96-
if ($Command -ine "README") {
95+
else {
96+
#Clear any content in that file as long as its not a readme file
9797
Clear-Content $File -Force
98+
9899
}
99100
}
100101
}
@@ -182,10 +183,12 @@ function Get-ExternalDocsUrl {
182183
}
183184
if (-not([string]::IsNullOrEmpty($ExternalDocUrl))) {
184185
Start-WebScrapping -GraphProfile $GraphProfile -ExternalDocUrl $ExternalDocUrl -Command $Command -GraphProfilePath $GraphProfilePath -UriPath $UriPath -Module $Module
185-
}else{
186+
}
187+
else {
186188
# This step will still correct the examples if the external docs url is not found
187189
$ExampleFile = "$GraphProfilePath/$Command.md"
188190
Retain-ExistingCorrectExamples -Content (Get-Content $ExampleFile) -File $ExampleFile -CommandPattern $Command
191+
189192
}
190193
}
191194

@@ -216,17 +219,17 @@ function Start-WebScrapping {
216219
[string] $Module = "Users",
217220
[string] $GraphProfilePath = (Join-Path $PSScriptRoot "..\src\Users\Users\examples\v1.0")
218221
)
219-
$ExternalDocUrlPaths = $ExternalDocUrl.Split("://")[1].Split("/")
220-
$LastExternalDocUrlPathSegmentWithQueryParam = $ExternalDocUrlPaths[$ExternalDocUrlPaths.Length - 1]
221-
$LastExternalDocUrlPathSegmentWithoutQueryParam = $LastExternalDocUrlPathSegmentWithQueryParam.Split("?")[0]
222-
223-
$GraphDocsUrl = "https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/$GraphProfile/api/$LastExternalDocUrlPathSegmentWithoutQueryParam.md"
224-
$UrlPaths = $GraphDocsUrl.Split("://")[1].Split("/")
225-
$LastPathSegment = $UrlPaths[$UrlPaths.Length - 1]
226-
$HeaderList = New-Object -TypeName 'System.Collections.ArrayList';
227-
$ExampleLinks = New-Object -TypeName 'System.Collections.ArrayList';
228-
$Snippets = New-Object -TypeName 'System.Collections.ArrayList';
229-
try{
222+
$ExternalDocUrlPaths = $ExternalDocUrl.Split("://")[1].Split("/")
223+
$LastExternalDocUrlPathSegmentWithQueryParam = $ExternalDocUrlPaths[$ExternalDocUrlPaths.Length - 1]
224+
$LastExternalDocUrlPathSegmentWithoutQueryParam = $LastExternalDocUrlPathSegmentWithQueryParam.Split("?")[0]
225+
226+
$GraphDocsUrl = "https://raw.githubusercontent.com/microsoftgraph/microsoft-graph-docs-contrib/main/api-reference/$GraphProfile/api/$LastExternalDocUrlPathSegmentWithoutQueryParam.md"
227+
$UrlPaths = $GraphDocsUrl.Split("://")[1].Split("/")
228+
$LastPathSegment = $UrlPaths[$UrlPaths.Length - 1]
229+
$HeaderList = New-Object -TypeName 'System.Collections.ArrayList';
230+
$ExampleLinks = New-Object -TypeName 'System.Collections.ArrayList';
231+
$Snippets = New-Object -TypeName 'System.Collections.ArrayList';
232+
try {
230233
($readStream, $HttpWebResponse) = FetchStream -GraphDocsUrl $GraphDocsUrl
231234

232235
while (-not $readStream.EndOfStream) {
@@ -275,7 +278,8 @@ function Start-WebScrapping {
275278
$Description = "This example shows how to use the $DescriptionCommand Cmdlet."
276279

277280
Update-ExampleFile -GraphProfile $GraphProfile -HeaderList $HeaderList -ExampleList $Snippets -ExampleFile $ExampleFile -Description $Description -Command $Command -ExternalDocUrl $url -UriPath $UriPath -Module $Module
278-
}catch {
281+
}
282+
catch {
279283
Write-Host "`nError Message: " $_.Exception.Message
280284
Write-Host "`nError in Line: " $_.InvocationInfo.Line
281285
Write-Host "`nError in Line Number: "$_.InvocationInfo.ScriptLineNumber

0 commit comments

Comments
 (0)