Closed Liturgist closed 1 year ago
I'm unable to repro your issue, and you failed to include any verbose logs (either by copy/pasting the relevant section of your log file, or by re-running the command with -Verbose
) that would provide pointers into the issue that you're having.
For reference, this command works fine:
Get-GitHubRepositoryLanguage -OwnerName microsoft -RepositoryName powershellforgithub
returns:
PowerShell
----------
1446793
@HowardWolosky, thank you for looking at the question. It requires querying multiple repos. Here is more information.
PS C:\> Get-GitHubRepositoryLanguage -OwnerName microsoft -RepositoryName PowerShellForGitHub
PowerShell
----------
1446793
PS C:\> Get-GitHubRepositoryLanguage -OwnerName powershell -RepositoryName powershell
C# : 30816340
PowerShell : 5130858
Roff : 216538
Shell : 57893
Rich Text Format : 40664
HTML : 18166
XSLT : 14394
JavaScript : 8738
Dockerfile : 6482
Batchfile : 24
However, when the two commands are run sequentially or in a script, the output contains only language 'PowerShell' information.
PS C:\> Get-GitHubRepositoryLanguage -OwnerName microsoft -RepositoryName PowerShellForGitHub -Verbose
>> Get-GitHubRepositoryLanguage -OwnerName powershell -RepositoryName powershell -Verbose
>>
VERBOSE: [0.16.1] Executing: Get-GitHubRepositoryLanguage -OwnerName "microsoft" -RepositoryName "PowerShellForGitHub" -Verbose:$true
VERBOSE: Getting languages for PowerShellForGitHub
VERBOSE: Accessing [Get] https://api.github.com/repos/microsoft/PowerShellForGitHub/languages [Timeout = 0)]
VERBOSE: HTTP/1.1 GET with 0-byte payload
VERBOSE: received 22-byte response of content type application/json
VERBOSE: Telemetry has been disabled via configuration. Skipping reporting event [Get-GitHubRepositoryLanguage].
VERBOSE: [0.16.1] Executing: Get-GitHubRepositoryLanguage -OwnerName "powershell" -RepositoryName "powershell" -Verbose:$true
VERBOSE: Getting languages for powershell
VERBOSE: Accessing [Get] https://api.github.com/repos/powershell/powershell/languages [Timeout = 0)]
VERBOSE: HTTP/1.1 GET with 0-byte payload
VERBOSE: received 166-byte response of content type application/json
VERBOSE: Telemetry has been disabled via configuration. Skipping reporting event [Get-GitHubRepositoryLanguage].
PowerShell
----------
1446793
5130858
PS C:\> cat $Env:USERPROFILE/bin/atest.ps1
Get-GitHubRepositoryLanguage -OwnerName microsoft -RepositoryName PowerShellForGitHub -Verbose
Get-GitHubRepositoryLanguage -OwnerName powershell -RepositoryName powershell -Verbose
PS C:\> & $Env:USERPROFILE/bin/atest.ps1
VERBOSE: [0.16.1] Executing: Get-GitHubRepositoryLanguage -OwnerName "microsoft" -RepositoryName "PowerShellForGitHub" -Verbose:$true
VERBOSE: Getting languages for PowerShellForGitHub
VERBOSE: Accessing [Get] https://api.github.com/repos/microsoft/PowerShellForGitHub/languages [Timeout = 0)]
VERBOSE: HTTP/1.1 GET with 0-byte payload
VERBOSE: received 22-byte response of content type application/json
VERBOSE: Telemetry has been disabled via configuration. Skipping reporting event [Get-GitHubRepositoryLanguage].
VERBOSE: [0.16.1] Executing: Get-GitHubRepositoryLanguage -OwnerName "powershell" -RepositoryName "powershell" -Verbose:$true
VERBOSE: Getting languages for powershell
VERBOSE: Accessing [Get] https://api.github.com/repos/powershell/powershell/languages [Timeout = 0)]
VERBOSE: HTTP/1.1 GET with 0-byte payload
VERBOSE: received 166-byte response of content type application/json
VERBOSE: Telemetry has been disabled via configuration. Skipping reporting event [Get-GitHubRepositoryLanguage].
PowerShell
----------
1446793
5130858
PS C:\> Get-GitHubRepositoryLanguage -OwnerName microsoft -RepositoryName PowerShellForGitHub | Get-Member
TypeName: GitHub.RepositoryLanguage
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
PowerShell NoteProperty long PowerShell=1446793
PS C:\> Get-GitHubRepositoryLanguage -OwnerName powershell -RepositoryName powershell | Get-Member
TypeName: GitHub.RepositoryLanguage
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Batchfile NoteProperty long Batchfile=24
C# NoteProperty long C#=30816340
Dockerfile NoteProperty long Dockerfile=6482
HTML NoteProperty long HTML=18166
JavaScript NoteProperty long JavaScript=8738
PowerShell NoteProperty long PowerShell=5130858
Rich Text Format NoteProperty long Rich Text Format=40664
Roff NoteProperty long Roff=216538
Shell NoteProperty long Shell=57893
XSLT NoteProperty long XSLT=14394
This is simply the nature of PowerShell ... nothing specific to this module.
This will produce the same result.
$a = Get-GitHubRepositoryLanguage -OwnerName microsoft -RepositoryName PowerShellForGitHub -Verbose
$b = Get-GitHubRepositoryLanguage -OwnerName powershell -RepositoryName powershell -Verbose
$a
>> $b
Or more simply:
$a = [PSCustomObject]@{'a' = 1}
$b = [PSCustomObject]@{'a' = 1; 'b' = 2; 'c' = 3 }
$a
>> $b
What are you trying to accomplish with that command? It's pretty ambiguous at the moment.
@HowardWolosky, I would like to produce a list of repos and the languages used. Something like:
RepoName Language Loc
-------- -------- ---
repo1 PowerShell 0858
repo2 C# 30816340
repo2 PowerShell 5130858
repo2 Roff 216538
repo2 Shell 57893
repo3 Rich Text Format 40664
repo3 HTML 18166
ConvertFrom-Json
converts a json string into a [PSCustomObject]
, and that's what PowerShellForGitHub is built on top of (as is almost any PowerShell module that interacts with a REST Api). The objects that come out of that Get-GitHubRepositoryLanguage
are not guaranteed to have the same properties however (both PowerShell and PowerShellForGitHub have a PowerShell
property, but PowerShell has a number of other ones as well). PowerShell doesn't know how to merge disparate [PSCustomObject]
s into a single table.
To achieve that list, you'll need to do post-processing of the data. Something like this:
$repos = @(
@{'owner' = 'PowerShell'; 'name' = 'PowerShell' },
@{'owner' = 'microsoft'; 'name' = 'PowerShellForGitHub' }
)
$repoLanguages = @()
foreach ($repo in $repos)
{
$result = Get-GitHubRepositoryLanguage -OwnerName $repo.owner -RepositoryName $repo.name
foreach ($lang in $result.PSObject.Properties.Name)
{
$repoLanguages += [PSCustomObject]@{
'owner' = $repo.owner
'repo' = $repo.name
'language' = $lang
'loc' = $result.$lang
}
}
}
# this will spit out a table that matches what you're looking for:
$repoLanguages
<#
owner repo language loc
----- ---- -------- ---
PowerShell PowerShell C# 30816340
PowerShell PowerShell PowerShell 5140070
PowerShell PowerShell Roff 216538
PowerShell PowerShell Shell 57893
PowerShell PowerShell Rich Text Format 40664
PowerShell PowerShell HTML 18166
PowerShell PowerShell XSLT 14394
PowerShell PowerShell JavaScript 8738
PowerShell PowerShell Dockerfile 6482
PowerShell PowerShell Batchfile 24
microsoft PowerShellForGitHub PowerShell 1446793
#>
A description of your problem or question
Cannot get languages from multiple repos.
Steps to reproduce the issue
Use multiple Get-GitHubRepositoryLangage statements.
Verbose logs showing the problem
N/A
Suggested solution to the issue
N/A
Operating System
OsName : Microsoft Windows 10 Enterprise OsOperatingSystemSKU : EnterpriseEdition OsArchitecture : 64-bit WindowsVersion : 2009 WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406 OsLanguage : en-US OsMuiLanguages : {en-US}
PowerShell Version
Name Value
PSVersion 7.3.2 PSEdition Core GitCommitId 7.3.2 OS Microsoft Windows 10.0.19044 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0
Module Version
Running: 0.16.1 Installed: 0.16.1