Created
March 14, 2024 06:52
-
-
Save mmodrow/c6a564d6a9d157043778442f8def1e96 to your computer and use it in GitHub Desktop.
Transform a single card from a Trello Board Export to denormalized JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param ( | |
[string] | |
$jsonImportPath, | |
[string] | |
$jsonExportPath, | |
[string] | |
$cardName | |
) | |
$trelloData = Get-Content $jsonImportPath -Encoding UTF8 | ConvertFrom-Json | |
$rawCard = $trelloData.cards | Where-Object { $_.name.contains($cardName) } | Select-Object -First 1 | |
if (!$rawCard) { | |
Write-Warning "No matching card found in json dump. Exiting." | |
exit 1 | |
} | |
$comments = @( | |
( | |
$trelloData.actions | | |
Where-Object { $_.data.card.id -eq $rawCard.id -and $_.type -eq "commentCard" } | |
).data.text | |
) | |
$checklists = @(($trelloData.checklists | Where-Object { $_.idCard -eq $rawCard.id }) | ForEach-Object { [PSCustomObject]@{ | |
name = $_.name | |
items = $_.checkItems | ForEach-Object { | |
[PSCustomObject]@{ | |
name = $_.name | |
isComplete = $_.state -eq "complete" | |
} | |
} | |
} | |
}) | |
$card = [PSCustomObject]@{ | |
name = $rawCard.name | |
description = $rawCard.desc | |
attachments = $rawCard.attachments | ForEach-Object { | |
[PSCustomObject]@{ | |
name = $_.name | |
fileName = $_.fileName | |
url = $_.url | |
mimeType = $_.mimeType | |
} | |
} | |
comments = $comments | |
checklists = $checklists | |
} | |
$jsonExport = ConvertTo-Json $card -Depth 10 | |
if (!$jsonExportPath) { | |
return $jsonExport | |
} | |
Set-Content -Value $jsonExport -Path $jsonExportPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment