<commit_before>﻿$ErrorActionPreference = 'Stop'
$Env:NODE_OPTIONS = "--max-old-space-size=8192"
Set-StrictMode -Version 1
$exitCode = 0

[string[]] $errors = @()

function LogError([string]$message) {
    if ($env:TF_BUILD) {
        Write-Host "##vso[task.logissue type=error]$message"
    }
    Write-Host -f Red "error: $message"
    $script:errors += $message
}

function Invoke-Block([scriptblock]$cmd) {
    $cmd | Out-String | Write-Verbose
    & $cmd

    # Need to check both of these cases for errors as they represent different items
    # - $?: did the powershell script block throw an error
    # - $lastexitcode: did a windows command executed by the script block end in error
    if ((-not $?) -or ($lastexitcode -ne 0)) {
        if ($error -ne $null) {
            Write-Warning $error[0]
        }
        throw "Command failed to execute: $cmd"
    }
}

function Find-Mapping([string]$path) {
    $fileContent = Get-Content $path
    $name = ''
    foreach ($item in $fileContent) {
        if (($item -match '\$\(csharp-sdks-folder\)')) {
            $matchResult = $item -match "\/([^/]+)\/"
            $name = $matches[0].Substring(1, $matches[0].Length - 2)
            if (($name -ne '') -and ($name -notmatch "\$")) {
                break
            }
        }
    }
    return $name
}

try {
    Write-Output "======== Start Code Validation ========"
    
    Write-Host "Check PR associate"
    Write-Host "REPOSITORY_NAME: $Env:REPOSITORY_NAME"
    Write-Host "PULLREQUEST_ID: $Env:PULLREQUEST_ID"
    if (($null -eq $Env:REPOSITORY_NAME) -or ($null -eq $Env:PULLREQUEST_ID) -or ($Env:REPOSITORY_NAME -eq "") -or ($Env:PULLREQUEST_ID -eq "")) {
        Write-Host "There is no PR associate with this run, skip the code check." -ForegroundColor red -BackgroundColor white
        break
    }

    # Get RP Mapping
    Write-Output "Start RP mapping "
    $RPMapping = [ordered]@{ }
    $readmePath = ''
    git clone https://github.com/Azure/azure-rest-api-specs.git ../azure-rest-api-specs
    $folderNames = Get-ChildItem ../azure-rest-api-specs/specification
    $folderNames | ForEach-Object {
        $folderName = ''
        $readmePath = "../azure-rest-api-specs/specification/$($_.Name)/resource-manager/readme.csharp.md"
        if (Test-Path $readmePath) {<commit_msg>Update Track1 code check script (#18107)<commit_after>﻿$ErrorActionPreference = 'Stop'
$Env:NODE_OPTIONS = "--max-old-space-size=8192"
Set-StrictMode -Version 1
$exitCode = 0

[string[]] $errors = @()

function LogError([string]$message) {
    if ($env:TF_BUILD) {
        Write-Host "##vso[task.logissue type=error]$message"
    }
    Write-Host -f Red "error: $message"
    $script:errors += $message
}

function Invoke-Block([scriptblock]$cmd) {
    $cmd | Out-String | Write-Verbose
    & $cmd

    # Need to check both of these cases for errors as they represent different items
    # - $?: did the powershell script block throw an error
    # - $lastexitcode: did a windows command executed by the script block end in error
    if ((-not $?) -or ($lastexitcode -ne 0)) {
        if ($error -ne $null) {
            Write-Warning $error[0]
        }
        throw "Command failed to execute: $cmd"
    }
}

function Find-Mapping([string]$path) {
    $fileContent = Get-Content $path
    $name = ''
    foreach ($item in $fileContent) {
        if (($item -match '\$\(csharp-sdks-folder\)')) {
            $matchResult = $item -match "\/([^/]+)\/"
            $name = $matches[0].Substring(1, $matches[0].Length - 2)
            if (($name -ne '') -and ($name -notmatch "\$")) {
                break
            }
        }
    }
    return $name
}

try {
    Write-Output "======== Start Code Validation ========"
    
    Write-Host "Check PR associate"
    Write-Host "REPOSITORY_NAME: $Env:REPOSITORY_NAME"
    Write-Host "PULLREQUEST_ID: $Env:PULLREQUEST_ID"
    if (($null -eq $Env:REPOSITORY_NAME) -or ($null -eq $Env:PULLREQUEST_ID) -or ($Env:REPOSITORY_NAME -eq "") -or ($Env:PULLREQUEST_ID -eq "") -or ($Env:PULLREQUEST_ID -match 'PullRequestNumber')) {
        Write-Host "There is no PR associate with this run, skip the code check." -ForegroundColor red -BackgroundColor white
        break
    }

    # Get RP Mapping
    Write-Output "Start RP mapping "
    $RPMapping = [ordered]@{ }
    $readmePath = ''
    git clone https://github.com/Azure/azure-rest-api-specs.git ../azure-rest-api-specs
    $folderNames = Get-ChildItem ../azure-rest-api-specs/specification
    $folderNames | ForEach-Object {
        $folderName = ''
        $readmePath = "../azure-rest-api-specs/specification/$($_.Name)/resource-manager/readme.csharp.md"
        if (Test-Path $readmePath) {
{'fraction_non_alphanumeric': 0.15644955300127714, 'fraction_numerical': 0.006385696040868455, 'mean_word_length': 2.6539657853810263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5693486', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1526, 'n_words': 381}