Skip to content

Commit a1e9e58

Browse files
author
James Brundage
committed
Updating action (improving email determination) (#152)
1 parent ed1b745 commit a1e9e58

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

Github/Actions/PipeScriptAction.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,21 @@ $processScriptOutput = { process {
100100

101101

102102
if (-not $UserName) { $UserName = $env:GITHUB_ACTOR }
103-
if (-not $UserEmail) { $UserEmail = "$UserName@github.com" }
103+
if (-not $UserEmail) {
104+
$GitHubUserEmail =
105+
if ($env:GITHUB_TOKEN) {
106+
Invoke-RestMethod -uri "https://api.github.com/user/emails" -Headers @{
107+
Authorization = "token $env:GITHUB_TOKEN"
108+
} |
109+
Select-Object -First 1 -ExpandProperty email
110+
} else {''}
111+
$UserEmail =
112+
if ($GitHubUserEmail) {
113+
$GitHubUserEmail
114+
} else {
115+
"$UserName@github.com"
116+
}
117+
}
104118
git config --global user.email $UserEmail
105119
git config --global user.name $UserName
106120

action.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ runs:
4747
id: PipeScriptAction
4848
shell: pwsh
4949
env:
50-
SkipBuild: ${{inputs.SkipBuild}}
50+
PipeScript: ${{inputs.PipeScript}}
5151
UserName: ${{inputs.UserName}}
52-
CommitMessage: ${{inputs.CommitMessage}}
5352
UserEmail: ${{inputs.UserEmail}}
54-
PipeScript: ${{inputs.PipeScript}}
53+
CommitMessage: ${{inputs.CommitMessage}}
54+
SkipBuild: ${{inputs.SkipBuild}}
5555
run: |
5656
$Parameters = @{}
5757
$Parameters.PipeScript = ${env:PipeScript}
@@ -168,7 +168,21 @@ runs:
168168
169169
170170
if (-not $UserName) { $UserName = $env:GITHUB_ACTOR }
171-
if (-not $UserEmail) { $UserEmail = "[email protected]" }
171+
if (-not $UserEmail) {
172+
$GitHubUserEmail =
173+
if ($env:GITHUB_TOKEN) {
174+
Invoke-RestMethod -uri "https://api.github.com/user/emails" -Headers @{
175+
Authorization = "token $env:GITHUB_TOKEN"
176+
} |
177+
Select-Object -First 1 -ExpandProperty email
178+
} else {''}
179+
$UserEmail =
180+
if ($GitHubUserEmail) {
181+
$GitHubUserEmail
182+
} else {
183+
184+
}
185+
}
172186
git config --global user.email $UserEmail
173187
git config --global user.name $UserName
174188

0 commit comments

Comments
 (0)