Using GitHub API via PowerShell Module #18
Replies: 4 comments 1 reply
-
One note, the above uses a user's numeric id in github. In most circumstances, it probably makes more sense to invite by email address. That can be done using "email", see the api docs on creating an organization invite for more info. |
Beta Was this translation helpful? Give feedback.
-
Also, be careful, you can run into paging issues with this approach. Will add some info when I get a chance on how to deal with paging, but there's some docs that seem like a good starting place |
Beta Was this translation helpful? Give feedback.
-
As previously discussed, I have added my helper scripts for converting GitHub API results into Markdown lists. These do the following nice things: Capture work completed in the last sprint. Look for work that might be slipping off of my radar. List issues that need to be sized by the team. Show-GHToDiscuss shows open issues with the label 'DiscussAtStandUp'. Show-GHNoMilestone shows issues that are not part of any GitHub milestone. These commands each have a matching 'Get-' command in case you want to work with |
Beta Was this translation helpful? Give feedback.
-
After some months working with GitHub through PowerShell, I've learned some interesting things about the GitHub API and the GitHub CLI, and when to use each. To that end, I separated my previous PowerShell into two separate modules - one that does tasks that require the API, and another that does tasks that require GitHub CLI. The two tools feel a bit...independent...right now. If you're using them and interacting entirely through PowerShell, you can just mix the two libraries in scripts, as needed, as long as you don't mind first provisioning both types of connections in your shell environment, first. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There's a very handy PowerShell Module for GitHub, PowerShellForGitHub. It lets you work with the GitHub API in a more "powershellesque" fashion.
The one shortcoming so far is that it's not a complete implementation of the api, with the notable exception of missing invites. The the github api is pretty straightforward and I've used a PowerShell script that re-uses the lower-level function that calls out to the api directly....
Following snippet based off of InviteAllFromOrg.ps1. $invitee here has some information about a $user, including their github login, id (numeric id), and team ids for the target organization.
$hashBody = @{}
$hashBody['invitee_id'] = $invitee.id
$hashBody['team_ids'] = @($invitee.TeamNames | %{ $target_org_team_ids[ $_ ] })
$body = (ConvertTo-Json -InputObject $hashBody)
$params = @{
'Method' = 'Post'
'UriFragment' = "orgs/uiuclib-repo-archive/invitations"
'Body' = $body
}
if( -not $DryRun ) {
try {
$invite_results = Invoke-GHRestMethod @params
Write-Output $invite_results
}
catch {
Write-Output "Request failed on $($invitee.login): $PSItem"
}
Beta Was this translation helpful? Give feedback.
All reactions