Skip to content

Commit 93a23c7

Browse files
add flag for exporting to csv
1 parent 536effa commit 93a23c7

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

src/GitlabCli/Formats.ps1xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@
264264
<TableHeaders>
265265
<TableColumnHeader/>
266266
<TableColumnHeader/>
267-
<TableColumnHeader/>
267+
<TableColumnHeader>
268+
<Label>Scopes</Label>
269+
</TableColumnHeader>
268270
<TableColumnHeader>
269271
<Label>LastUsedAt</Label>
270272
</TableColumnHeader>
@@ -283,7 +285,7 @@
283285
<PropertyName>Name</PropertyName>
284286
</TableColumnItem>
285287
<TableColumnItem>
286-
<PropertyName>Scope</PropertyName>
288+
<PropertyName>ScopesDisplay</PropertyName>
287289
</TableColumnItem>
288290
<TableColumnItem>
289291
<PropertyName>LastUsedAtSortable</PropertyName>
@@ -320,7 +322,7 @@
320322
<PropertyName>Name</PropertyName>
321323
</TableColumnItem>
322324
<TableColumnItem>
323-
<PropertyName>Scope</PropertyName>
325+
<PropertyName>ScopesDisplay</PropertyName>
324326
</TableColumnItem>
325327
<TableColumnItem>
326328
<PropertyName>ExpiresAt</PropertyName>

src/GitlabCli/PersonalAccessTokens.psm1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function Get-GitlabPersonalAccessToken {
6060
[switch]
6161
$FetchUsers,
6262

63+
[Parameter()]
64+
[switch]
65+
$ForExport,
66+
6367
[Parameter()]
6468
[uint]
6569
$MaxPages,
@@ -137,6 +141,24 @@ function Get-GitlabPersonalAccessToken {
137141
}
138142
}
139143

144+
if ($ForExport) {
145+
return $Results |
146+
ForEach-Object {
147+
[pscustomobject]@{
148+
Id = $_.Id
149+
Name = $_.Name
150+
Description = $_.Description
151+
User = $_.Username ?? $_.UserId
152+
Scopes = $_.ScopesDisplay
153+
Active = $_.Active
154+
CreatedAt = $_.CreatedAt.ToString('yyyy-MM-dd')
155+
LastUsedAt = $_.LastUsedAt ? $_.LastUsedAt.ToString('yyyy-MM-dd') : $null
156+
ExpiresAt = $_.ExpiresAt ? $_.ExpiresAt.ToString('yyyy-MM-dd') : $null
157+
}
158+
} |
159+
Sort-Object -Descending LastUsedAt
160+
}
161+
140162
$Results
141163
}
142164

src/GitlabCli/Types.ps1xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@
121121
<GetScriptBlock>$this.LastUsedAt.ToString('yyyy-MM-dd HH:mm')</GetScriptBlock>
122122
</ScriptProperty>
123123
<ScriptProperty>
124-
<Name>Scope</Name>
125-
<GetScriptBlock>$this.Scopes</GetScriptBlock>
124+
<Name>ScopesDisplay</Name>
125+
<GetScriptBlock>$this.Scopes -join ', '</GetScriptBlock>
126126
</ScriptProperty>
127127
<ScriptProperty>
128128
<Name>Username</Name>
@@ -134,8 +134,8 @@
134134
<Name>Gitlab.NewPersonalAccessToken</Name>
135135
<Members>
136136
<ScriptProperty>
137-
<Name>Scope</Name>
138-
<GetScriptBlock>$this.Scopes</GetScriptBlock>
137+
<Name>ScopesDisplay</Name>
138+
<GetScriptBlock>$this.Scopes -join ', '</GetScriptBlock>
139139
</ScriptProperty>
140140
</Members>
141141
</Type>

0 commit comments

Comments
 (0)