Save/Save-AppsInRepository.ps1

<#
 .Synopsis
  Save Apps in Repository
 .Description
  The SaveAppsInRepository function is used to save apps in a repository using Azure DevOps and Git. It performs the following actions:
  - Configures Azure DevOps
  - Performs Git actions to create a new branch and add changes
  - Creates a pull request in Azure DevOps
 .Parameter PRName
  The name of the pull request that will be used when creating the pull request and Git commit.
 .Parameter branchName
  The name of the Git branch that will be created for adding changes.
 .Parameter filterName
  The name of the filter that will be used when removing old apps.
 .Parameter pathToPreviousapps
  The path to the directory where previous apps are stored.
 .Parameter pathToArtifacts
  The path to the directory where artifacts are stored for copying.
 .Parameter SystemCollectionUri
  The URI of the Azure DevOps system collection.
 .Parameter SystemTeamProject
  The Azure DevOps system team project.
 .Parameter SystemAccessToken
  The Azure DevOps system access token.
 .Parameter BuildRepositoryName
  The name of the repository for creating the pull request.
 .Parameter folderNames
  An array of folder names.
 .Parameter Version
  Version of the current build.
#>

function Save-AppsInRepository {
    param (
        [Parameter(Mandatory=$true)]
        [string]$PRName,
        [Parameter(Mandatory=$true)]
        [string]$branchName,
        [Parameter(Mandatory=$true)]
        [string]$appNames,
        [Parameter(Mandatory=$true)]
        [string]$pathToPreviousapps,
        [Parameter(Mandatory=$true)]
        [string]$pathToArtifacts = $env:pathToArtifacts,
        [Parameter(Mandatory=$true)]
        $SystemCollectionUri = $env:SystemCollectionUri,
        [Parameter(Mandatory=$true)]
        $SystemTeamProject = $env:SystemTeamProject,
        [Parameter(Mandatory=$true)]
        $SystemAccessToken = $env:SystemAccessToken,
        [Parameter(Mandatory=$true)]
        $BuildRepositoryName = $env:BuildRepositoryName,
        [Parameter(Mandatory=$true)]
        $Version = $env:Version,
        [Parameter(Mandatory=$true)]
        $BuildSourcesDirectory = $env:BuildSourcesDirectory
    )

    Write-Host "PRName: $PRName"
    Write-Host "branchName: $branchName"
    Write-Host "appNames: $appNames"
    Write-Host "pathToPreviousapps: $pathToPreviousapps"
    Write-Host "pathToArtifacts: $pathToArtifacts"
    Write-Host "SystemCollectionUri: $SystemCollectionUri"
    Write-Host "SystemTeamProject: $SystemTeamProject"
    Write-Host "SystemAccessToken: $SystemAccessToken"
    Write-Host "BuildRepositoryName: $BuildRepositoryName"
    Write-Host "version: $Version"
    Write-Host "BuildSourcesDirectory: $BuildSourcesDirectory"

    # try {
    # az devops configure --defaults organization="$SystemCollectionUri" project="$SystemTeamProject" --use-git-aliases true
    # }
    # catch {
    # Write-Error "An error occurred while configuring Azure DevOps: $_"
    # }

    # git fetch origin master
    # git checkout master
    # git checkout -b $branchName

    # # $appNames = "SMART business LLC_SMART"
    # $appPaths = @($appNames.Split(',').Trim() | Foreach-Object {
    # Get-ChildItem -Path (Join-Path $pathToPreviousapps ("*"+$_+"*.app"))| Remove-Item -Force -Recurse
    # })

    # $appPaths = @($appNames.Split(',').Trim() | Foreach-Object {
    # Get-ChildItem -Path (Join-Path $pathToArtifacts ("*"+$_+"*.app")) | Copy-Item -Destination $pathToPreviousapps
    # })

    # try {
    # $directories = Get-ChildItem -Path $BuildSourcesDirectory -Filter app -Recurse -Directory -ErrorAction SilentlyContinue

    # foreach ($directory in $directories) {
    # $file = Join-Path -Path $directory.FullName -ChildPath AppSourceCop.json

    # if (Test-Path -Path $file) {

    # $content = Get-Content -Path $file | ConvertFrom-Json
    # $content.version = "$Version"
    # $content | ConvertTo-Json | Set-Content -Path $file
    # }
    # }
    # }
    # catch {
    # Write-Error "An error occurred while searching for AppSourceCop.json files or updating the version: $_"
    # }

    # try {
    # git add .
    # git commit -m $PRName
    # git push origin $branchName
    # } catch {
    # Write-Output "An error occurred while executing Git commands: $_"
    # }

    # try {
    # $env:AZURE_DEVOPS_EXT_PAT = "$SystemAccessToken"
    # az devops login --organization "$SystemCollectionUri"
    # az repos pr create --repository "$BuildRepositoryName" --source-branch $branchName --target-branch master --title $PRName --description $PRName
    # }
    # catch {
    # Write-Error "An error occurred while creating the pull request: $_"
    # }
}