Skip to content

Commit d794325

Browse files
authored
Merge pull request #281 from CommunityToolkit/feature/scripts/get-changed-components
Added Get-Changed-Components.ps1
2 parents f12b7d9 + 36b7671 commit d794325

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Get-Changed-Components.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<#
2+
.PARAMETER FromSha
3+
The SHA of the commit to start the diff from. This is typically the SHA of the main branch.
4+
The default value is 'origin/main'.
5+
6+
.PARAMETER ToSha
7+
The SHA of the commit to end the diff at. This is typically the SHA of the current commit.
8+
If not provided, the script will use the current commit SHA.
9+
10+
.EXAMPLE
11+
Get-Changed-Components.ps1 -FromSha 'origin/main' -ToSha $(git rev-parse HEAD)
12+
13+
Get-Changed-Components.ps1 -t $(git rev-parse HEAD)
14+
15+
Gets the components that have been changed in a specific patch range, defined by -FromSha and -ToSha parameters.
16+
17+
.NOTES
18+
Author: Arlo Godfrey
19+
Date: 2/19/2024
20+
#>
21+
Param (
22+
[Alias("f")]
23+
[string]$FromSha = 'origin/main',
24+
25+
[Alias("t")]
26+
[string]$ToSha
27+
)
28+
29+
if (-not $ToSha) {
30+
$ToSha = $(git rev-parse HEAD)
31+
}
32+
33+
git fetch origin main
34+
35+
$changedComponentFiles = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) -- components/"
36+
$otherChanges = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) | Select-String -NotMatch '^components/'"
37+
38+
if (-not $otherChanges) {
39+
$names = $changedComponentFiles | ForEach-Object { ($_ -replace '^components/', '') -replace '/.*$', '' }
40+
$uniqueNames = $names | Sort-Object -Unique
41+
$quotedNames = $uniqueNames | ForEach-Object { "'$_'" }
42+
$changedComponentsList = $quotedNames -join ','
43+
return $changedComponentsList
44+
}
45+
else {
46+
return 'all';
47+
}

0 commit comments

Comments
 (0)