GitHub reaching to web servies on the web gives scripts data power
Overview
I wanted to make calls to GitHub’s API from a PowerShell script.
While looking for examples, I found several libraries that already do it:
-
PsGitHub by Trevor Sullivan
-
Posh-GitHub by Ethan J. Brown installed by Chocolately.
-
GitHubConnect by David O’Brien
-
PowerShellForGitHub by Microsoft’s PowerShell team.
Do you know of others? Please let me know.
Use PowerShellForGitHub module
-
PowerShellForGitHub by Microsoft’s PowerShell team.
which exists within Microsoft’s PSGallery repository ecosystem which consists of modules.
It’s a package manager like Chocolatey for Windows Desktops and the Advanced Packaging Tool (APT) of Linux distributions.
-
The module exists within several other PS modules (in a PowerShell CLI Terminal window):
(Find-Module).count $response = Find-Module $response[0] | format-list # details for first item Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
(Find-Module).count
returned 1084 on November 4, 2016. So list commands are not appropriate:$response | Sort-Object $response.GetEnumerator() | Sort-Object Value -descending
-
List the many fields in metadata for module PowerShellForGitHub:
$response.GetEnumerator() | ?{ $_.Name -eq "PowerShellForGitHub" } | format-list
The response:
Name : PowerShellForGitHub Version : 0.1.0 Type : Module Description : PowerShell wrapper for GitHub API Author : Microsoft Corporation CompanyName : PowerShellTeam Copyright : (c) 2016 Microsoft Corporation. All rights reserved. PublishedDate : 7/27/16 8:33:44 PM InstalledDate : UpdatedDate : LicenseUri : https://github.com/PowerShell/PowerShellForGitHub/ blob/master/LICENSE ProjectUri : https://github.com/PowerShell/PowerShellForGitHub IconUri : Tags : {GitHub, API, PowerShell, PSModule} Includes : {Cmdlet, Workflow, Function, DscResource...} PowerShellGetFormatVersion : ReleaseNotes : Dependencies : {} RepositorySourceLocation : https://www.powershellgallery.com/api/v2/ Repository : PSGallery PackageManagementProvider : NuGet AdditionalMetadata : {developmentDependency, FileList, isLatestVersion, IsPrerelease...}
-
This command is necessary to avoid errors when modules are installed:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
If it worked, no text is returned, just the PowerShell prompt again.
-
The GitHub README says to rename ApiTokensTemplate.psm1 to ApiTokens.psm1 and update value of $global:gitHubApiToken with GitHub token for your account.
QUESTION: how do I do that before having the file???
-
Install the latest module in PS Gallery within the PowerShell CLI:
Install-Module -Name PowerShellForGitHub
If Set-PSRepoitory was not run before this, the following would appear:
Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
Rerun after Set-PSRepository:
BLAH: The response I got is aother error, but the message showed me where the file is installed on my Mac:
PackageManagement\Install-Package : Could not find a part of the path '/usr/local/microsoft/powershell/6.0.0-alpha.10/Modules/PowerShellForGitHub/0.1.0'. Installing package 'PowerShellForGitHub' At /usr/local/microsoft/powershell/6.0.0-alpha.10/Modules/PowerShellGet/PSModul e.psm1:1711 char:21 + ... $null = PackageManagement\Install-Package @PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Microsoft.Power....InstallPackage :InstallPackage) [Install-Package], Exception + FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand,Microsoft.PowerShell.PackageManagement. Cmdlets.InstallPackage
Looking into the folder, there are a lot of .dll files. So it’s not applicable to me. Thus, I …
-
Uninstall
Uninstall-Module PowerShellForGitHub
BLAH: This is the error message I received:
PackageManagement\Uninstall-Package : No match was found for the specified search criteria and module names 'PowerShellForGitHub'. At /usr/local/microsoft/powershell/6.0.0-alpha.10/Modules/PowerShellGet/PSModul e.psm1:2096 char:21 + ... $null = PackageManagement\Uninstall-Package @PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Microsoft.Power...ninstallPacka ge:UninstallPackage) [Uninstall-Package], Exception + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagem ent.Cmdlets.UninstallPackage
-
Since I was running a Mac, I got rid of it and went without using a library.
More on API Microservices
This is one of a series:
- API Portals
- GraphQL API
- GitHub API
- GitHub GraphQL API
- API Swagger
- API Design Tools
- API Design
- API Programming
- REST API Responses
- API Management Evaluation
- API Management by Microsoft Azure
- API Management by Amazon
- PowerShell GitHub API Programming
- PowerShell API Programming
- PowerShell Desired State Configuration
- PowerShell on Mac
More about Git & GitHub
This is one of a series on Git and GitHub:
- Why Git? (file-based backups vs Git clone)
- Git basics (script)
- Git whoops (correct mistakes)
- Git command shortcuts
- Git interactive merge (imerge)
- Git patch
- Git utilities
- Git hooks
- GitHub data security
- GitHub actions for automation JavaScript
- GitHub REST API
- GitHub GraphQL API
- GitHub PowerShell API Programming
- GitHub GraphQL PowerShell Module