Skip to content

Commit f5cc552

Browse files
🩹 [Patch]: git config output as hashtable[] (#260)
## Description This pull request includes changes to the Update-ConverageReport workflow and updates to the `Get-GitHubGitConfig` function to return a hashtable array instead of a `pscustomobject`. Changes to GitHub Actions workflow: * Renamed `.github/workflows/Set-CoverageReport.yml` to `.github/workflows/Update-CoverageReport.yml` and updated the job names and script references accordingly. [[1]](diffhunk://#diff-e6405cf30762034bf8d27ee149a940b9d5136faad852c26538e8fcee8cb09cf6L1-R1) [[2]](diffhunk://#diff-e6405cf30762034bf8d27ee149a940b9d5136faad852c26538e8fcee8cb09cf6L13-R13) [[3]](diffhunk://#diff-e6405cf30762034bf8d27ee149a940b9d5136faad852c26538e8fcee8cb09cf6L22-R25) Updates to `Get-GitHubGitConfig.ps1` script: * Changed the `OutputType` attribute from `[pscustomobject]` to `[object[]]`. * Improved error handling and logging when retrieving Git configuration, and refactored the script to use an array of hashtables (key value pairs) for configuration storage instead of a `pscustomobject`. This is to support multiple values with the same name, which `git config` supports. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent eca70d0 commit f5cc552

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

.github/workflows/Set-CoverageReport.yml renamed to .github/workflows/Update-CoverageReport.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update coverage report
1+
name: Update-CoverageReport
22

33
on:
44
workflow_dispatch:
@@ -10,7 +10,7 @@ permissions:
1010
contents: write
1111

1212
jobs:
13-
Update-Coverage:
13+
Update-CoverageReport:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout repository
@@ -19,7 +19,7 @@ jobs:
1919
- name: Initialize-PSModule
2020
uses: PSModule/Initialize-PSModule@v1
2121

22-
- name: Update coverage report
22+
- name: Update-CoverageReport
2323
uses: PSModule/GitHub-Script@v1
2424
with:
25-
Script: . '.\scripts\Set-CoverageReport.ps1'
25+
Script: . '.\scripts\Update-CoverageReport.ps1'
File renamed without changes.

src/functions/public/Git/Get-GitHubGitConfig.ps1

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
Gets the global Git configuration.
1313
#>
14-
[OutputType([pscustomobject])]
14+
[OutputType([object[]])]
1515
[CmdletBinding()]
1616
param(
1717
[Parameter()]
@@ -26,7 +26,6 @@
2626

2727
process {
2828
try {
29-
3029
$gitExists = Get-Command -Name 'git' -ErrorAction SilentlyContinue
3130
Write-Debug "GITEXISTS: $gitExists"
3231
if (-not $gitExists) {
@@ -44,23 +43,23 @@
4443
return
4544
}
4645

47-
$config = @{}
48-
git config --$Scope --list | ConvertFrom-StringData | ForEach-Object {
49-
$config += $_
46+
$config = @()
47+
$configList = git config --$Scope --list 2>&1
48+
if ($LASTEXITCODE -ne 0) {
49+
Write-Verbose "Failed to get git configuration for [$Scope]."
50+
$global:LASTEXITCODE = 0
51+
Write-Debug "Resetting LASTEXITCODE: $LASTEXITCODE"
52+
return $config
5053
}
51-
$result = @{}
52-
$config.GetEnumerator() | ForEach-Object {
53-
$name = $_.Key
54-
$value = $_.Value
55-
if ($value -match '(?i)AUTHORIZATION:\s*(?<scheme>[^\s]+)\s+(?<token>.*)') {
56-
$secret = $matches['token']
57-
Add-GitHubMask -Value $secret
58-
}
59-
$result += @{
60-
$name = $value
54+
55+
$configList = $configList | Sort-Object
56+
$configList | ForEach-Object {
57+
$name, $value = $_ -split '=', 2
58+
$config += @{
59+
($name.Trim()) = ($value.Trim())
6160
}
6261
}
63-
[pscustomobject]$result
62+
$config
6463
} catch {
6564
throw $_
6665
}

0 commit comments

Comments
 (0)