Skip to content

Commit 8290286

Browse files
Merge pull request #134 from StartAutomating/ugit-remotes
ugit 0.3.7
2 parents 87ce2f7 + 3e7ac3e commit 8290286

22 files changed

+788
-130
lines changed

.github/workflows/TestAndPublish.yml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -383,32 +383,34 @@ jobs:
383383
384384
if ($releaseExists) {
385385
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
386-
return
386+
$releasedIt = $releaseExists
387+
} else {
388+
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
389+
[Ordered]@{
390+
owner = '${{github.owner}}'
391+
repo = '${{github.repository}}'
392+
tag_name = $targetVersion
393+
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
394+
body =
395+
if ($env:RELEASENOTES) {
396+
$env:RELEASENOTES
397+
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
398+
$imported.PrivateData.PSData.ReleaseNotes
399+
} else {
400+
"$($imported.Name) $targetVersion"
401+
}
402+
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
403+
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
404+
} | ConvertTo-Json
405+
) -Headers @{
406+
"Accept" = "application/vnd.github.v3+json"
407+
"Content-type" = "application/json"
408+
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
409+
}
387410
}
388411
389412
390-
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
391-
[Ordered]@{
392-
owner = '${{github.owner}}'
393-
repo = '${{github.repository}}'
394-
tag_name = $targetVersion
395-
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
396-
body =
397-
if ($env:RELEASENOTES) {
398-
$env:RELEASENOTES
399-
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
400-
$imported.PrivateData.PSData.ReleaseNotes
401-
} else {
402-
"$($imported.Name) $targetVersion"
403-
}
404-
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
405-
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
406-
} | ConvertTo-Json
407-
) -Headers @{
408-
"Accept" = "application/vnd.github.v3+json"
409-
"Content-type" = "application/json"
410-
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
411-
}
413+
412414
413415
414416
if (-not $releasedIt) {
@@ -443,10 +445,9 @@ jobs:
443445
$fileBytes = [IO.File]::ReadAllBytes($file.FullName)
444446
$releasedFiles[$file.Name] =
445447
Invoke-RestMethod -Uri "${releaseUploadUrl}?name=$($file.Name)" -Headers @{
446-
"Accept" = "application/vnd.github+json"
447-
"ContentType" = "application/octet-stream"
448+
"Accept" = "application/vnd.github+json"
448449
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
449-
} -Body $fileBytes
450+
} -Body $fileBytes -ContentType Application/octet-stream
450451
$releasedFiles[$file.Name]
451452
}
452453
}
@@ -584,6 +585,7 @@ jobs:
584585
uses: StartAutomating/Piecemeal@main
585586
- name: UseEZOut
586587
uses: StartAutomating/EZOut@master
587-
- name: UseHelpOut
588+
- name: Run HelpOut
588589
uses: StartAutomating/HelpOut@master
590+
id: HelpOut
589591

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 0.3.7:
2+
3+
* git remote
4+
* Now supporting git remote! (Fixes #129)
5+
6+
~~~PowerShell
7+
git remote | git remote show
8+
~~~
9+
10+
Also, some improvements to the GitHub Action:
11+
12+
* Icon Update (Fixes #132)
13+
* No longer using set-output (Fixes #131)
14+
* Adding -InstallModule to Action (Fixes #132)
15+
16+
---
17+
118
## 0.3.6:
219

320
* git log

Extensions/Git.Grep.UGit.Extension.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
<#
2+
.SYNOPSIS
3+
git grep extension
4+
.DESCRIPTION
5+
Outputs matches from git grep.
6+
7+
When possible, the regular expression will be converted into PowerSEhll so that the .Match populates accurately.
8+
.EXAMPLE
9+
git grep '-i' example # look for all examples in the repository
10+
.LINK
11+
Out-Git
12+
#>
113
[Management.Automation.Cmdlet("Out","Git")] # It extends Out-Git
214
[ValidatePattern("^git grep",Options='IgnoreCase')] # when the pattern is "git grep"
315
[OutputType('Git.Grep.Match')]
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<#
2+
.Synopsis
3+
Git Remotes Extension
4+
.Description
5+
Outputs git remotes as objects.
6+
.EXAMPLE
7+
git remote
8+
.EXAMPLE
9+
git remote | git remote get-url
10+
.EXAMPLE
11+
git remote | git remote show
12+
#>
13+
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
14+
[ValidatePattern("^git remote")] # that is run when the command starts with git remote.
15+
[OutputType('git.remote.name','git.remote.uri', 'git.remote')]
16+
param( )
17+
18+
begin {
19+
$remoteLines = @()
20+
}
21+
22+
process {
23+
$remoteLines += $_
24+
}
25+
26+
end {
27+
28+
if ($gitArgument -match '--(?>n|dry-run)' -or # If the arguments matched --n or --dry-run or
29+
$remoteLines[0] -like 'usage:*' # the output lines started with usage:
30+
) {
31+
return $remoteLines # return the output directly.
32+
}
33+
34+
# git remote can do a few different things
35+
switch -Regex ($gitCommand) {
36+
'git remote\s{0,}$' {
37+
# With no other parameters, it returns the remote name.
38+
return [PSCustomObject][Ordered]@{
39+
PSTypename = 'git.remote.name'
40+
RemoteName = $remoteLines -join ' ' -replace '\s'
41+
GitRoot = $gitRoot
42+
}
43+
}
44+
'git remote get-url (?<RemoteName>\S+)\s{0,}$' {
45+
# With get-url, it returns the URL
46+
return [PSCustomObject][Ordered]@{
47+
PSTypename = 'git.remote.url'
48+
RemoteName = $matches.RemoteName
49+
RemoteUrl = $remoteLines -join ' ' -replace '\s'
50+
GitOutputLines = $remoteLines
51+
GitRoot = $gitRoot
52+
}
53+
}
54+
'git remote show (?<RemoteName>\S+)\s{0,}$' {
55+
# With show, it returns _a lot_ of stuff. We want to track:
56+
$remoteName = $matches.RemoteName
57+
# * Each named URL
58+
$gitRemoteUrls = [ordered]@{
59+
PSTypeName = 'git.remote.urls'
60+
}
61+
# * All remote branches
62+
$remoteBranches = @()
63+
# * All local branches
64+
$localBranches = @()
65+
# * All tracked upstream branches
66+
$trackedUpstreams = @()
67+
# * The Head branch
68+
$headBranch = ''
69+
$inSection = ''
70+
# We go thru each line returned by git remote show
71+
foreach ($line in $remoteLines) {
72+
if ($line -match '^\*\sremote\s(?<RemoteName>\S+)') {
73+
# We can ignore the first line (we already know the remote name)
74+
}
75+
elseif ($line -match 'URL:') {
76+
# Lines containing URL: can be split into a purpose and URL.
77+
$purpose, $remoteUrl = $line -split 'URL:'
78+
$gitRemoteUrls[$purpose -replace '\s'] = $remoteUrl -replace '\s'
79+
}
80+
elseif ($line -match '^\s{1,}HEAD branch:') {
81+
# The head branch line is helpfully marked.
82+
$headBranch = $line -replace '^\s{1,}HEAD branch:' -replace '\s'
83+
}
84+
elseif ($line -match '^\s{2}Remote Branches:') {
85+
# as are the names of each section
86+
$inSection = 'Remote Branches'
87+
}
88+
elseif ($line -match "^\s{2}Local branches configured for 'git pull':") {
89+
$inSection = 'LocalBranches'
90+
}
91+
elseif ($line -match "^\s{2}Local refs configured for 'git push':") {
92+
$inSection = 'LocalRefs'
93+
}
94+
elseif ($inSection -and $line -match '^\s{4}') {
95+
# Within each section, we'll want capture a branch name and status
96+
if ($inSection -eq 'Remote Branches') {
97+
$remoteBranch, $status, $null = $line -split '\s{1,}' -ne ''
98+
$remoteBranches += [PSCustomObject][Ordered]@{
99+
PSTypename = 'git.remote.branch'
100+
BranchName = $remoteBranch
101+
Status = $status
102+
}
103+
}
104+
elseif ($inSection -eq 'Local Branches') {
105+
$localBranch, $status = $line -split '\s{1,}' -ne ''
106+
$status = $status -join ' '
107+
$localBranches += [PSCustomObject][Ordered]@{
108+
PSTypename = 'git.remote.local.branch'
109+
BranchName = $localBranch
110+
Status = $status
111+
}
112+
}
113+
elseif ($inSection -eq 'LocalRefs') {
114+
$localBranch, $status = $line -split '\s{1,}' -ne ''
115+
$status = $status -join ' '
116+
$trackedUpstreams += [PSCustomObject][Ordered]@{
117+
PSTypename = 'git.remote.tracked.upstream'
118+
BranchName = $localBranch
119+
Status = $status
120+
}
121+
}
122+
}
123+
}
124+
125+
# Now we can return a custom object with all of the data from git.remote.show, and let the formatter do the work.
126+
return [PSCustomObject][Ordered]@{
127+
PSTypename = 'git.remote.show'
128+
RemoteName = $remoteName
129+
HeadBranch = $headBranch
130+
RemoteURLs = [PSCustomObject]$gitRemoteUrls
131+
RemoteBranches = $remoteBranches
132+
LocalBranches = $localBranches
133+
TrackedUpstreams = $trackedUpstreams
134+
GitOutputLines = $remoteLines
135+
GitRoot = $gitRoot
136+
}
137+
}
138+
139+
default {
140+
# If it wasn't any scenario we know how to parse, return the lines as-is.
141+
return $remoteLines
142+
}
143+
}
144+
}
145+

Formatting/Git.Remote.format.ps1

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Formatting definitions for various outputs from Git.Remote
2+
3+
Write-FormatView -TypeName Git.Remote.Name -Property RemoteName -GroupByProperty GitRoot
4+
5+
Write-FormatView -TypeName Git.Remote.Url -Property RemoteName, RemoteUrl -GroupByProperty GitRoot
6+
7+
Write-FormatView -TypeName Git.Remote.Show -Action {
8+
Write-FormatViewExpression -Text '* remote '
9+
Write-FormatViewExpression -ForegroundColor Verbose -Property RemoteName
10+
Write-FormatViewExpression -Newline
11+
Write-FormatViewExpression -Text ' HEAD branch: '
12+
Write-FormatViewExpression -ForegroundColor Verbose -Property HeadBranch
13+
Write-FormatViewExpression -Newline
14+
Write-FormatViewExpression -Text ' URLS: '
15+
Write-FormatViewExpression -Newline
16+
Write-FormatViewExpression -ScriptBlock {
17+
(' ' * 4) + @(
18+
$_.RemoteUrls | Out-String -Width ($host.UI.RawUI.BufferSize.Width - 4)
19+
) -split [Environment]::NewLine -join (
20+
[Environment]::NewLine + (' ' * 4)
21+
)
22+
}
23+
Write-FormatViewExpression -Newline
24+
Write-FormatViewExpression -Text ' Remote Branches:'
25+
Write-FormatViewExpression -Newline
26+
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property RemoteBranches
27+
Write-FormatViewExpression -Newline
28+
Write-FormatViewExpression -Text ' Local Branches:'
29+
Write-FormatViewExpression -Newline
30+
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property LocalBranches
31+
Write-FormatViewExpression -Text ' Tracked Upstreams:'
32+
Write-FormatViewExpression -Newline
33+
Write-FormatViewExpression -ControlName GitRemoteBranchList -Property TrackedUpstreams
34+
Write-FormatViewExpression -Newline
35+
}
36+
37+
Write-FormatView -TypeName n/a -Name GitRemoteBranchList -AsControl -Action {
38+
(' ' * 4) + @($_ |
39+
Format-Table -Property BranchName, Status |
40+
Out-String -Width ($host.UI.RawUI.BufferSize.Width - 4)
41+
) -split [Environment]::NewLine -join (
42+
[Environment]::NewLine + (' ' * 4)
43+
)
44+
}
45+

GitHub/Actions/UGitAction.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ $UGitScript,
2727
[switch]
2828
$SkipUGitPS1,
2929

30+
# A list of modules to be installed from the PowerShell gallery before scripts run.
31+
[string[]]
32+
$InstallModule,
33+
3034
# If provided, will commit any remaining changes made to the workspace with this commit message.
3135
[string]
3236
$CommitMessage,
@@ -55,6 +59,24 @@ if ($env:GITHUB_ACTION_PATH) {
5559
throw "Action Path not found"
5660
}
5761

62+
#region -InstallModule
63+
if ($InstallModule) {
64+
"::group::Installing Modules" | Out-Host
65+
foreach ($moduleToInstall in $InstallModule) {
66+
$moduleInWorkspace = Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -File |
67+
Where-Object Name -eq "$($moduleToInstall).psd1" |
68+
Where-Object {
69+
$(Get-Content $_.FullName -Raw) -match 'ModuleVersion'
70+
}
71+
if (-not $moduleInWorkspace) {
72+
Install-Module $moduleToInstall -Scope CurrentUser -Force
73+
Import-Module $moduleToInstall -Force -PassThru | Out-Host
74+
}
75+
}
76+
"::endgroup::" | Out-Host
77+
}
78+
#endregion -InstallModule
79+
5880
"::notice title=ModuleLoaded::ugit Loaded from Path - $($ugitModulePath)" | Out-Host
5981

6082
$anyFilesChanged = $false
@@ -96,7 +118,7 @@ if ($ugitScript) {
96118
Out-Host
97119
}
98120
$ugitScriptTook = [Datetime]::Now - $ugitScriptStart
99-
"::set-output name=ugitScriptRuntime::$($ugitScriptTook.TotalMilliseconds)" | Out-Host
121+
"::notice title=ugitScriptRuntime::$($ugitScriptTook.TotalMilliseconds)" | Out-Host
100122

101123
$ugitPS1Start = [DateTime]::Now
102124
$ugitPS1List = @()
@@ -115,9 +137,9 @@ if (-not $SkipugitPS1) {
115137
}
116138
$ugitPS1EndStart = [DateTime]::Now
117139
$ugitPS1Took = [Datetime]::Now - $ugitPS1Start
118-
"::set-output name=ugitPS1Count::$($ugitPS1List.Length)" | Out-Host
119-
"::set-output name=ugitPS1Files::$($ugitPS1List -join ';')" | Out-Host
120-
"::set-output name=ugitPS1Runtime::$($ugitPS1Took.TotalMilliseconds)" | Out-Host
140+
"::notice title=ugitPS1Count::$($ugitPS1List.Length)" | Out-Host
141+
"::notice title=ugitPS1Files::$($ugitPS1List -join ';')" | Out-Host
142+
"::notice title=ugitPS1Runtime::$($ugitPS1Took.TotalMilliseconds)" | Out-Host
121143
if ($CommitMessage -or $anyFilesChanged) {
122144
if ($CommitMessage) {
123145
dir $env:GITHUB_WORKSPACE -Recurse |

0 commit comments

Comments
 (0)