├── .editorconfig
├── .gitattributes
├── .github
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE
│ └── bug-report.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .prettierrc.json
├── .vscode
└── settings.json
├── Assets
├── PSGitHub-opengraph-header.pdn
└── psgithub.svg
├── Completers
├── Codespaces.ps1
├── Issues.ps1
├── Milestone.ps1
├── Repository.ps1
└── Search.ps1
├── Formats
├── Codespace.Format.ps1xml
├── CombinedCommitStatus.Format.ps1xml
├── Comment.Format.ps1xml
├── Event.Format.ps1xml
├── Label.Format.ps1xml
├── Milestone.Format.ps1xml
├── ProjectCard.Format.ps1xml
├── ProjectColumn.Format.ps1xml
├── PullRequest.Format.ps1xml
├── PullRequestFile.Format.ps1xml
├── RateLimit.Format.ps1xml
├── RateLimitResource.Format.ps1xml
├── RateLimitResources.Format.ps1xml
├── RequestedReviewers.Format.ps1xml
└── Runner.Format.ps1xml
├── Functions
├── Private
│ ├── Add-DefaultParameterValues.ps1
│ ├── ConvertTo-ColoredPatch.ps1
│ ├── Get-GitHubToken.ps1
│ ├── Invoke-GitHubApi.ps1
│ └── Invoke-GitHubGraphQlApi.ps1
└── Public
│ ├── Actions
│ ├── Add-GitHubRunnerLabel.ps1
│ ├── Get-GitHubRunner.ps1
│ ├── Get-GitHubRunnerApplication.ps1
│ ├── Get-GitHubRunnerRegistrationToken.ps1
│ ├── Remove-GitHubRunner.ps1
│ └── Remove-GitHubRunnerLabel.ps1
│ ├── Add-GitHubAssignee.ps1
│ ├── Codespaces
│ ├── Get-GitHubCodespace.ps1
│ ├── Get-GitHubCodespaceMachine.ps1
│ ├── New-GitHubCodespace.ps1
│ ├── Remove-GitHubCodespace.ps1
│ ├── Start-GitHubCodespace.ps1
│ ├── Stop-GitHubCodespace.ps1
│ └── Update-GitHubCodespace.ps1
│ ├── Copy-GitHubTemplateRepository.ps1
│ ├── Find-GitHubLabel.ps1
│ ├── Find-GitHubRepository.ps1
│ ├── Find-GitHubUser.ps1
│ ├── Get-GitHubAssignee.ps1
│ ├── Get-GitHubBetaProject.ps1
│ ├── Get-GitHubCombinedCommitStatus.ps1
│ ├── Get-GitHubComment.ps1
│ ├── Get-GitHubCommitLog.ps1
│ ├── Get-GitHubGist.ps1
│ ├── Get-GitHubLabel.ps1
│ ├── Get-GitHubLicense.ps1
│ ├── Get-GitHubMilestone.ps1
│ ├── Get-GitHubOrganization.ps1
│ ├── Get-GitHubRateLimit.ps1
│ ├── Get-GitHubTeam.ps1
│ ├── Get-GitHubTeamMember.ps1
│ ├── Get-GitHubUser.ps1
│ ├── Issues
│ ├── Find-GitHubIssue.ps1
│ ├── Get-GitHubIssue.ps1
│ ├── Get-GitHubIssueTimeline.ps1
│ ├── New-GitHubIssue.ps1
│ └── Update-GitHubIssue.ps1
│ ├── New-GitHubComment.ps1
│ ├── New-GitHubGist.ps1
│ ├── New-GitHubLabel.ps1
│ ├── New-GitHubMilestone.ps1
│ ├── New-GitHubReview.ps1
│ ├── New-GitHubReviewRequest.ps1
│ ├── Projects
│ ├── Add-GitHubBetaProjectItem.ps1
│ ├── BetaProjectItemFragment.graphql
│ ├── Get-GitHubBetaProjectItem.ps1
│ ├── Get-GitHubProject.ps1
│ ├── Get-GitHubProjectCard.ps1
│ ├── Get-GitHubProjectColumn.ps1
│ ├── Move-GitHubProjectCard.ps1
│ ├── New-GitHubProjectCard.ps1
│ └── Set-GitHubBetaProjectItemField.ps1
│ ├── Pulls
│ ├── Get-GitHubPullRequest.ps1
│ ├── Get-GitHubPullRequestFile.ps1
│ ├── Merge-GitHubPullRequest.ps1
│ ├── New-GitHubPullRequest.ps1
│ └── Update-GitHubPullRequest.ps1
│ ├── Releases
│ ├── Get-GitHubRelease.ps1
│ ├── Get-GitHubReleaseAsset.ps1
│ ├── New-GitHubRelease.ps1
│ ├── New-GitHubReleaseAsset.ps1
│ └── Remove-GitHubReleaseAsset.ps1
│ ├── Remove-GitHubAssignee.ps1
│ ├── Remove-GitHubGist.ps1
│ ├── Remove-GitHubGitRef.ps1
│ ├── Remove-GitHubLabel.ps1
│ ├── Repositories
│ ├── Get-GitHubRepository.ps1
│ ├── Get-GitHubRepositoryLanguages.ps1
│ ├── New-GitHubRepository.ps1
│ └── Remove-GitHubRepository.ps1
│ ├── Save-GitHubGist.ps1
│ ├── Set-GitHubToken.ps1
│ ├── Start-GitHubFork.ps1
│ ├── Submit-GitHubReview.ps1
│ ├── Update-GitHubGist.ps1
│ ├── Update-GitHubLabel.ps1
│ ├── Update-GitHubRepository.ps1
│ └── Update-GitHubUser.ps1
├── LICENSE.md
├── PSGitHub.psd1
├── PSGitHub.psm1
├── PSScriptAnalyzerSettings.psd1
├── README.md
├── Screenshots
├── CombinedCommitStatus-List.svg
├── Issue-Completion.svg
├── Issue-Custom.svg
├── Issue-Table.svg
├── Label-Table.svg
├── Milestone-Table.svg
└── PullRequest-List-Full.svg
├── Tests
└── Unit
│ └── psgithub.tests.ps1
├── Types
├── CombinedCommitStatus.Types.ps1xml
├── Comment.Types.ps1xml
├── Commit.Types.ps1xml
├── CommitStatus.Types.ps1xml
├── Event.Types.ps1xml
├── Gist.Types.ps1xml
├── GistFile.Types.ps1xml
├── Issue.Types.ps1xml
├── Label.Types.ps1xml
├── License.Types.ps1xml
├── Milestone.Types.ps1xml
├── Organization.Types.ps1xml
├── Project.Types.ps1xml
├── ProjectCard.Types.ps1xml
├── ProjectColumn.Types.ps1xml
├── PullRequest.Types.ps1xml
├── PullRequestFile.Types.ps1xml
├── RateLimit.Types.ps1xml
├── RateLimitResource.Types.ps1xml
├── RateLimitResources.Types.ps1xml
├── Release.Types.ps1xml
├── Repository.Types.ps1xml
├── Review.Types.ps1xml
├── Team.Types.ps1xml
└── User.Types.ps1xml
└── appveyor.yml
/.editorconfig:
--------------------------------------------------------------------------------
1 |
2 | [*]
3 | indent_size = 4
4 | indent_style = space
5 | end_of_line = lf
6 | charset = utf-8
7 | insert_final_newline = true
8 | trim_trailing_whitespace = true
9 |
10 | [*.{yml,json,md}]
11 | indent_size = 2
12 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text eol=lf
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | If you'd like to contribue to this project, there are several different methods:
2 |
3 | - Submit a [Pull Request](https://www.github.com/pcgeek86/PSGitHub/pulls) against the GitHub repository, containing:
4 | - Bug fixes
5 | - Documentation enhancements
6 | - Continuous integration & deployment enhancements
7 | - Perform user testing and validation, and report bugs on the [Issue Tracker](https://www.github.com/pcgeek86/PSGitHub/issues)
8 | - Raise awareness about the project through [Twitter](https://twitter.com/#PowerShell), [Facebook](https://facebook.com), and other social media platforms
9 |
10 | If you're new to Git revision control, and the GitHub service, it's suggested that you learn about some basic Git fundamentals, and take an overview of the GitHub service offerings.
11 |
12 | # Contribution Guidelines
13 |
14 | Different software developers have different styles. If you're interested in contributing to this project, please review the following guidelines.
15 | While these guidelines aren't necessarily "set in stone," they should help guide the essence of the project, to ensure quality, user satisfaction (*delight*, even), and success.
16 |
17 | ## Project Structure
18 |
19 | - The module manifest (`.psd1` file) must explicitly denote which functions are being exported. No wildcards allowed.
20 | - Private, helper functions should exist under `/Functions/Private`.
21 | - Publicly accessible functions should exist under `/Functions/Public`.
22 | - We may create subfolders for categories, if this gets too uncontrollable.
23 | - Only one function can be defined in each script file, for public-facing functions.
24 | - Use comment-based help inside the function definition, before the `[CmdletBinding()]` attribute and parameter block
25 | - All functions must declare the `[CmdletBinding()]` attribute.
26 | - Any module configuration, or cached data (such as authentication tokens), should be stored under a single JSON file.
27 | - No use of XML anywhere in the project, unless you enjoy doing work that won't get merged.
28 |
29 | ## Testing
30 |
31 | - We will use the Pester testing framework to perform unit tests.
32 | - Test files should be broken into GitHub feature areas (eg. Repositories, Issues, Users, etc.).
33 | - Test files should exist under `/Tests`.
34 |
35 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug-report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create an issue report to help us improve
4 | title: Please enter an issue title
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | Before submitting your issue for the `PSGitHub` project, please take a moment to provide the following details:
11 |
12 | **Describe the bug**
13 | A clear and concise description of what the bug is.
14 |
15 | **To Reproduce**
16 | Steps to reproduce the behavior:
17 | 1. Go to '...'
18 | 2. Click on '....'
19 | 3. Scroll down to '....'
20 | 4. See error
21 |
22 | **Expected behavior**
23 | A clear and concise description of what you expected to happen.
24 |
25 | **Screenshots**
26 | If applicable, add screenshots to help explain your problem.
27 |
28 | **Environment**
29 | [ ] Version of PowerShell you're using
30 | [ ] PowerShell host you're using (eg. Console Host, ISE, Visual Studio)
31 | [ ] Operating system you're running
32 | [ ] Version of PSGitHub you're using (use Get-Module -Name PSGitHub)
33 |
34 | Thanks for contributing your feedback and support! You can optionally submit a Pull Request against this project, if you have a fix you'd like to share.
35 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Thanks for submitting a Pull Request to the PSGitHub project!
2 |
3 | # Bug Fixes
4 |
5 | Use the pound / hash sign to indicate which GitHub issues this Pull Request fixes, if applicable.
6 |
7 | - Fixes #1
8 | - Fixes #2
9 | - Fixes #3
10 |
11 | # Improvements / Enhancements
12 |
13 | List out any code changes or enhancements you've made. This includes refactoring and removal of extraneous code. :)
14 |
15 | - Enhancement 1
16 | - Enhancement 2
17 | - Enhancement 3
18 |
19 | To improve visibility of this Pull Request, make sure to mention one of the project administrators, using `@githubusername` syntax.
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Screenshots/frames/
2 |
3 | # Project Files
4 | token.json
5 |
6 | # Windows image file caches
7 | Thumbs.db
8 | ehthumbs.db
9 |
10 | # Folder config file
11 | Desktop.ini
12 |
13 | # Recycle Bin used on file shares
14 | $RECYCLE.BIN/
15 |
16 | # Windows Installer files
17 | *.cab
18 | *.msi
19 | *.msm
20 | *.msp
21 |
22 | # Windows shortcuts
23 | *.lnk
24 |
25 | # =========================
26 | # Operating System Files
27 | # =========================
28 |
29 | # OSX
30 | # =========================
31 |
32 | .DS_Store
33 | .AppleDouble
34 | .LSOverride
35 |
36 | # Thumbnails
37 | ._*
38 |
39 | # Files that might appear in the root of a volume
40 | .DocumentRevisions-V100
41 | .fseventsd
42 | .Spotlight-V100
43 | .TemporaryItems
44 | .Trashes
45 | .VolumeIcon.icns
46 |
47 | # Directories potentially created on remote AFP share
48 | .AppleDB
49 | .AppleDesktop
50 | Network Trash Folder
51 | Temporary Items
52 | .apdisk
53 |
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 110,
3 | "proseWrap": "always"
4 | }
5 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.formatOnSave": true,
3 | "[powershell]": {
4 | "editor.formatOnSave": false
5 | },
6 | "powershell.codeFormatting.newLineAfterCloseBrace": false,
7 | "powershell.codeFormatting.alignPropertyValuePairs": false,
8 | "xml.format.joinContentLines": false
9 | }
10 |
--------------------------------------------------------------------------------
/Assets/PSGitHub-opengraph-header.pdn:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pcgeek86/PSGitHub/415fbdfd389d9b6bd24bd8cf435daff3045897c0/Assets/PSGitHub-opengraph-header.pdn
--------------------------------------------------------------------------------
/Completers/Codespaces.ps1:
--------------------------------------------------------------------------------
1 | $codespaceNameCompleter = {
2 | [CmdletBinding()]
3 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
4 | [hashtable] $TokenParam = @{}
5 | Add-DefaultParameterValues -Command $commandName -Parameters $TokenParam
6 |
7 | try {
8 | $CodespaceList = Get-GitHubCodespace @TokenParam
9 | foreach ($Codespace in $CodespaceList) {
10 | if ($Codespace.Name -match $wordToComplete) {
11 | Write-Output -InputObject $Codespace.Name
12 | }
13 | }
14 | }
15 | catch {
16 | #Set-Content -Path psgithub.error.log -Value $PSItem
17 | }
18 | }
19 |
20 | Get-Command -Module PSGitHub -Name *Codespace* | `
21 | Where-Object -FilterScript { $PSItem.Parameters -and $PSItem.Parameters.ContainsKey('CodespaceName') } | `
22 | ForEach-Object { Register-ArgumentCompleter -CommandName $PSItem.Name -ParameterName CodespaceName -ScriptBlock $codespaceNameCompleter }
--------------------------------------------------------------------------------
/Completers/Milestone.ps1:
--------------------------------------------------------------------------------
1 | using namespace System.Management.Automation;
2 |
3 | $milestoneNumberCompleter = {
4 | [CmdletBinding()]
5 | param([string]$command, [string]$parameter, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$params)
6 | Add-DefaultParameterValues -Command $command -Parameters $params
7 | if (-not $params.ContainsKey('RepositoryName')) {
8 | return
9 | }
10 | $getMilestoneParams = @{
11 | RepositoryName = $params.RepositoryName
12 | }
13 | if ($params.ContainsKey('Owner')) {
14 | $getMilestoneParams.Owner = $params.Owner
15 | }
16 | if ($params.ContainsKey('Token')) {
17 | $getMilestoneParams.Token = $params.Token
18 | }
19 | Get-GitHubMilestone @getMilestoneParams |
20 | Where-Object { "$($_.Number)" -like "$wordToComplete*" } |
21 | ForEach-Object {
22 | $tooltip = $_.Title + "`e[3m" + (if ($_.Description) { $_.Description } else { '' }) + "`e[0m"
23 | [CompletionResult]::new($_.Number, "$($_.Number.ToString().PadLeft(2, ' ')) `e[3m$($_.Title)`e[0m", [CompletionResultType]::ParameterValue, $tooltip)
24 | }
25 | }
26 | Register-ArgumentCompleter -CommandName Get-GitHubIssue -ParameterName MilestoneNumber -ScriptBlock $milestoneNumberCompleter
27 | Register-ArgumentCompleter -CommandName New-GitHubPullRequest -ParameterName MilestoneNumber -ScriptBlock $milestoneNumberCompleter
28 | Register-ArgumentCompleter -CommandName Get-GitHubMilestone -ParameterName Number -ScriptBlock $milestoneNumberCompleter
29 |
30 | $milestoneTitleCompleter = {
31 | [CmdletBinding()]
32 | param([string]$command, [string]$parameter, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$params)
33 | Add-DefaultParameterValues -Command $command -Parameters $params
34 | if (-not $params.ContainsKey('RepositoryName')) {
35 | return
36 | }
37 | $getMilestoneParams = @{
38 | RepositoryName = $params.RepositoryName
39 | }
40 | if ($params.ContainsKey('Owner')) {
41 | $getMilestoneParams.Owner = $params.Owner
42 | }
43 | if ($params.ContainsKey('Token')) {
44 | $getMilestoneParams.Token = $params.Token
45 | }
46 | Get-GitHubMilestone @getMilestoneParams |
47 | Where-Object { $_.Title -like "$wordToComplete*" } |
48 | ForEach-Object {
49 | $tooltip = if ($_.Description) { $_.Description } else { $_.Title }
50 | [CompletionResult]::new($_.Title, $_.Title, [CompletionResultType]::ParameterValue, $tooltip)
51 | }
52 | }
53 | Register-ArgumentCompleter -CommandName Get-GitHubIssue -ParameterName MilestoneTitle -ScriptBlock $milestoneTitleCompleter
54 | Register-ArgumentCompleter -CommandName New-GitHubPullRequest -ParameterName MilestoneTitle -ScriptBlock $milestoneTitleCompleter
55 |
--------------------------------------------------------------------------------
/Completers/Repository.ps1:
--------------------------------------------------------------------------------
1 | using namespace System.Management.Automation;
2 |
3 | $ownerCompleter = {
4 | [CmdletBinding()]
5 | param([string]$command, [string]$parameter, [string]$wordToComplete, [CommandAst]$commandAst, [Hashtable]$params)
6 | Add-DefaultParameterValues -Command $command -Parameters $params
7 | & {
8 | $tokenParam = @{ }
9 | if ($params.ContainsKey('Token')) {
10 | $tokenParam.Token = $params.Token
11 | }
12 | # Requesting one of your own repos
13 | $user = Get-GitHubUser @tokenParam
14 | if ($wordToComplete -and $user.Login -like "$wordToComplete*") {
15 | return $user
16 | }
17 | # Requesting a repo of one of your orgs
18 | $orgs = $user | Get-GitHubOrganization @tokenParam | Where-Object { $_.Login -like "$wordToComplete*" }
19 | if ($wordToComplete -and $orgs) {
20 | return $orgs
21 | }
22 | # Invoking autocomplete without any character typed
23 | if (-not $wordToComplete) {
24 | return ($user, $orgs) | ForEach-Object { $_ }
25 | }
26 | # Requesting any other repo
27 | Find-GitHubUser -Query "in:login $wordToComplete" @tokenParam |
28 | Where-Object { $_.Login -like "$wordToComplete*" } |
29 | Select-Object -First 10
30 | } | ForEach-Object {
31 | $tooltip = if ('PSGitHub.Organization' -in $_.PSTypeNames -and $_.Description) {
32 | $_.Description
33 | } elseif ('PSGitHub.User' -in $_.PSTypeNames -and $_.Name) {
34 | $_.Name
35 | } else {
36 | $_.Login
37 | }
38 | [CompletionResult]::new($_.Login, $_.Login, [CompletionResultType]::ParameterValue, $tooltip)
39 | }
40 | }
41 | Get-Command *-GitHub* | Where-Object { $_.Parameters -and $_.Parameters.ContainsKey('Owner') } | ForEach-Object {
42 | Register-ArgumentCompleter -CommandName $_.Name -ParameterName Owner -ScriptBlock $ownerCompleter
43 | }
44 |
45 | $repositoryNameCompleter = {
46 | [CmdletBinding()]
47 | param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
48 |
49 | #Add-DefaultParameterValues -Command $commandName -Parameters $fakeBoundParameter
50 | $RepoArray = [System.Object[]]::new(40)
51 |
52 | $findRepoParams = @{
53 | Query = $wordToComplete
54 | }
55 | if ($fakeBoundParameter.ContainsKey('Owner')) {
56 | $findRepoParams.Query += ' user:{0}' -f $fakeBoundParameter.Owner
57 | }
58 | try {
59 | Find-GitHubRepository @findRepoParams | ForEach-Object -Begin { $i = 0 } -Process {
60 | $RepoArray[$i] = $PSItem
61 | $i++
62 | }
63 | }
64 | catch {
65 | # Once array is filled up, stop execution
66 | }
67 |
68 | try {
69 | foreach ($Repo in $RepoArray) {
70 | $tooltip = if ($Repo.Description) { $Repo.Description } else { $Repo.Name }
71 | if (!$fakeBoundParameter.ContainsKey('Owner')) {
72 | $CompletionText = '{0} -Owner {1}' -f $Repo.Name, $Repo.Owner
73 | [CompletionResult]::new($CompletionText, $Repo.Name, [CompletionResultType]::ParameterValue, $tooltip)
74 | }
75 | else {
76 | [CompletionResult]::new($Repo.Name, $Repo.Name, [CompletionResultType]::ParameterValue, $tooltip)
77 | }
78 | }
79 | }
80 | catch {
81 | # Set-Content -Path $HOME/psgithub.error.log -Value $PSItem
82 | # Add-Content -Path $HOME/psgithub.error.log -Value ($RepoArray.SyncRoot | ConvertTo-Json)
83 | }
84 | }
85 |
86 | Get-Command *-GitHub* | Where-Object { $_.Parameters -and $_.Parameters.ContainsKey('RepositoryName') } | ForEach-Object {
87 | Register-ArgumentCompleter -CommandName $_.Name -ParameterName RepositoryName -ScriptBlock $repositoryNameCompleter
88 | }
89 |
--------------------------------------------------------------------------------
/Formats/Codespace.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Table
5 |
6 | PSGitHub.Codespace
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | id
35 |
36 |
37 | name
38 |
39 |
40 | $_.machine.name
41 |
42 |
43 | state
44 |
45 |
46 | location
47 |
48 |
49 | $_.repository.full_name
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/Formats/CombinedCommitStatus.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | GitHubCombinedCommitStatusList
6 |
7 | PSGitHub.CombinedCommitStatus
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | "`e[33m$($_.Sha)`e[0m"
16 |
17 |
18 |
19 |
20 | $icon = switch ($_.State) {
21 | 'success' { "✅" }
22 | 'pending' { "🔄" }
23 | 'failure' { "❌" }
24 | }
25 | "$icon `e[1m$($_.State)`e[0m"
26 |
27 |
28 |
29 |
30 |
31 | ($_.Statuses | ForEach-Object {
32 | $icon = switch ($_.State) {
33 | 'success' { "✅" }
34 | 'pending' { "🔄" }
35 | 'failure' { "❌" }
36 | 'error' { "❗️" }
37 | }
38 | # iTerm 2 image inline
39 | # $avatar = "`e]1337;File=inline=1;height=1:$([System.Convert]::ToBase64String((Invoke-WebRequest $_.avatar_url).Content))`a"
40 | "$icon $($_.Context) `e[3m$($_.Description)`e[0m`n`e[2m$($_.TargetUrl)`e[0m"
41 | }) -join "`n"
42 |
43 |
44 |
45 | TotalCount
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Formats/Comment.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Compact
5 |
6 | PSGitHub.Comment
7 |
8 |
9 |
10 |
11 |
12 |
13 | "`e[4m`e[1m$($_.User.Login)`e[0m`e[4m on $($_.CreatedAt)`e[0m"
14 |
15 |
16 |
17 | ($_.Body | ConvertFrom-Markdown -AsVT100EncodedString).VT100EncodedString
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | List
26 |
27 | PSGitHub.Comment
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | $_.User.Login
36 |
37 |
38 |
39 | CreatedAt
40 |
41 |
42 |
43 | UpdatedAt
44 |
45 |
46 |
47 | HtmlUrl
48 |
49 |
50 |
51 | ($_.Body | ConvertFrom-Markdown -AsVT100EncodedString).VT100EncodedString
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/Formats/Label.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Table
5 |
6 | PSGitHub.Label
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | $_.ToColoredString()
29 |
30 |
31 | Color
32 |
33 |
34 | Default
35 |
36 |
37 | Description
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Wide
46 |
47 | PSGitHub.Label
48 |
49 |
50 | 4
51 |
52 |
53 |
54 | $_.ToColoredString()
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/Formats/Milestone.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Table
5 |
6 | PSGitHub.Milestone
7 |
8 |
9 |
10 |
11 |
12 |
13 | Right
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | Right
24 |
25 |
26 |
27 | Right
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Number
38 |
39 |
40 |
41 | $color = if ($_.State -eq 'open') { "`e[32m" } else { "`e[31m" }
42 | return $color + $_.State + "`e[0m"
43 |
44 |
45 |
46 | Title
47 |
48 |
49 | "`e[32m$($_.OpenIssues)`e[0m"
50 |
51 |
52 | "`e[31m$($_.ClosedIssues)`e[0m"
53 |
54 |
55 | DueOn
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/Formats/ProjectCard.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Column
5 |
6 | PSGitHub.ProjectCard
7 |
8 |
9 |
10 |
11 |
12 |
13 | Note
14 |
15 |
16 |
17 |
18 |
19 |
20 | PSGitHub.ProjectCard
21 | content_url
22 |
23 |
24 |
25 |
26 | Owner
27 |
28 |
29 | RepositoryName
30 |
31 |
32 | Number
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/Formats/ProjectColumn.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Column
5 |
6 | PSGitHub.ProjectColumn
7 |
8 |
9 | 6
10 |
11 |
12 |
13 | "`e[47m`e[30m $($_.Name) `e[0m"
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Formats/RateLimit.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | List
5 |
6 | PSGitHub.RateLimit
7 |
8 |
9 |
10 |
11 |
12 |
13 | Resources
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Formats/RateLimitResource.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | List
5 |
6 | PSGitHub.RateLimitResource
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | Limit
15 |
16 |
17 |
18 | Remaining
19 |
20 |
21 |
22 | Reset
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Formats/RateLimitResources.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | List
5 |
6 | PSGitHub.RateLimitResources
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | Core
15 |
16 |
17 |
18 | Search
19 |
20 |
21 |
22 | GraphQL
23 |
24 |
25 |
26 | IntegrationManifest
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/Formats/RequestedReviewers.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | List
5 |
6 | PSGitHub.RequestedReviewers
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | Users
15 |
16 |
17 |
18 | Teams
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Formats/Runner.Format.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Table
5 |
6 | PSGitHub.Runner
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | id
35 |
36 |
37 | name
38 |
39 |
40 | os
41 |
42 |
43 | status
44 |
45 |
46 | busy
47 |
48 |
49 | $_.labels.name -join ','
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/Functions/Private/Add-DefaultParameterValues.ps1:
--------------------------------------------------------------------------------
1 |
2 | # Default parameter values do not get applied before a completer is invoked,
3 | # but can contain important defaults like the Token
4 | function Add-DefaultParameterValues {
5 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Scope = 'Function')]
6 | [CmdletBinding()]
7 | param(
8 | [string] $Command,
9 | [hashtable] $Parameters
10 | )
11 | foreach ($entry in $global:PSDefaultParameterValues.GetEnumerator()) {
12 | $commandPattern, $parameter = $entry.Key.Split(':')
13 | if ($Command -like $commandPattern) {
14 | $Parameters.Add($parameter, $entry.Value)
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Functions/Private/ConvertTo-ColoredPatch.ps1:
--------------------------------------------------------------------------------
1 | # Syntax-highlights a git diff with ANSI color codes.
2 | # Used in Format.ps1xml files.
3 | function ConvertTo-ColoredPatch {
4 | [CmdletBinding()]
5 | param(
6 | [Parameter(Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
7 | [string] $Patch
8 | )
9 | process {
10 | ($Patch -split "`n" | ForEach-Object {
11 | if ($_.StartsWith('-')) {
12 | "`e[31m$_`e[0m"
13 | } elseif ($_.StartsWith('+')) {
14 | "`e[32m$_`e[0m"
15 | } elseif ($_.StartsWith('@@')) {
16 | $_ -replace '@@(.+)@@', "`e[36m@@`$1@@`e[0m"
17 | } elseif ($_.StartsWith('diff ') -or $_.StartsWith('index ') -or $_.StartsWith('--- ') -or $_.StartsWith('+++ ')) {
18 | "`e[1m$_`e[0m"
19 | } else {
20 | $_
21 | }
22 | }) -join "`n"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Functions/Private/Get-GitHubToken.ps1:
--------------------------------------------------------------------------------
1 |
2 | function Get-GitHubToken {
3 | <#
4 | .Synopsis
5 | OBSOLETE Internal function to retrieve the GitHub Personal Access Token from disk.
6 |
7 | .Notes
8 | Created by Trevor Sullivan
9 | #>
10 | [CmdletBinding()]
11 | [OutputType([Security.SecureString])]
12 | [Obsolete('Tokens should be provided through the -Token parameter or $PSDefaultParameterValues')]
13 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
14 | param (
15 | )
16 |
17 | # Linux and macOS do not have Windows Data Protection API,
18 | # so they cannot store a token encrypted in a config file
19 | if ($IsMacOS -or $IsLinux) {
20 | return
21 | }
22 |
23 | $tokenPath = '{0}\token.json' -f (Split-Path -Path $MyInvocation.MyCommand.Module.Path -Parent)
24 |
25 | ### Detect if we are running inside the Microsoft Azure Automation service
26 | if (!(Get-Command -Name Get-AutomationPSCredential -ErrorAction Ignore) -or (Get-Process -Name System)) {
27 | # Read the token from disk
28 | if (!(Test-Path $tokenPath)) {
29 | return
30 | }
31 | $config = (Get-Content -Path $tokenPath -Raw | ConvertFrom-Json)
32 | if ([string]::IsNullOrEmpty($config.PersonalAccessToken)) {
33 | return
34 | }
35 | Write-Warning 'Relying on a token set through Set-GitHubToken is deprecated. Provide the -Token parameter or set it through $PSDefaultParameterValues'
36 | $config.PersonalAccessToken | ConvertTo-SecureString
37 | } else {
38 | ### If we're running inside Azure Automation, then retrieve the credential from the Asset Store
39 | $gitHubCredential = Get-AutomationPSCredential -Name GitHub;
40 | $gitHubCredential.Password
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Functions/Private/Invoke-GitHubGraphQlApi.ps1:
--------------------------------------------------------------------------------
1 | function Invoke-GitHubGraphQlApi {
2 | <#
3 | .Synopsis
4 | An internal function that is responsible for invoking the GitHub GraphQL endpoint.
5 |
6 | .Parameter Headers
7 | A HashTable of the HTTP request headers as key-value pairs. Some features in the GitHub
8 | API do not require any request headers, in which case this parameter should not be specified.
9 |
10 | NOTE: Do not include the HTTP Authorization header in this HashTable, as the Authorization header
11 | will be set by this function.
12 |
13 | .Parameter BaseUri
14 | Optional base URL of the GitHub API to resolve Uri from, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
15 | Defaults to "https://api.github.com".
16 |
17 | .Parameter Token
18 | The GitHub OAuth token to use for authenticating the request.
19 | Create one at https://github.com/settings/tokens/new.
20 | Not all requests require a token.
21 | #>
22 | [CmdletBinding()]
23 | param (
24 | [Parameter(Mandatory, Position = 0)]
25 | [string] $Query,
26 |
27 | $Variables = @{ },
28 |
29 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
30 |
31 | # HTTP headers
32 | [HashTable] $Headers = @{ },
33 |
34 | [Security.SecureString] $Token
35 | )
36 |
37 | process {
38 | $Headers['User-Agent'] = 'PowerShell PSGitHub'
39 |
40 | # Resolve the Uri parameter with https://api.github.com as a base URI
41 | # This allows to call this function with just a path,
42 | # but also supply a full URI (e.g. for a GitHub enterprise instance)
43 | $Uri = [Uri]::new($BaseUri, 'graphql')
44 |
45 | $apiRequest = @{
46 | Headers = $Headers
47 | Uri = $Uri
48 | Method = 'POST'
49 | }
50 |
51 | # add the HTTP Authorization header to authenticate the HTTP request.
52 | if ($Token) {
53 | $apiRequest.Authentication = 'Bearer'
54 | $apiRequest.Token = $Token
55 | } else {
56 | Write-Verbose -Message 'Making request without API token'
57 | }
58 |
59 |
60 | $body = @{
61 | query = $Query
62 | variables = $Variables
63 | }
64 |
65 | $apiRequest.Body = $body | ConvertTo-Json -Depth 100
66 | Write-Debug ("Query: " + $Query)
67 | Write-Debug ("Variables: " + ($Variables | ConvertTo-Json))
68 |
69 | # We need to communicate using TLS 1.2 against GitHub.
70 | [Net.ServicePointManager]::SecurityProtocol = 'tls12'
71 |
72 | # Invoke the REST API
73 | try {
74 | $result = Invoke-RestMethod @apiRequest -ResponseHeadersVariable responseHeaders
75 | if ($responseHeaders.ContainsKey('X-RateLimit-Limit')) {
76 | Write-Verbose "Rate limit total: $($responseHeaders['X-RateLimit-Limit'])"
77 | Write-Verbose "Rate limit remaining: $($responseHeaders['X-RateLimit-Remaining'])"
78 | $resetUnixSeconds = [int]($responseHeaders['X-RateLimit-Reset'][0])
79 | $resetDateTime = ([System.DateTimeOffset]::FromUnixTimeSeconds($resetUnixSeconds)).DateTime
80 | Write-Verbose "Rate limit resets: $resetDateTime"
81 | }
82 | if ($result.errors) {
83 | $result.errors | ForEach-Object message | Write-Error
84 | }
85 | $result.data
86 | } catch {
87 | if (
88 | $_.Exception.PSObject.TypeNames -notcontains 'Microsoft.PowerShell.Commands.HttpResponseException' -and # PowerShell Core
89 | $_.Exception -isnot [System.Net.WebException] # Windows PowerShell
90 | ) {
91 | # Throw any error that is not a HTTP response error (e.g. server not reachable)
92 | throw $_
93 | }
94 | # This is the only way to get access to the response body for errors in old PowerShell versions.
95 | # PowerShell >=7.0 could use -SkipHttpErrorCheck with -StatusCodeVariable
96 | $_.ErrorDetails.Message | Write-Error
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Functions/Public/Actions/Add-GitHubRunnerLabel.ps1:
--------------------------------------------------------------------------------
1 | function Add-GitHubRunnerLabel {
2 | <#
3 | .SYNOPSIS
4 | Add a new label to a GitHub Runner that's registered to a GitHub repository.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.RunnerLabels')]
8 | param(
9 | [Parameter(Mandatory, Position = 0)]
10 | [string] $Owner,
11 |
12 | [Parameter(Mandatory, Position = 1)]
13 | [string] $RepositoryName,
14 |
15 | [Parameter(Mandatory, Position = 2)]
16 | [string] $RunnerId,
17 |
18 | [Parameter(Mandatory, Position = 2)]
19 | [string[]] $Label,
20 |
21 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
22 | # Defaults to "https://api.github.com"
23 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
24 | [Security.SecureString] $Token
25 | )
26 |
27 | process {
28 | $Body = @{
29 | labels = $Label
30 | } | ConvertTo-Json
31 | $Path = 'repos/{0}/{1}/actions/runners/{2}/labels' -f $Owner, $RepositoryName, $RunnerId
32 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Post -Body $Body |
33 | ForEach-Object { $_ } |
34 | ForEach-Object {
35 | $_.PSTypeNames.Insert(0, 'PSGitHub.RunnerLabels')
36 | $_
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Functions/Public/Actions/Get-GitHubRunner.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubRunner {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the GitHub Runners registered to a GitHub repository.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Runner')]
8 | param(
9 | [Parameter(Mandatory, Position = 0)]
10 | [string] $Owner,
11 |
12 | [Parameter(Mandatory, Position = 1)]
13 | [Alias('Name')]
14 | [string] $RepositoryName,
15 |
16 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17 | # Defaults to "https://api.github.com"
18 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19 | [Security.SecureString] $Token
20 | )
21 |
22 | process {
23 | $Path = 'repos/{0}/{1}/actions/runners' -f $Owner, $RepositoryName
24 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token |
25 | ForEach-Object { $_.runners } |
26 | ForEach-Object {
27 | $_.PSTypeNames.Insert(0, 'PSGitHub.Runner')
28 | $_
29 | }
30 | }
31 | }
32 |
33 | Export-ModuleMember -Alias @(
34 | (New-Alias -Name gghrun -Value Get-GitHubRunner -PassThru)
35 | )
36 |
--------------------------------------------------------------------------------
/Functions/Public/Actions/Get-GitHubRunnerApplication.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubRunnerApplication {
2 | <#
3 | .SYNOPSIS
4 | Retrieves the URLs to download the GitHub Runner application archive, with the installation files.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.RunnerApplication')]
8 | param(
9 | [Parameter(Mandatory, Position = 0)]
10 | [string] $Owner,
11 |
12 | [Parameter(Mandatory, Position = 1)]
13 | [Alias('Name')]
14 | [string] $RepositoryName,
15 |
16 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17 | # Defaults to "https://api.github.com"
18 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19 | [Security.SecureString] $Token
20 | )
21 |
22 | process {
23 | $Path = 'repos/{0}/{1}/actions/runners/downloads' -f $Owner, $RepositoryName
24 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token |
25 | ForEach-Object { $_ } |
26 | ForEach-Object {
27 | $_.PSTypeNames.Insert(0, 'PSGitHub.RunnerApplication')
28 | $_
29 | }
30 | }
31 | }
32 |
33 | Export-ModuleMember -Alias @(
34 | (New-Alias -Name gghrunapp -Value Get-GitHubRunnerApplication -PassThru)
35 | )
36 |
--------------------------------------------------------------------------------
/Functions/Public/Actions/Get-GitHubRunnerRegistrationToken.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubRunnerRegistrationToken {
2 | <#
3 | .SYNOPSIS
4 | Retrieves a registration token for GitHub Actions self-hosted runners. Pass this token to the GitHub Runner configuration script, to register it with a GitHub repository.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.RunnerRegistrationToken')]
8 | param(
9 | [Parameter(Mandatory, Position = 0)]
10 | [string] $Owner,
11 |
12 | [Parameter(Mandatory, Position = 1)]
13 | [Alias('Name')]
14 | [string] $RepositoryName,
15 |
16 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17 | # Defaults to "https://api.github.com"
18 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19 | [Security.SecureString] $Token
20 | )
21 |
22 | process {
23 | $Path = 'repos/{0}/{1}/actions/runners/registration-token' -f $Owner, $RepositoryName
24 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Post |
25 | ForEach-Object { $_ } |
26 | ForEach-Object {
27 | $_.PSTypeNames.Insert(0, 'PSGitHub.RunnerRegistrationToken')
28 | $_
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Functions/Public/Actions/Remove-GitHubRunner.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubRunner {
2 | <#
3 | .SYNOPSIS
4 | Removes a registered GitHub Runner from a GitHub repository.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Runner')]
8 | param(
9 | [Parameter(Mandatory, Position = 0)]
10 | [string] $Owner,
11 |
12 | [Parameter(Mandatory, Position = 1)]
13 | [string] $RepositoryName,
14 |
15 | [Parameter(Mandatory, Position = 2)]
16 | [int] $RunnerId,
17 |
18 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
19 | # Defaults to "https://api.github.com"
20 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
21 | [Security.SecureString] $Token
22 | )
23 |
24 | process {
25 | $Path = 'repos/{0}/{1}/actions/runners/{2}' -f $Owner, $RepositoryName, $RunnerId
26 | $null = Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Delete
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/Functions/Public/Actions/Remove-GitHubRunnerLabel.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubRunnerLabel {
2 | <#
3 | .SYNOPSIS
4 | Removes a label from a GitHub Runner that's registered to a GitHub repository.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.RunnerLabels')]
8 | param(
9 | [Parameter(Mandatory, Position = 0)]
10 | [string] $Owner,
11 |
12 | [Parameter(Mandatory, Position = 1)]
13 | [string] $RepositoryName,
14 |
15 | [Parameter(Mandatory, Position = 2)]
16 | [string] $RunnerId,
17 |
18 | [Parameter(Mandatory, Position = 2)]
19 | [string] $Label,
20 |
21 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
22 | # Defaults to "https://api.github.com"
23 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
24 | [Security.SecureString] $Token
25 | )
26 |
27 | process {
28 | $Path = 'repos/{0}/{1}/actions/runners/{2}/labels/{3}' -f $Owner, $RepositoryName, $RunnerId, $Label
29 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Delete -Body $Body |
30 | ForEach-Object { $_ } |
31 | ForEach-Object {
32 | $_.PSTypeNames.Insert(0, 'PSGitHub.RunnerLabels')
33 | $_
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Functions/Public/Add-GitHubAssignee.ps1:
--------------------------------------------------------------------------------
1 | function Add-GitHubAssignee {
2 | [CmdletBinding(SupportsShouldProcess)]
3 | [OutputType('PSGitHub.Issue')]
4 | param (
5 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
6 | [Alias('User')]
7 | [string] $Owner,
8 |
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [ValidateNotNullOrEmpty()]
11 | [ValidatePattern('^[\w-\.]+$')]
12 | [Alias('Repository')]
13 | [string] $RepositoryName,
14 |
15 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
16 | [int] $Number,
17 |
18 | # Usernames who will be added as assignees to the issue.
19 | [string[]] $Assignees,
20 |
21 | # Team slugs whose members will be added as assignees to the issue (in addition to Assignees).
22 | [string[]] $TeamAssignees,
23 |
24 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
25 | # Defaults to "https://api.github.com"
26 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
27 | [Security.SecureString] $Token
28 | )
29 |
30 | process {
31 | if ($TeamAssignees) {
32 | $Assignees += $TeamAssignees |
33 | ForEach-Object { Get-GitHubTeam -OrganizationName $Owner -Slug $_ -Token $Token } |
34 | Get-GitHubTeamMember -Token $Token |
35 | ForEach-Object { $_.Login }
36 | }
37 |
38 | $body = @{
39 | assignees = $Assignees
40 | }
41 |
42 | $shouldProcessCaption = "Adding assignee to GitHub issue"
43 | $shouldProcessDescription = "Adding $($Assignees.Count) assignees to GitHub issue `e[1m#$Number`e[0m in repository `e[1m$Owner/$RepositoryName`e[0m."
44 | $shouldProcessWarning = "Do you want to add $($Assignees.Count) assignees the GitHub issue `e[1m#$Number`e[0m in repository `e[1m$Owner/$RepositoryName`e[0m?"
45 |
46 | if ($PSCmdlet.ShouldProcess($shouldProcessDescription, $shouldProcessWarning, $shouldProcessCaption)) {
47 | Invoke-GitHubApi -Method POST "repos/$Owner/$RepositoryName/issues/$Number/assignees" -Body ($body | ConvertTo-Json) -BaseUri $BaseUri -Token $Token |
48 | ForEach-Object {
49 | $_.PSTypeNames.Insert(0, 'PSGitHub.Issue')
50 | $_.User.PSTypeNames.Insert(0, 'PSGitHub.User')
51 | foreach ($label in $_.Labels) {
52 | $label.PSTypeNames.Insert(0, 'PSGitHub.Label')
53 | }
54 | foreach ($assignee in $_.Assignees) {
55 | $assignee.PSTypeNames.Insert(0, 'PSGitHub.User')
56 | }
57 | $_
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Functions/Public/Codespaces/Get-GitHubCodespace.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubCodespace {
2 | <#
3 | .SYNOPSIS
4 | Lists the authenticated user's codespaces.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Codespace')]
8 | param(
9 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
10 | # Defaults to "https://api.github.com"
11 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
12 | [Security.SecureString] $Token
13 | )
14 |
15 | process {
16 | $Path = 'user/codespaces'
17 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token |
18 | ForEach-Object { $_.codespaces } |
19 | ForEach-Object {
20 | $_.PSTypeNames.Insert(0, 'PSGitHub.Codespace')
21 | $_
22 | }
23 | }
24 | }
25 |
26 | Export-ModuleMember -Alias @(
27 | (New-Alias -Name gghcs -Value Get-GitHubCodespace -PassThru)
28 | )
29 |
--------------------------------------------------------------------------------
/Functions/Public/Codespaces/Get-GitHubCodespaceMachine.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubCodespaceMachine {
2 | <#
3 | .SYNOPSIS
4 | List the machine types a codespace can transition to use.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.CodespaceMachine')]
8 | param(
9 | [Parameter(Mandatory = $true, Position = 0)]
10 | [Alias('Name')]
11 | [string] $CodespaceName,
12 |
13 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
14 | # Defaults to "https://api.github.com"
15 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
16 | [Security.SecureString] $Token
17 | )
18 |
19 | process {
20 | $Path = 'user/codespaces/{0}/machines' -f $CodespaceName
21 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token |
22 | ForEach-Object { $_.machines } |
23 | ForEach-Object {
24 | $_.PSTypeNames.Insert(0, 'PSGitHub.CodespaceMachine')
25 | $_
26 | }
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/Functions/Public/Codespaces/New-GitHubCodespace.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubCodespace {
2 | <#
3 | .SYNOPSIS
4 | Creates a codespace owned by the authenticated user in the specified repository.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Codespace')]
8 | param(
9 | [Parameter(Mandatory = $true)]
10 | [string] $Owner,
11 |
12 | [Parameter(Mandatory = $true, Position = 0)]
13 | [string] $RepositoryName,
14 |
15 | [string] $Location = 'WestUs2',
16 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17 | # Defaults to "https://api.github.com"
18 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19 | [Security.SecureString] $Token
20 | )
21 |
22 | process {
23 | $Path = 'repos/{0}/{1}/codespaces' -f $Owner, $RepositoryName
24 | $Body = @{
25 | location = $Location
26 | } | ConvertTo-Json
27 | Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Post -Body $Body
28 | }
29 | }
30 |
31 | Export-ModuleMember -Alias @(
32 | (New-Alias -Name nghcs -Value New-GitHubCodespace -PassThru)
33 | )
34 |
--------------------------------------------------------------------------------
/Functions/Public/Codespaces/Remove-GitHubCodespace.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubCodespace {
2 | <#
3 | .SYNOPSIS
4 | Deletes a user's codespace.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Codespace')]
8 | param(
9 | [Parameter(Mandatory = $true, Position = 0)]
10 | [Alias('Name')]
11 | [string] $CodespaceName,
12 |
13 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
14 | # Defaults to "https://api.github.com"
15 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
16 | [Security.SecureString] $Token
17 | )
18 |
19 | process {
20 | $Path = 'user/codespaces/{0}' -f $CodespaceName
21 | $null = Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Delete
22 | }
23 | }
24 |
25 | Export-ModuleMember -Alias @(
26 | (New-Alias -Name rmghcs -Value Remove-GitHubCodespace -PassThru)
27 | )
28 |
--------------------------------------------------------------------------------
/Functions/Public/Codespaces/Start-GitHubCodespace.ps1:
--------------------------------------------------------------------------------
1 | function Start-GitHubCodespace {
2 | <#
3 | .SYNOPSIS
4 | Starts a user's codespace.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Codespace')]
8 | param(
9 | [Parameter(Mandatory = $true, Position = 0)]
10 | [Alias('Name')]
11 | [string] $CodespaceName,
12 |
13 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
14 | # Defaults to "https://api.github.com"
15 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
16 | [Security.SecureString] $Token
17 | )
18 |
19 | process {
20 | $Path = 'user/codespaces/{0}/start' -f $CodespaceName
21 | $null = Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Post
22 | }
23 | }
24 |
25 | Export-ModuleMember -Alias @(
26 | (New-Alias -Name saghcs -Value Start-GitHubCodespace -PassThru)
27 | )
28 |
--------------------------------------------------------------------------------
/Functions/Public/Codespaces/Stop-GitHubCodespace.ps1:
--------------------------------------------------------------------------------
1 | function Stop-GitHubCodespace {
2 | <#
3 | .SYNOPSIS
4 | Stops a user's codespace.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Codespace')]
8 | param(
9 | [Parameter(Mandatory = $true, Position = 0)]
10 | [Alias('Name')]
11 | [string] $CodespaceName,
12 |
13 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
14 | # Defaults to "https://api.github.com"
15 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
16 | [Security.SecureString] $Token
17 | )
18 |
19 | process {
20 | $Path = 'user/codespaces/{0}/stop' -f $CodespaceName
21 | $null = Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Post
22 | }
23 | }
24 |
25 | Export-ModuleMember -Alias @(
26 | (New-Alias -Name spghcs -Value Stop-GitHubCodespace -PassThru)
27 | )
28 |
--------------------------------------------------------------------------------
/Functions/Public/Codespaces/Update-GitHubCodespace.ps1:
--------------------------------------------------------------------------------
1 | function Update-GitHubCodespace {
2 | <#
3 | .SYNOPSIS
4 | Updates a user's codespace.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Codespace')]
8 | param(
9 | [Parameter(Mandatory = $true, Position = 0)]
10 | [Alias('Name')]
11 | [string] $CodespaceName,
12 |
13 | [Parameter(Mandatory = $true, Position = 1)]
14 | [string] $Machine,
15 |
16 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17 | # Defaults to "https://api.github.com"
18 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19 | [Security.SecureString] $Token
20 | )
21 |
22 | process {
23 | $Path = 'user/codespaces/{0}' -f $CodespaceName
24 | $Body = @{
25 | machine = $Machine
26 | } | ConvertTo-Json
27 | $null = Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Patch Body $Body
28 | }
29 | }
30 |
31 | Export-ModuleMember -Alias @(
32 | (New-Alias -Name upghcs -Value Update-GitHubCodespace -PassThru)
33 | )
34 |
--------------------------------------------------------------------------------
/Functions/Public/Copy-GitHubTemplateRepository.ps1:
--------------------------------------------------------------------------------
1 | function Copy-GitHubTemplateRepository {
2 | <#
3 | .Synopsis
4 | Creates a new repository using a repository template.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Repository')]
8 | param (
9 | [Parameter(Mandatory, Position = 0)]
10 | [ValidateNotNullOrEmpty()]
11 | [string] $Name,
12 |
13 | [Parameter(Mandatory)]
14 | [ValidateNotNullOrEmpty()]
15 | [string] $Owner,
16 |
17 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
18 | [ValidateNotNullOrEmpty()]
19 | [string] $TemplateOwner,
20 |
21 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
22 | [ValidateNotNullOrEmpty()]
23 | [string] $TemplateRepositoryName,
24 |
25 | [string] $Description,
26 | [switch] $Private,
27 |
28 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
29 | # Defaults to "https://api.github.com"
30 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
31 | [Security.SecureString] $Token
32 | )
33 |
34 | process {
35 |
36 | $uri = "repos/$TemplateOwner/$TemplateRepository/generate"
37 | $body = @{
38 | name = $Name
39 | description = $Description
40 | owner = $Owner
41 | private = [bool]$Private
42 | }
43 |
44 | Invoke-GitHubApi -Method POST $uri -Body ($Body | ConvertTo-Json) -BaseUri $BaseUri -Token $Token | ForEach-Object {
45 | $_.PSTypeNames.Insert(0, 'PSGitHub.Repository')
46 | $_.TemplateRepository.PSTypeNames.Insert(0, 'PSGitHub.Repository')
47 | $_.Owner.Insert(0, 'PSGitHub.User')
48 | $_
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Functions/Public/Find-GitHubLabel.ps1:
--------------------------------------------------------------------------------
1 | function Find-GitHubLabel {
2 | <#
3 | .SYNOPSIS
4 | Searches GitHub labels for a repository by a search query.
5 | .INPUTS
6 | PSGitHub.Repository
7 | #>
8 | [CmdletBinding()]
9 | [OutputType('PSGitHub.Label')]
10 | param(
11 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
12 | [Alias('Id')]
13 | [int] $RepositoryId,
14 |
15 | [Parameter(Mandatory, Position = 0)]
16 | [string] $Query,
17 |
18 | [ValidateSet('created', 'updated')]
19 | [string] $Sort,
20 |
21 | [ValidateSet('asc', 'desc')]
22 | [Alias('Direction')]
23 | [string] $Order,
24 |
25 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
26 | # Defaults to "https://api.github.com"
27 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
28 | [Security.SecureString] $Token
29 | )
30 |
31 | process {
32 | $params = @{
33 | repository_id = $RepositoryId
34 | q = $Query
35 | sort = $Sort
36 | order = $Order
37 | }
38 | $headers = @{
39 | Accept = 'application/vnd.github.symmetra-preview+json'
40 | }
41 | Invoke-GitHubApi 'search/labels' -Body $params -BaseUri $BaseUri -Token $Token -Headers $headers |
42 | ForEach-Object { $_.items } |
43 | ForEach-Object {
44 | $_.PSTypeNames.Insert(0, 'PSGitHub.Label')
45 | $_
46 | }
47 | }
48 | }
49 |
50 | Export-ModuleMember -Alias (
51 | New-Alias -Name Search-GitHubLabels -Value Find-GitHubLabel -PassThru
52 | )
53 |
--------------------------------------------------------------------------------
/Functions/Public/Find-GitHubRepository.ps1:
--------------------------------------------------------------------------------
1 | function Find-GitHubRepository {
2 | <#
3 | .Synopsis
4 | This function searches for repositories on GitHub.
5 |
6 | .Parameter Sort
7 | Optional. Choose the property to sort on, for GitHub repository search results:
8 |
9 | - Default: Best match
10 | - Stars: Sort by the number of stars the repositories have
11 | - Forks: Sort by the number of forks the repositories have
12 | - Updated: Sort by the last update date/time of the repositories
13 |
14 | .Parameter Order
15 | Optional. Specify the order to sort search results.
16 |
17 | - Ascending
18 | - Descending
19 |
20 | .Link
21 | https://trevorsullivan.net
22 | https://developer.github.com/v3/search
23 | #>
24 | [CmdletBinding()]
25 | [OutputType('PSGitHub.Repository')]
26 | param (
27 | [Parameter(Mandatory, Position = 0)]
28 | [string] $Query,
29 |
30 | [ValidateSet('stars', 'forks', 'updated', 'help-wanted-issues')]
31 | [Alias('SortBy')] # BC
32 | [string] $Sort,
33 |
34 | [ValidateSet('asc', 'desc')]
35 | [Alias('SortOrder')] # BC
36 | [Alias('Direction')]
37 | [string] $Order,
38 |
39 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
40 | # Defaults to "https://api.github.com"
41 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
42 | [Security.SecureString] $Token
43 | )
44 |
45 | $queryParams = @{
46 | q = $Query
47 | }
48 | if ($Sort) {
49 | $queryParams.Add('sort', $Sort);
50 | }
51 | if ($Order) {
52 | $queryParams.Add('order', $Order);
53 | }
54 |
55 | $ApiCall = @{
56 | Uri = 'search/repositories'
57 | Body = $queryParams
58 | Token = $Token
59 | BaseUri = $BaseUri
60 | }
61 | Invoke-GitHubApi @ApiCall | ForEach-Object { $_.items } | ForEach-Object {
62 | $_.PSTypeNames.Insert(0, 'PSGitHub.Repository')
63 | $_.Owner.PSTypeNames.Insert(0, 'PSGitHub.User')
64 | if ($_.License) {
65 | $_.License.PSTypeNames.Insert(0, 'PSGitHub.License')
66 | }
67 | $_
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Functions/Public/Find-GitHubUser.ps1:
--------------------------------------------------------------------------------
1 | function Find-GitHubUser {
2 | <#
3 | .SYNOPSIS
4 | Searches GitHub issues and pull requests by a search query.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.User')]
8 | param(
9 | [Parameter(Mandatory)]
10 | [string] $Query,
11 |
12 | [ValidateSet('followers', 'repositories', 'joined')]
13 | [string] $Sort,
14 |
15 | [ValidateSet('asc', 'desc')]
16 | [Alias('Direction')]
17 | [string] $Order,
18 |
19 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
20 | # Defaults to "https://api.github.com"
21 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
22 | [Security.SecureString] $Token
23 | )
24 |
25 | process {
26 | $params = @{
27 | q = $Query
28 | sort = $Sort
29 | order = $Order
30 | }
31 | Invoke-GitHubApi 'search/users' -Body $params -BaseUri $BaseUri -Token $Token |
32 | ForEach-Object { $_.items } |
33 | ForEach-Object {
34 | $_.PSTypeNames.Insert(0, 'PSGitHub.User')
35 | $_
36 | }
37 | }
38 | }
39 |
40 | Export-ModuleMember -Alias @(
41 | (New-Alias -Name Search-GitHubUsers -Value Find-GitHubUser -PassThru),
42 | (New-Alias -Name Find-GitHubOrganization -Value Find-GitHubUser -PassThru),
43 | (New-Alias -Name Search-GitHubOrganizations -Value Find-GitHubUser -PassThru)
44 | )
45 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubAssignee.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubAssignee {
2 | <#
3 | .SYNOPSIS
4 | This function returns a list of valid assignees for a GitHub repository.
5 |
6 | .INPUTS
7 | PSGitHub.PullRequest
8 | PSGitHub.Repository
9 |
10 | .LINK
11 | https://trevorsullivan.net
12 | https://developer.github.com/v3/issues/assignees/#list-assignees
13 | #>
14 | [CmdletBinding()]
15 | [OutputType('PSGitHub.User')]
16 | param (
17 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
18 | [string] $Owner,
19 |
20 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
21 | [ValidateNotNullOrEmpty()]
22 | [ValidatePattern('^[\w-\.]+$')]
23 | [Alias('Repository')]
24 | [string] $RepositoryName,
25 |
26 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
27 | # Defaults to "https://api.github.com"
28 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
29 | [Security.SecureString] $Token
30 | )
31 | process {
32 | Invoke-GitHubApi "repos/$Owner/$RepositoryName/assignees" -BaseUri $BaseUri -Token $Token | ForEach-Object { $_ } | ForEach-Object {
33 | $_.PSTypeNames.Insert(0, 'PSGitHub.User')
34 | $_
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubBetaProject.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubBetaProject {
2 | <#
3 | .SYNOPSIS
4 | EXPERIMENTAL: Gets a GitHub project (Beta).
5 | #>
6 | [CmdletBinding()]
7 | param(
8 | # The project node ID.
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [Alias('ProjectNodeId')]
11 | [string] $Id,
12 |
13 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
14 | # Defaults to "https://api.github.com"
15 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
16 | [Security.SecureString] $Token
17 | )
18 |
19 | process {
20 | $result = Invoke-GitHubGraphQlApi `
21 | -Headers @{ 'GraphQL-Features' = 'projects_next_graphql' } `
22 | -Query 'query($projectId: ID!) {
23 | node(id: $projectId) {
24 | ... on ProjectNext {
25 | id
26 | number
27 | title
28 | description
29 | updatedAt
30 | viewerCanUpdate
31 | closed
32 | owner {
33 | ... on Organization {
34 | login
35 | }
36 | }
37 | fields(first: 30) {
38 | nodes {
39 | name
40 | settings
41 | createdAt
42 | updatedAt
43 | }
44 | }
45 | }
46 | }
47 | }' `
48 | -Variables @{
49 | projectId = $Id
50 | } `
51 | -BaseUri $BaseUri `
52 | -Token $Token
53 |
54 | if (!$result.node) {
55 | return
56 | }
57 |
58 | $fields = [ordered]@{ }
59 | foreach ($field in $result.node.fields.nodes) {
60 | $field.settings = $field.settings | ConvertFrom-Json
61 | $fields[$field.name] = $field
62 | }
63 |
64 | $result.node.fields = $fields
65 |
66 | $result.node
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubCombinedCommitStatus.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubCombinedCommitStatus {
2 | <#
3 | .SYNOPSIS
4 | Gets the status of a commit
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.CombinedCommitStatus')]
8 | param(
9 | # The owner of the target repository
10 | [Parameter(ValueFromPipelineByPropertyName)]
11 | [string] $Owner = (Get-GitHubUser -Token $Token).login, # This doesn't work for org repos.
12 |
13 | # The name of the repository
14 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
15 | [ValidateNotNullOrEmpty()]
16 | [ValidatePattern('^[\w-\.]+$')]
17 | [Alias('Repository')]
18 | [string] $RepositoryName,
19 |
20 | # SHA, branch name or tag name
21 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
22 | [ValidateNotNullOrEmpty()]
23 | [Alias('Sha')]
24 | [Alias('FriendlyName')]
25 | [string] $Ref,
26 |
27 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
28 | # Defaults to "https://api.github.com"
29 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
30 | [Security.SecureString] $Token
31 | )
32 |
33 | process {
34 | Invoke-GitHubApi "repos/$Owner/$RepositoryName/commits/$Ref/status" -BaseUri $BaseUri -Token $Token | ForEach-Object {
35 | $_.PSTypeNames.Insert(0, 'PSGitHub.CombinedCommitStatus')
36 | $_.Repository.PSTypeNames.Insert(0, 'PSGitHub.Repository')
37 | $_.Repository.Owner.PSTypeNames.Insert(0, 'PSGitHub.User')
38 | foreach ($status in $_.Statuses) {
39 | $status.PSTypeNames.Insert(0, 'PSGitHub.CommitStatus')
40 | }
41 | $_
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubCommitLog.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubCommitLog {
2 | <#
3 | .SYNOPSIS
4 | Get the commits of a GitHub repository.
5 | #>
6 |
7 | [CmdletBinding()]
8 | [OutputType('PSGitHub.Commit')]
9 | param(
10 | [Parameter(ValueFromPipelineByPropertyName)]
11 | [string] $Owner,
12 |
13 | [Parameter(ValueFromPipelineByPropertyName)]
14 | [ValidateNotNullOrEmpty()]
15 | [ValidatePattern('^[\w-\.]+$')]
16 | [string] $RepositoryName,
17 |
18 | [Parameter(ValueFromPipelineByPropertyName)]
19 | [Alias('Name')] # For piping branches
20 | [string] $Ref,
21 |
22 | [string] $Author,
23 | [string] $Path,
24 | [DateTime] $Since,
25 | [DateTime] $Until,
26 |
27 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
28 | # Defaults to "https://api.github.com"
29 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
30 | [Security.SecureString] $Token
31 | )
32 |
33 | process {
34 | $uri = "repos/$Owner/$RepositoryName/commits"
35 | $params = @()
36 | if ($Ref) {
37 | $params += "sha=$Ref"
38 | }
39 | if ($Author) {
40 | $params += "author=$Author"
41 | }
42 | if ($Since) {
43 | $params += "since=" + $Since.ToString('o')
44 | }
45 | if ($Until) {
46 | $params += "until=" + $Until.ToString('o')
47 | }
48 | if ($Path) {
49 | $params += "path=" + $Path.ToString('o')
50 | }
51 | $uri += "?" + ($params -join "&")
52 | # expand arrays
53 | Invoke-GitHubApi $uri -BaseUri $BaseUri -Token $Token |
54 | ForEach-Object { $_ } |
55 | ForEach-Object {
56 | $_.PSTypeNames.Insert(0, 'PSGitHub.Commit')
57 | if ($null -ne $_.Author) {
58 | $_.Author.PSTypeNames.Insert(0, 'PSGitHub.User')
59 | }
60 | if ($null -ne $_.Committer) {
61 | $_.Committer.PSTypeNames.Insert(0, 'PSGitHub.User')
62 | }
63 | foreach ($parent in $_.Parents) {
64 | $parent.PSTypeNames.Insert(0, 'PSGitHub.Commit')
65 | }
66 | $_
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubLabel.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubLabel {
2 | <#
3 | .SYNOPSIS
4 | Gets GitHub labels.
5 |
6 | .DESCRIPTION
7 | This command retrieves GitHub labels for the specified repository using
8 | the authenticated user.
9 |
10 | .PARAMETER Owner
11 | The GitHub username of the account or organization that owns the GitHub
12 | repository specified in the parameter -RepositoryName parameter.
13 |
14 | .PARAMETER Repository
15 | The name of the GitHub repository, that is owned by the GitHub username
16 | specified by parameter -Owner.
17 |
18 | .PARAMETER Name
19 | Retrieve a single label with the specified name from the GitHub repository
20 | specified by the parameters -Owner and -RepositoryName.
21 |
22 | .PARAMETER Page
23 | The page number of the results to return. Default: 1
24 |
25 | .EXAMPLE
26 | # Retrieve all labels from the repository Mary/WebApps:
27 | Get-GitHubLabel -Owner Mary -RepositoryName WebApps
28 |
29 | .EXAMPLE
30 | # Retrieve only the label 'Label1' from the repository Mary/WebApps:
31 | Get-GitHubLabel -Owner Mary -RepositoryName WebApps -Name Label1
32 |
33 | #>
34 | [CmdletBinding()]
35 | [OutputType('PSGitHub.Label')]
36 | param (
37 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
38 | [Alias('User')]
39 | [string] $Owner,
40 |
41 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
42 | [ValidateNotNullOrEmpty()]
43 | [ValidatePattern('^[\w-\.]+$')]
44 | [Alias('Repository')]
45 | [string] $RepositoryName,
46 |
47 | [ValidateRange(1, [int]::MaxValue)]
48 | [int] $Page,
49 |
50 | [string] $Name,
51 |
52 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
53 | # Defaults to "https://api.github.com"
54 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
55 | [Security.SecureString] $Token = (Get-GitHubToken)
56 | )
57 |
58 | $uri = 'repos/{0}/{1}/labels' -f $Owner, $RepositoryName
59 |
60 | if ($Name) {
61 | $uri += ("/{0}" -f $Name)
62 | }
63 |
64 | $queryParams = @{ }
65 | if ($Page) {
66 | $queryParams.page = $Page
67 | }
68 |
69 | $apiCall = @{
70 | Headers = @{
71 | Accept = 'application/vnd.github.symmetra-preview+json'
72 | }
73 | Body = $queryParams
74 | Method = 'Get'
75 | Uri = $uri
76 | Token = $Token
77 | BaseUri = $BaseUri
78 | }
79 |
80 | Invoke-GitHubApi @apiCall | ForEach-Object { $_ } | ForEach-Object {
81 | $_.PSTypeNames.Insert(0, 'PSGitHub.Label')
82 | $_
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubLicense.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubLicense {
2 | <#
3 | .SYNOPSIS
4 | this cmdlet the the licenses that github provide
5 |
6 | .DESCRIPTION
7 | this cmdlet uses github preview api: licenses, please read https://developer.github.com/v3/licenses/ for more detail
8 |
9 | .PARAMETER LicenseId
10 | the identifier of a licenses, this is provided by GitHub and not universal
11 | This is also called 'key' sometimes
12 |
13 | .EXAMPLE
14 | PS C:\> Get-GitHubLicense
15 | Get all the licenses that github provided
16 |
17 | .EXAMPLE
18 | PS C:\> Get-GitHubLicense mit
19 | Get the information about mit license
20 |
21 | #>
22 | [CmdletBinding()]
23 | [OutputType('PSGitHub.License')]
24 | param(
25 | [Parameter(Position = 0)]
26 | [string] $LicenseId,
27 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
28 | # Defaults to "https://api.github.com"
29 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
30 | [Security.SecureString] $Token = (Get-GitHubToken)
31 | )
32 |
33 | process {
34 | if (-Not ($LicenseId)) {
35 | $uri = 'licenses'
36 | } else {
37 | $uri = 'licenses/{0}' -f $LicenseId
38 | }
39 |
40 | $headers = @{
41 | Accept = 'application/vnd.github.drax-preview+json'
42 | }
43 | Invoke-GitHubApi -Method get -Uri $uri -Headers $headers -BaseUri $BaseUri -Token $Token | ForEach-Object { $_ } | ForEach-Object {
44 | $_.PSTypeNames.Insert(0, 'PSGitHub.License')
45 | $_
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubMilestone.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubMilestone {
2 | <#
3 | .Synopsis
4 | Gets GitHub milestones.
5 |
6 | .Parameter Owner
7 | The GitHub username of the account or organization that owns the GitHub repository specified in the -RepositoryName parameter.
8 |
9 | .Parameter Repository
10 | Required. The name of the GitHub repository that is owned by the -Owner parameter.
11 |
12 | .Parameter Number
13 | The number of the milestone that you want to retrieve.
14 |
15 | .Example
16 | ### Get a specific milestone, based on the milestone's number.
17 | Get-GitHubMilestone -Milestone 1;
18 |
19 | .Example
20 | ### Get a list of milestone for the specified repository
21 | Get-GitHubMilestone -Owner pcgeek86 -RepositoryName PSGitHub;
22 |
23 | .Link
24 | https://trevorsullivan.net
25 | https://developer.github.com/v3/issues
26 | #>
27 | [CmdletBinding(DefaultParameterSetName = 'FindMilestones')]
28 | [OutputType('PSGitHub.Milestone')]
29 | param (
30 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
31 | [Alias('User')]
32 | [string] $Owner,
33 |
34 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
35 | [ValidateNotNullOrEmpty()]
36 | [ValidatePattern('^[\w-\.]+$')]
37 | [Alias('Repository')]
38 | [string] $RepositoryName,
39 |
40 | [Parameter(ParameterSetName = 'SpecificMilestone', Mandatory)]
41 | [int] $Number,
42 |
43 | [Parameter(ParameterSetName = 'FindMilestones')]
44 | [ValidateSet('Open', 'Closed', 'All')]
45 | [string] $State,
46 |
47 | [Parameter(ParameterSetName = 'FindMilestones')]
48 | [ValidateSet('DueDate', 'Completeness')]
49 | [string] $Sort,
50 |
51 | [Parameter(ParameterSetName = 'FindMilestones')]
52 | [ValidateSet('Ascending', 'Descending')]
53 | [string] $Direction,
54 |
55 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
56 | # Defaults to "https://api.github.com"
57 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
58 | [Security.SecureString] $Token = (Get-GitHubToken)
59 | )
60 |
61 | process {
62 | $queryParams = @{ };
63 | if ($Sort) {
64 | $queryParams.sort = ($Sort -creplace '([a-z])([A-Z])', '$1_$2').ToLower(); # PascalCase to snake_case
65 | }
66 | if ($State) {
67 | $queryParams.state = $State.ToLower();
68 | }
69 | if ($Direction) {
70 | $queryParams.direction = ($Direction -replace 'ending$', '').ToLower();
71 | }
72 | $Uri = if ($Number) {
73 | 'repos/{0}/{1}/milestones/{2}' -f $Owner, $RepositoryName, $Number;
74 | } else {
75 | 'repos/{0}/{1}/milestones' -f $Owner, $RepositoryName;
76 | }
77 |
78 | Invoke-GitHubApi -Method GET $Uri -Body $queryParams -BaseUri $BaseUri -Token $Token | ForEach-Object { $_ } | ForEach-Object {
79 | $_.PSTypeNames.Insert(0, 'PSGitHub.Milestone')
80 | $_.Creator.PSTypeNames.Insert(0, 'PSGitHub.User')
81 | $_
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubOrganization.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubOrganization {
2 | [OutputType('PSGitHub.Organization')]
3 | [CmdletBinding(DefaultParameterSetName = 'All')]
4 | param (
5 | # Gets the org a specific user is part of.
6 | [Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'User')]
7 | [string] $Username,
8 |
9 | # Gets the org with a specific name.
10 | [Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'Org')]
11 | [string] $OrganizationName,
12 |
13 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
14 | # Defaults to "https://api.github.com"
15 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
16 | [Security.SecureString] $Token
17 | )
18 |
19 | $url = if ($Username) {
20 | "users/$Username/orgs"
21 | } elseif ($OrganizationName) {
22 | "orgs/$OrganizationName"
23 | } else {
24 | "organizations"
25 | }
26 |
27 | Invoke-GitHubApi $url -BaseUri $BaseUri -Token $Token | ForEach-Object { $_ } | ForEach-Object {
28 | $_.PSTypeNames.Insert(0, 'PSGitHub.Organization')
29 | $_
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubRateLimit.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubRateLimit {
2 | [OutputType('PSGitHub.RateLimit')]
3 | [CmdletBinding()]
4 | param (
5 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
6 | # Defaults to "https://api.github.com"
7 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
8 | [Security.SecureString] $Token
9 | )
10 |
11 | Invoke-GitHubApi 'rate_limit' -BaseUri $BaseUri -Token $Token | ForEach-Object {
12 | $_.PSTypeNames.Insert(0, 'PSGitHub.RateLimit')
13 | foreach ($resourceName in $_.Resources.PSObject.Properties.Name) {
14 | $resource = $_.Resources.$resourceName
15 | $resource.Reset = [System.DateTimeOffset]::FromUnixTimeSeconds($resource.Reset).DateTime
16 | $resource.PSTypeNames.Insert(0, 'PSGitHub.RateLimitResource')
17 | }
18 | $_.Resources.PSTypeNames.Insert(0, 'PSGitHub.RateLimitResources')
19 | $_
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubTeam.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubTeam {
2 | <#
3 | .SYNOPSIS
4 | Gets a GitHub team
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Team')]
8 | param(
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [string] $OrganizationName,
11 |
12 | [Parameter(ValueFromPipelineByPropertyName)]
13 | [string] $Slug,
14 |
15 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
16 | # Defaults to "https://api.github.com"
17 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
18 | [Security.SecureString] $Token
19 | )
20 |
21 | process {
22 | $url = "orgs/$OrganizationName/teams"
23 | if ($Slug) {
24 | $url += "/$Slug"
25 | }
26 | Invoke-GitHubApi $url -BaseUri $BaseUri -Token $Token |
27 | ForEach-Object { $_ } |
28 | ForEach-Object {
29 | $_.PSTypeNames.Insert(0, 'PSGitHub.Team')
30 | if ($_.Organization) {
31 | $_.Organization.PSTypeNames.Insert(0, 'PSGitHub.Organization')
32 | }
33 | $_
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubTeamMember.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubTeamMember {
2 | <#
3 | .SYNOPSIS
4 | Gets members of a GitHub team.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.User')]
8 | param(
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [string] $TeamId,
11 |
12 | [ValidateSet('member', 'maintainer', 'all')]
13 | [string] $Role,
14 |
15 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
16 | # Defaults to "https://api.github.com"
17 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
18 | [Security.SecureString] $Token
19 | )
20 |
21 | process {
22 | $params = @{ }
23 | if ($Role) {
24 | $params.role = $Role
25 | }
26 | Invoke-GitHubApi "teams/$TeamId/members" -Body $params -BaseUri $BaseUri -Token $Token |
27 | ForEach-Object { $_ } |
28 | ForEach-Object {
29 | $_.PSTypeNames.Insert(0, 'PSGitHub.Team')
30 | $_
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Functions/Public/Get-GitHubUser.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubUser {
2 | [OutputType('PSGitHub.User')]
3 | [CmdletBinding()]
4 | param (
5 | # Gets a specific user by username.
6 | # If not given, returns the authenticated user of the token.
7 | [Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'SpecificUser')]
8 | [string] $Username = '',
9 |
10 | [Parameter(ParameterSetName = 'ListAllUsers')]
11 | [switch] $All,
12 |
13 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
14 | # Defaults to "https://api.github.com"
15 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
16 | [Security.SecureString] $Token = (Get-GitHubToken)
17 | )
18 |
19 | switch ($PSCmdlet.ParameterSetName) {
20 | 'SpecificUser' {
21 | $url = if ($Username -ne '') {
22 | "users/$Username"
23 | } else {
24 | "user"
25 | }
26 |
27 | $url = 'users/{0}' -f $Username
28 | break
29 | }
30 | 'ListAllUsers' {
31 | $url = 'users'
32 | break
33 | }
34 | }
35 |
36 | Invoke-GitHubApi $url -BaseUri $BaseUri -Token $Token | ForEach-Object {
37 | $_.PSTypeNames.Insert(0, 'PSGitHub.User')
38 | $_
39 | }
40 | }
41 |
42 | Export-ModuleMember -Alias (
43 | New-Alias -Name Get-GitHubAuthenticatedUser -Value Get-GitHubUser -PassThru
44 | )
45 |
--------------------------------------------------------------------------------
/Functions/Public/Issues/Find-GitHubIssue.ps1:
--------------------------------------------------------------------------------
1 | function Find-GitHubIssue {
2 | <#
3 | .SYNOPSIS
4 | Searches GitHub issues and pull requests by a search query.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Issue')]
8 | param(
9 | [Parameter(Mandatory, Position = 0)]
10 | [string] $Query,
11 |
12 | [ValidateSet('stars', 'forks', 'help-wanted-issues', 'updated')]
13 | [string] $Sort,
14 |
15 | [ValidateSet('asc', 'desc')]
16 | [Alias('Direction')]
17 | [string] $Order,
18 |
19 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
20 | # Defaults to "https://api.github.com"
21 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
22 | [Security.SecureString] $Token = (Get-GitHubToken)
23 | )
24 |
25 | process {
26 | $params = @{
27 | q = $Query
28 | sort = $Sort
29 | order = $Order
30 | }
31 | Invoke-GitHubApi 'search/issues' -Body $params -BaseUri $BaseUri -Token $Token |
32 | ForEach-Object { $_.items } |
33 | ForEach-Object {
34 | $_.PSTypeNames.Insert(0, 'PSGitHub.Issue')
35 | if ($null -ne $_.PSObject.Properties['pull_request']) {
36 | $_.PSTypeNames.Insert(0, 'PSGitHub.PullRequest')
37 | }
38 | foreach ($label in $_.Labels) {
39 | $label.PSTypeNames.Insert(0, 'PSGitHub.Label')
40 | }
41 | $_
42 | }
43 | }
44 | }
45 |
46 | Export-ModuleMember -Alias @(
47 | (New-Alias -Name Search-GitHubIssues -Value Find-GitHubIssue -PassThru),
48 | (New-Alias -Name Find-GitHubPullRequest -Value Find-GitHubIssue -PassThru),
49 | (New-Alias -Name Search-GitHubPullRequests -Value Find-GitHubIssue -PassThru)
50 | )
51 |
--------------------------------------------------------------------------------
/Functions/Public/Issues/Get-GitHubIssueTimeline.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubIssueTimeline {
2 | [CmdletBinding(SupportsShouldProcess)]
3 | [OutputType('PSGitHub.Event')]
4 | param (
5 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
6 | [Alias('User')]
7 | [string] $Owner,
8 |
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [ValidateNotNullOrEmpty()]
11 | [ValidatePattern('^[\w-\.]+$')]
12 | [Alias('Repository')]
13 | [string] $RepositoryName,
14 |
15 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
16 | [int] $Number,
17 |
18 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
19 | # Defaults to "https://api.github.com"
20 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
21 | [Security.SecureString] $Token
22 | )
23 |
24 | process {
25 | Invoke-GitHubApi "repos/$Owner/$RepositoryName/issues/$Number/timeline" `
26 | -Accept 'application/vnd.github.mockingbird-preview', 'application/vnd.github.starfox-preview+json' `
27 | -BaseUri $BaseUri `
28 | -Token $Token |
29 | ForEach-Object { $_ } |
30 | ForEach-Object {
31 | $_.PSTypeNames.Insert(0, 'PSGitHub.Event')
32 | if ($_.Actor) {
33 | $_.Actor.PSTypeNames.Insert(0, 'PSGitHub.User')
34 | }
35 | if ($_.Event -in 'labeled', 'unlabeled') {
36 | $_.Label.PSTypeNames.Insert(0, 'PSGitHub.Label')
37 | }
38 | if ($_.Event -eq 'cross-referenced') {
39 | $_.Source.Issue.PSTypeNames.Insert(0, 'PSGitHub.Issue')
40 | if ($_.Source.Issue.pull_request) {
41 | $_.Source.Issue.PSTypeNames.Insert(0, 'PSGitHub.PullRequest')
42 | }
43 | }
44 | $_
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Functions/Public/Issues/New-GitHubIssue.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubIssue {
2 | <#
3 | .Synopsis
4 | Creates a new GitHub issue.
5 |
6 | .Parameter Title
7 | Required. The title of the new GitHub issue that will be created. This field doesn't support Markdown.
8 |
9 | .Parameter Body
10 | Optional. Defines the body text, using Markdown, for the GitHub issue. Most people probably won't like you
11 | if you don't specify a body, so the recommendation would be to specify one.
12 |
13 | .Parameter Owner
14 | The GitHub username of the account or organization that owns the GitHub repository specified in the -RepositoryName parameter.
15 |
16 | .Parameter Repository
17 | Required. The name of the GitHub repository that is owned by the -Owner parameter, where the new GitHub issue will be
18 | created.
19 |
20 | .Parameter Assignee
21 | Optional. The GitHub username of the individual who the new issues will be assigned to.
22 |
23 | .Parameter Labels
24 | Optional. An array of strings that indicate the labels that will be assigned to this GitHub issue upon creation.
25 |
26 | .Link
27 | https://trevorsullivan.net
28 | https://developer.github.com/v3/issues
29 | #>
30 | [CmdletBinding()]
31 | [OutputType('PSGitHub.Issue')]
32 | param (
33 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
34 | [Alias('User')]
35 | [string] $Owner,
36 |
37 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
38 | [ValidateNotNullOrEmpty()]
39 | [ValidatePattern('^[\w-\.]+$')]
40 | [Alias('Repository')]
41 | [string] $RepositoryName,
42 |
43 | [Parameter(Mandatory)]
44 | [string] $Title,
45 |
46 | [string] $Body,
47 | [string[]] $Assignees,
48 | [string[]] $Labels,
49 |
50 | # The title of the milestone to associate this issue with. Optional.
51 | [AllowNull()]
52 | $MilestoneTitle,
53 |
54 | # The number of the milestone to associate this issue with. Optional.
55 | [AllowNull()]
56 | $MilestoneNumber,
57 |
58 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
59 | # Defaults to "https://api.github.com"
60 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
61 | [Security.SecureString] $Token = (Get-GitHubToken)
62 | )
63 |
64 | ### Build the core message body -- we'll add more properties soon
65 | $ApiBody = @{
66 | title = $Title;
67 | };
68 |
69 | ### Add an issue body to the message payload (optional)
70 | if ($Body) { $ApiBody.body = $Body }
71 |
72 | if ($Assignees) { $ApiBody.assignees = $Assignees }
73 |
74 | ### Add array of labels to the issue message body
75 | if ($Labels) { $ApiBody.labels = $Labels }
76 |
77 | ### Add the milestone to the issue message body
78 | if ($MilestoneName) {
79 | $MilestoneNumber = Get-GitHubMilestone | Where-Object { $_.Title -eq $MilestoneTitle } | ForEach-Object { $_.Number }
80 | if (-not $MilestoneNumber) {
81 | Write-Error "Milestone `"$($MilestoneTitle)`" does not exist"
82 | return
83 | }
84 | }
85 | if ($MilestoneNumber) { $ApiBody.milestone = $MilestoneNumber }
86 |
87 | ### Set up the API call
88 | $ApiCall = @{
89 | Body = $ApiBody | ConvertTo-Json
90 | Uri = 'repos/{0}/{1}/issues' -f $Owner, $RepositoryName;
91 | Method = 'Post';
92 | Token = $Token
93 | BaseUri = $BaseUri
94 | }
95 |
96 | ### Invoke the GitHub REST method
97 | Invoke-GitHubApi @ApiCall | ForEach-Object {
98 | $_.PSTypeNames.Insert(0, 'PSGitHub.Issue')
99 | $_.User.PSTypeNames.Insert(0, 'PSGitHub.User')
100 | foreach ($label in $_.Labels) {
101 | $label.PSTypeNames.Insert(0, 'PSGitHub.Label')
102 | }
103 | $_
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/Functions/Public/New-GitHubComment.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubComment {
2 | <#
3 | .SYNOPSIS
4 | Creates a comment on a GitHub issue.
5 |
6 | .PARAMETER Owner
7 | The GitHub username of the account or organization that owns the GitHub repository
8 | specified in the -RepositoryName parameter.
9 |
10 | .PARAMETER Repository
11 | The name of the GitHub repository containing the issue to which the comment
12 | will be added.
13 |
14 | .PARAMETER Number
15 | The number of the issue to which the comment will be added.
16 |
17 | .PARAMETER Body
18 | The text of the comment.
19 |
20 | .EXAMPLE
21 | # Add a multiline comment containing Markdown to an issue:
22 |
23 | $body = @"
24 | Things to consider:
25 | - A thing
26 | - Another thing
27 | "@
28 | New-GitHubComment -Owner Mary -RepositoryName WebApps -Number 42 -Body $body
29 |
30 | #>
31 | [CmdletBinding()]
32 | param (
33 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
34 | [Alias('User')]
35 | [string] $Owner,
36 |
37 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
38 | [ValidateNotNullOrEmpty()]
39 | [ValidatePattern('^[\w-\.]+$')]
40 | [string] $RepositoryName,
41 |
42 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
43 | [ValidateRange(1, [int]::MaxValue)]
44 | [int] $Number,
45 |
46 | [Parameter(Mandatory)]
47 | [string] $Body,
48 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
49 | # Defaults to "https://api.github.com"
50 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
51 | [Security.SecureString] $Token = (Get-GitHubToken)
52 | )
53 |
54 | $uri = 'repos/{0}/{1}/issues/{2}/comments' -f $Owner, $RepositoryName, $Number
55 |
56 | $apiBody = @{
57 | body = $Body
58 | } | ConvertTo-Json
59 |
60 | $apiCall = @{
61 | Method = 'Post';
62 | Uri = $uri;
63 | Body = $apiBody;
64 | Token = $Token
65 | BaseUri = $BaseUri
66 | }
67 |
68 | Invoke-GitHubApi @apiCall | ForEach-Object {
69 | $_.PSTypeNames.Insert(0, 'PSGitHub.Comment')
70 | $_.User.PSTypeNames.Insert(0, 'PSGitHub.User')
71 | $_
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Functions/Public/New-GitHubMilestone.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubMilestone {
2 | <#
3 | .Synopsis
4 | Creates a new GitHub milestone.
5 |
6 | .Parameter Owner
7 | The GitHub username of the account or organization that owns the GitHub repository specified in the -RepositoryName parameter.
8 |
9 | .Parameter Repository
10 | Required. The name of the GitHub repository that is owned by the -Owner parameter, where the new GitHub milestone will be
11 | created.
12 | #>
13 | [CmdletBinding(DefaultParameterSetName = 'FindMilestones', SupportsShouldProcess)]
14 | [OutputType('PSGitHub.Milestone')]
15 | param (
16 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
17 | [Alias('User')]
18 | [Alias('Organization')]
19 | [string] $Owner,
20 |
21 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
22 | [ValidateNotNullOrEmpty()]
23 | [ValidatePattern('^[\w-_\.]+$')]
24 | [Alias('Repository')]
25 | [string] $RepositoryName,
26 |
27 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
28 | [ValidateNotNullOrEmpty()]
29 | [string] $Title,
30 |
31 | [Parameter(ValueFromPipelineByPropertyName)]
32 | [string] $Description,
33 |
34 | [Parameter(ValueFromPipelineByPropertyName)]
35 | [ValidateSet('open', 'closed')]
36 | [string] $State = 'open',
37 |
38 | [Parameter(ValueFromPipelineByPropertyName)]
39 | [AllowNull()]
40 | [DateTime] $DueOn,
41 |
42 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
43 | # Defaults to "https://api.github.com"
44 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
45 | [Security.SecureString] $Token
46 | )
47 |
48 | process {
49 | $body = @{
50 | title = $Title
51 | state = $State
52 | description = $Description
53 | due_on = $DueOn.ToString('yyyy-MM-dd')
54 | }
55 |
56 | $shouldProcessCaption = 'Creating new GitHub milestone'
57 | $shouldProcessDescription = "Creating the GitHub milestone `e[1m$Title`e[0m in the repository `e[1m$Owner/$RepositoryName`e[0m."
58 | $shouldProcessWarning = "Do you want to create the GitHub milestone `e[1m$Title`e[0m in the repository `e[1m$Owner/$RepositoryName`e[0m?"
59 |
60 | if ($PSCmdlet.ShouldProcess($shouldProcessDescription, $shouldProcessWarning, $shouldProcessCaption)) {
61 |
62 | Invoke-GitHubApi -Method POST "repos/$Owner/$RepositoryName/milestones" -Body ($body | ConvertTo-Json) -BaseUri $BaseUri -Token $Token | ForEach-Object {
63 | $_.PSTypeNames.Insert(0, 'PSGitHub.Milestone')
64 | $_.Creator.PSTypeNames.Insert(0, 'PSGitHub.User')
65 | if ($null -ne $_.DueOn) {
66 | $_.DueOn = Get-Date -Date $_.DueOn -DisplayHint Date
67 | }
68 | $_
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Functions/Public/New-GitHubReview.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubReview {
2 | <#
3 | .SYNOPSIS
4 | Creates a review for the given pull request.
5 | #>
6 | [CmdletBinding(DefaultParameterSetName = 'PENDING')]
7 | [OutputType('PSGitHub.Review')]
8 | param(
9 | # Number of the pull request
10 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
11 | [ValidateRange(1, [int]::MaxValue)]
12 | [int] $Number,
13 |
14 | # The owner of the target repository
15 | [Parameter(ValueFromPipelineByPropertyName)]
16 | [ValidatePattern('^[\w-\.]+$')] # safety check to make sure no owner/repo slug (with slash) was passed
17 | [string] $Owner = (Get-GitHubUser -Token $Token).login, # This doesn't work for org repos.
18 |
19 | # The name of the target repository
20 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
21 | [ValidateNotNullOrEmpty()]
22 | [ValidatePattern('^[\w-\.]+$')]
23 | [Alias('Repository')]
24 | [string] $RepositoryName,
25 |
26 | # The SHA of the commit that needs a review. Not using the latest commit
27 | # SHA may render your review comment outdated if a subsequent commit
28 | # modifies the line you specify as the position. Defaults to the most
29 | # recent commit in the pull request when you do not specify a value.
30 | [string] $CommitId,
31 |
32 | [Parameter(Mandatory, ParameterSetName = 'REQUEST_CHANGES')]
33 | [switch] $RequestChanges,
34 |
35 | [Parameter(Mandatory, ParameterSetName = 'APPROVE')]
36 | [switch] $Approve,
37 |
38 | [Parameter(Mandatory, ParameterSetName = 'COMMENT')]
39 | [switch] $Comment,
40 |
41 | # Required when using REQUEST_CHANGES or COMMENT for the event
42 | # parameter. The body text of the pull request review.
43 | [Parameter(Position = 0, ParameterSetName = 'COMMENT')]
44 | [Parameter(Position = 0, ParameterSetName = 'APPROVE')]
45 | [Parameter(Position = 0, Mandatory, ParameterSetName = 'REQUEST_CHANGES')]
46 | [string] $Body,
47 |
48 | # Array of objects or hashtables with string path, int position and
49 | # string body fields.
50 | [ValidateNotNull()]
51 | [array] $Comments,
52 |
53 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
54 | # Defaults to "https://api.github.com"
55 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
56 | [Security.SecureString] $Token
57 | )
58 |
59 | process {
60 | $Comments = @($Comments | Where-Object { $_ } | ForEach-Object {
61 | [PSCustomObject]@{
62 | path = [string]$_.Path
63 | position = [int]$_.Position
64 | body = [string]$_.Body
65 | }
66 | })
67 | $apiBody = @{
68 | event = $PSCmdlet.ParameterSetName
69 | comments = $Comments
70 | }
71 | if ($CommitId) {
72 | $apiBody.commit_id = $CommitId
73 | }
74 |
75 | Invoke-GithubApi -Method POST "repos/$Owner/$RepositoryName/pulls/$Number/reviews" `
76 | -Body ($apiBody | ConvertTo-Json) `
77 | -BaseUri $BaseUri `
78 | -Token $Token |
79 | ForEach-Object {
80 | $_.PSTypeNames.Insert(0, 'PSGitHub.Review')
81 | $_.User.PSTypeNames.Insert(0, 'PSGitHub.User')
82 | $_
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Functions/Public/New-GitHubReviewRequest.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubReviewRequest {
2 | <#
3 | .SYNOPSIS
4 | Requests review from one or more users for a pull request.
5 | .INPUTS
6 | PSGitHub.PullRequest
7 | #>
8 | [CmdletBinding()]
9 | [OutputType('PSGitHub.PullRequest')]
10 | param(
11 | # Number of the pull request
12 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
13 | [ValidateRange(1, [int]::MaxValue)]
14 | [int] $Number,
15 |
16 | # The owner of the target repository
17 | [Parameter(ValueFromPipelineByPropertyName)]
18 | [ValidatePattern('^[\w-\.]+$')] # safety check to make sure no owner/repo slug (with slash) was passed
19 | [string] $Owner = (Get-GitHubUser -Token $Token).login, # This doesn't work for org repos.
20 |
21 | # The name of the target repository
22 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
23 | [ValidateNotNullOrEmpty()]
24 | [ValidatePattern('^[\w-\.]+$')]
25 | [Alias('Repository')]
26 | [string] $RepositoryName,
27 |
28 | # User logins that will be requested.
29 | [string[]] $Reviewers = @(),
30 |
31 | # Team slugs that will be requested.
32 | # The team must exist in the organization of the repository.
33 | [string[]] $TeamReviewers = @(),
34 |
35 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
36 | # Defaults to "https://api.github.com"
37 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
38 | [Security.SecureString] $Token = (Get-GitHubToken)
39 | )
40 |
41 | process {
42 | $body = @{
43 | reviewers = $Reviewers
44 | team_reviewers = $TeamReviewers
45 | }
46 |
47 | Invoke-GithubApi -Method POST "repos/$Owner/$RepositoryName/pulls/$Number/requested_reviewers" `
48 | -Body ($body | ConvertTo-Json) `
49 | -BaseUri $BaseUri `
50 | -Token $Token |
51 | ForEach-Object {
52 | $_.PSTypeNames.Insert(0, 'PSGitHub.Issue') # every PR is an issue
53 | $_.PSTypeNames.Insert(0, 'PSGitHub.PullRequest')
54 | $_.User.PSTypeNames.Insert(0, 'PSGitHub.User')
55 | $_.Head.PSTypeNames.Insert(0, 'PSGitHub.Commit')
56 | $_.Base.PSTypeNames.Insert(0, 'PSGitHub.Commit')
57 | foreach ($label in $_.Labels) {
58 | $label.PSTypeNames.Insert(0, 'PSGitHub.Label')
59 | }
60 | foreach ($assignee in $_.Assignees) {
61 | $assignee.PSTypeNames.Insert(0, 'PSGitHub.User')
62 | }
63 | foreach ($reviewer in $_.RequestedReviewers) {
64 | $reviewer.PSTypeNames.Insert(0, 'PSGitHub.User')
65 | }
66 | $_
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Functions/Public/Projects/Add-GitHubBetaProjectItem.ps1:
--------------------------------------------------------------------------------
1 | $betaProjectItemFragment = Get-Content -Raw "$PSScriptRoot/BetaProjectItemFragment.graphql"
2 |
3 | function Add-GitHubBetaProjectItem {
4 | <#
5 | .SYNOPSIS
6 | EXPERIMENTAL: Adds an item to a GitHub project (Beta).
7 | #>
8 | [CmdletBinding()]
9 | param(
10 | [Parameter(Mandatory)]
11 | [ValidateNotNullOrEmpty()]
12 | [string] $ProjectNodeId,
13 |
14 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
15 | [Alias('node_id', 'id')]
16 | [ValidateNotNullOrEmpty()]
17 | [string] $ContentNodeId,
18 |
19 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
20 | # Defaults to "https://api.github.com"
21 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
22 | [Security.SecureString] $Token
23 | )
24 |
25 | process {
26 | $result = Invoke-GitHubGraphQlApi `
27 | -Headers @{ 'GraphQL-Features' = 'projects_next_graphql' } `
28 | -Query ('mutation($input: AddProjectNextItemInput!) {
29 | addProjectNextItem(input: $input) {
30 | projectNextItem {
31 | ...BetaProjectItemFragment
32 | }
33 | }
34 | }
35 | ' + $betaProjectItemFragment) `
36 | -Variables @{
37 | input = @{
38 | projectId = $ProjectNodeId
39 | contentId = $ContentNodeId
40 | }
41 | } `
42 | -BaseUri $BaseUri `
43 | -Token $Token
44 |
45 | $item = $result.addProjectNextItem.projectNextItem
46 |
47 | Add-Member -InputObject $item -NotePropertyName 'ProjectNodeId' -NotePropertyValue $ProjectNodeId
48 |
49 | # Expose fields as ergonomic name=>value hashtable
50 | $fieldHashTable = [ordered]@{ }
51 | foreach ($fieldValue in $item.fieldValues.nodes) {
52 | $fieldValue.projectField.settings = $fieldValue.projectField.settings | ConvertFrom-Json
53 | $fieldSettings = $fieldValue.projectField.settings
54 | $value = if ($fieldSettings -and $fieldSettings.PSObject.Properties['options']) {
55 | ($fieldSettings.options | Where-Object { $_.id -eq $fieldValue.value }).Name
56 | } else {
57 | $fieldValue.value
58 | }
59 | $fieldHashTable[$fieldValue.projectField.name] = $value
60 | }
61 | Add-Member -InputObject $item -NotePropertyName 'Fields' -NotePropertyValue $fieldHashTable
62 |
63 | if ($item.content) {
64 | $item.content.labels = $item.content.labels.nodes
65 | $item.content.assignees = $item.content.assignees.nodes
66 | }
67 |
68 | $item
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Functions/Public/Projects/BetaProjectItemFragment.graphql:
--------------------------------------------------------------------------------
1 | fragment BetaProjectItemFragment on ProjectNextItem {
2 | id
3 | title
4 | createdAt
5 | updatedAt
6 | creator {
7 | login
8 | }
9 | fieldValues(first: 20) {
10 | nodes {
11 | value
12 | projectField {
13 | name
14 | settings
15 | }
16 | }
17 | }
18 | project {
19 | id
20 | number
21 | title
22 | }
23 | content {
24 | ... on Issue {
25 | __typename
26 | number
27 | state
28 | title
29 | body
30 | bodyText
31 | author {
32 | ... on Actor {
33 | login
34 | avatarUrl
35 | }
36 | }
37 | milestone {
38 | number
39 | title
40 | dueOn
41 | url
42 | }
43 | }
44 | ... on PullRequest {
45 | __typename
46 | number
47 | state
48 | title
49 | body
50 | bodyText
51 | author {
52 | ... on Actor {
53 | login
54 | avatarUrl
55 | }
56 | }
57 | milestone {
58 | number
59 | title
60 | dueOn
61 | url
62 | }
63 | }
64 | ... on Labelable {
65 | labels(first: 20) {
66 | nodes {
67 | name
68 | }
69 | }
70 | }
71 | ... on Assignable {
72 | assignees(first: 20) {
73 | nodes {
74 | login
75 | name
76 | }
77 | }
78 | }
79 | ... on RepositoryNode {
80 | repository {
81 | owner {
82 | login
83 | }
84 | name
85 | nameWithOwner
86 | }
87 | }
88 | ... on UniformResourceLocatable {
89 | url
90 | }
91 | ... on Node {
92 | id
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/Functions/Public/Projects/Get-GitHubProject.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubProject {
2 | <#
3 | .SYNOPSIS
4 | Gets a GitHub project.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.Project')]
8 | param(
9 | [Parameter(Mandatory, ParameterSetName = 'Owner', ValueFromPipelineByPropertyName)]
10 | [Alias('OrganizationName')]
11 | [string] $Owner,
12 |
13 | [Parameter(ParameterSetName = 'Owner', ValueFromPipelineByPropertyName)]
14 | [string] $RepositoryName,
15 |
16 | [Parameter(Mandatory, ParameterSetName = 'Id', ValueFromPipelineByPropertyName)]
17 | [int] $ProjectId,
18 |
19 | [string] $Name,
20 |
21 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
22 | # Defaults to "https://api.github.com"
23 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
24 | [Security.SecureString] $Token
25 | )
26 |
27 | process {
28 | $url = switch ($PSCmdlet.ParameterSetName) {
29 | 'Owner' {
30 | if ($RepositoryName) {
31 | "repos/$Owner/$RepositoryName/projects"
32 | } else {
33 | "orgs/$Owner/projects"
34 | }
35 | }
36 | 'Id' {
37 | "projects/$ProjectId"
38 | }
39 | }
40 | Invoke-GitHubApi $url -Accept 'application/vnd.github.inertia-preview+json' -BaseUri $BaseUri -Token $Token |
41 | ForEach-Object { $_ } |
42 | Where-Object { -not $Name -or $_.Name -like $Name } |
43 | ForEach-Object {
44 | $_.PSTypeNames.Insert(0, 'PSGitHub.Project')
45 | $_.Creator.PSTypeNames.Insert(0, 'PSGitHub.User')
46 | $_
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Functions/Public/Projects/Get-GitHubProjectCard.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubProjectCard {
2 | <#
3 | .SYNOPSIS
4 | Gets the cards for a column of a GitHub project.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.ProjectCard')]
8 | param(
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [int] $ColumnId,
11 |
12 | [Parameter(ValueFromPipelineByPropertyName)]
13 | [int] $CardId,
14 |
15 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
16 | # Defaults to "https://api.github.com"
17 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
18 | [Security.SecureString] $Token
19 | )
20 |
21 | process {
22 | $url = if ($CardId) {
23 | "projects/columns/cards/$CardId"
24 | } else {
25 | "projects/columns/$ColumnId/cards"
26 | }
27 | Invoke-GitHubApi $url -Accept 'application/vnd.github.inertia-preview+json' -BaseUri $BaseUri -Token $Token |
28 | ForEach-Object { $_ } |
29 | ForEach-Object {
30 | $_.PSTypeNames.Insert(0, 'PSGitHub.ProjectCard')
31 | $_
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Functions/Public/Projects/Get-GitHubProjectColumn.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubProjectColumn {
2 | <#
3 | .SYNOPSIS
4 | Gets the columns for a GitHub project.
5 | #>
6 | [CmdletBinding()]
7 | [OutputType('PSGitHub.ProjectColumn')]
8 | param(
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [int] $ProjectId,
11 |
12 | [int] $ColumnId,
13 |
14 | [string] $Name,
15 |
16 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17 | # Defaults to "https://api.github.com"
18 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19 | [Security.SecureString] $Token
20 | )
21 |
22 | process {
23 | $url = if ($Id) {
24 | "projects/columns/$ColumnId"
25 | } else {
26 | "projects/$ProjectId/columns"
27 | }
28 | Invoke-GitHubApi $url -Accept 'application/vnd.github.inertia-preview+json' -BaseUri $BaseUri -Token $Token |
29 | ForEach-Object { $_ } |
30 | Where-Object { -not $Name -or $_.Name -like $Name } |
31 | ForEach-Object {
32 | $_.PSTypeNames.Insert(0, 'PSGitHub.ProjectColumn')
33 | $_
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Functions/Public/Projects/Move-GitHubProjectCard.ps1:
--------------------------------------------------------------------------------
1 | function Move-GitHubProjectCard {
2 | <#
3 | .SYNOPSIS
4 | Moves a GitHub project card inside and in between columns.
5 | #>
6 | [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'Top')]
7 | param(
8 | # The ID of the card to move
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [int] $CardId,
11 |
12 | # Move the card to the top of the column
13 | [Parameter(Mandatory, ParameterSetName = 'top')]
14 | [switch] $Top,
15 |
16 | # Move the card to the bottom of the column
17 | [Parameter(Mandatory, ParameterSetName = 'bottom')]
18 | [switch] $Bottom,
19 |
20 | # ID of a card to place the card after
21 | [Parameter(Mandatory, ParameterSetName = 'after')]
22 | [int] $After,
23 |
24 | # Optional: Column to move the card to
25 | [int] $ColumnId,
26 |
27 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
28 | # Defaults to "https://api.github.com"
29 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
30 | [Security.SecureString] $Token
31 | )
32 |
33 | process {
34 | $body = @{
35 | position = switch ($PSCmdlet.ParameterSetName) {
36 | 'Top' { 'top' }
37 | 'Bottom' { 'bottom' }
38 | 'After' { "after:$After" }
39 | }
40 | }
41 | if ($ColumnId) {
42 | $body.column_id = $ColumnId
43 | }
44 |
45 | if ($Top -or $Bottom) {
46 | $position = "to the $($PSCmdlet.ParameterSetName)"
47 | if ($ColumnId) {
48 | $position += " of column $ColumnId"
49 | }
50 | } else {
51 | $position = "after card $After"
52 | if ($ColumnId) {
53 | $position = "to column $ColumnId $position"
54 | }
55 | }
56 |
57 | $shouldProcessCaption = "Moving GitHub project card"
58 | $shouldProcessDescription = "Moving GitHub project card $CardId $position"
59 | $shouldProcessWarning = "Do you want to move GitHub project card $CardId $position?"
60 |
61 | if ($PSCmdlet.ShouldProcess($shouldProcessDescription, $shouldProcessWarning, $shouldProcessCaption)) {
62 | Invoke-GitHubApi -Method POST "projects/columns/cards/$CardId/moves" -Accept 'application/vnd.github.inertia-preview+json' -Body ($body | ConvertTo-Json) -BaseUri $BaseUri -Token $Token | Out-Null
63 | Write-Information "Moved GitHub project card $CardId $position"
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Functions/Public/Projects/New-GitHubProjectCard.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubProjectCard {
2 | <#
3 | .SYNOPSIS
4 | Creates a new GitHub project card.
5 | .INPUTS
6 | PSGitHub.Issue. You can pipe in an issue from e.g. Get-GitHubIssue.
7 | PSGitHub.PullRequest. You can pipe in an issue from e.g. Get-GitHubPullRequest.
8 | PSGitHub.ProjectColumn. You can pipe in a column from Get-GitHubProjectColumn.
9 | #>
10 | [CmdletBinding(SupportsShouldProcess)]
11 | [OutputType('PSGitHub.ProjectCard')]
12 | param(
13 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
14 | [int] $ColumnId,
15 |
16 | # Creates a simple card with a note.
17 | [Parameter(Mandatory, ParameterSetName = 'Note')]
18 | [string] $Note,
19 |
20 | # Creates a card for an issue or pull request.
21 | [Parameter(Mandatory, ParameterSetName = 'ContentType', ValueFromPipelineByPropertyName)]
22 | [ValidateSet('Issue', 'PullRequest')]
23 | [Alias('Type')]
24 | [string] $ContentType,
25 |
26 | # The ID of the issue or pull request to create the card for.
27 | [Parameter(Mandatory, ParameterSetName = 'ContentType', ValueFromPipelineByPropertyName)]
28 | [Alias('Id')]
29 | [int] $ContentId,
30 |
31 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
32 | # Defaults to "https://api.github.com"
33 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
34 | [Security.SecureString] $Token
35 | )
36 |
37 | process {
38 | $body = switch ($PSCmdlet.ParameterSetName) {
39 | 'Note' {
40 | @{
41 | note = $Note
42 | }
43 | }
44 | 'ContentType' {
45 | @{
46 | content_type = $ContentType
47 | content_id = $ContentId
48 | }
49 | }
50 | }
51 | $headers = @{
52 | Accept = 'application/vnd.github.inertia-preview+json'
53 | }
54 |
55 | $shouldProcessCaption = "Creating new GitHub project card"
56 | $shouldProcessDescription = "Creating new GitHub project card in column $ColumnId"
57 | $shouldProcessWarning = "Do you want to create a new GitHub project card in column $ColumnId?"
58 |
59 | if ($PSCmdlet.ShouldProcess($shouldProcessDescription, $shouldProcessWarning, $shouldProcessCaption)) {
60 | Invoke-GitHubApi -Method POST "projects/columns/$ColumnId/cards" -Headers $headers -Body ($body | ConvertTo-Json) -BaseUri $BaseUri -Token $Token |
61 | ForEach-Object {
62 | $_.PSTypeNames.Insert(0, 'PSGitHub.ProjectCard')
63 | $_.Creator.PSTypeNames.Insert(0, 'PSGitHub.User')
64 | $_
65 | }
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/Functions/Public/Pulls/Get-GitHubPullRequestFile.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubPullRequestFile {
2 | <#
3 | .SYNOPSIS
4 | This cmdlet lists the files for a pull request.
5 |
6 | .DESCRIPTION
7 | Lists pull requests for given owner, repository and filter parameters.
8 |
9 | .INPUTS
10 | s PSGitHub.PullRequest. You can pipe the output of Get-GitHubPullRequest
11 | LibGit2Sharp.Repository. You can pipe the output of PowerGit's Get-GitRepository
12 | LibGit2Sharp.Branch. You can pipe the output of PowerGit's Get-GitBranch or Get-GitHead
13 | LibGit2Sharp.Commit. You can pipe the output of PowerGit's Get-GitCommit
14 | #>
15 | [CmdletBinding()]
16 | [OutputType('PSGitHub.PullRequestFile')]
17 | param(
18 | # The owner of the target repository
19 | [Parameter(ValueFromPipelineByPropertyName)]
20 | [string] $Owner,
21 |
22 | # The name of the target repository
23 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
24 | [ValidateNotNullOrEmpty()]
25 | [ValidatePattern('^[\w-\.]+$')]
26 | [Alias('Repository')]
27 | [ValidateNotNullOrEmpty()]
28 | [string] $RepositoryName,
29 |
30 | # Number of the pull request
31 | [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'Number')]
32 | [ValidateRange(1, [int]::MaxValue)]
33 | [int] $Number,
34 |
35 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
36 | # Defaults to "https://api.github.com"
37 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
38 | [Security.SecureString] $Token
39 | )
40 |
41 | process {
42 | Invoke-GitHubApi "repos/$Owner/$RepositoryName/pulls/$Number/files" -BaseUri $BaseUri -Token $Token | ForEach-Object { $_ } | ForEach-Object {
43 | $_.PSTypeNames.Insert(0, 'PSGitHub.PullRequestFile')
44 | $_
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Functions/Public/Releases/Get-GitHubRelease.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubRelease {
2 | <#
3 | .SYNOPSIS
4 | This command gets the github
5 |
6 | .DESCRIPTION
7 | This command gets the id of a release via the following 3 Parameter:
8 | 1. id -- the release id
9 | 2. tag name -- the release tag name
10 | 3. latest -- the latest release
11 |
12 | .PARAMETER Owner
13 | the Owner of the repo to retrieve the releases.
14 |
15 | .PARAMETER Repository
16 | The repo that you want to retrieve the release
17 |
18 | .PARAMETER Id
19 | the Id of the release to retrieve, optional
20 | (cannot be used together with 'Latest' or 'TagName')
21 |
22 | .PARAMETER TagName
23 | the TagName of the release to retrieve, optional
24 | (cannot be used together with 'Id' or 'Latest')
25 |
26 | .PARAMETER Latest
27 | when this switch is on, the command will retrieve the latest release, optional
28 | (cannot be used together with 'Id' or 'TagName')
29 |
30 | .EXAMPLE
31 | # get the latest release from soimort/you-get
32 | C:\PS> Get-GithubRelease -Owner soimort -RepositoryName you-get -Latest
33 |
34 | # get all the release from PowerShell/vscode-powershell
35 | C:\PS> Get-GithubRelease -Owner Powershell -RepositoryName vscode-powershell
36 |
37 | # get the version 'v0.1.0' release from PowerShell/vscode-powershell
38 | C:\PS> Get-GithubRelease -Owner Powershell -RepositoryName vscode-powershell -TagName v0.1.0
39 |
40 | # get the release with id 2161075 from PowerShell/vscode-powershell
41 | C:\PS> Get-GithubRelease -Owner Powershell -RepositoryName vscode-powershell -Id 2161075
42 |
43 | .NOTES
44 | you cannot use parameter 'Id', 'Latest', 'TagName' together
45 |
46 | #>
47 | [CmdletBinding(DefaultParameterSetName = '__AllParameterSets')]
48 | [OutputType('PSGitHub.Release')]
49 | param(
50 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
51 | [String] $Owner,
52 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
53 | [ValidateNotNullOrEmpty()]
54 | [ValidatePattern('^[\w-\.]+$')]
55 | [Alias('Repository')]
56 | [string] $RepositoryName,
57 | [Parameter(ParameterSetName = 'Id')]
58 | [String] $Id,
59 | [Parameter(ParameterSetName = 'TagName')]
60 | [String] $TagName,
61 | [Parameter(ParameterSetName = 'Latest')]
62 | [Switch] $Latest,
63 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
64 | # Defaults to "https://api.github.com"
65 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
66 | [Security.SecureString] $Token = (Get-GitHubToken)
67 | )
68 |
69 | process {
70 | # set the URL
71 | $uri = switch ($PSCmdlet.ParameterSetName) {
72 | 'Id' { "repos/$Owner/$RepositoryName/releases/$Id" }
73 | 'TagName' { "repos/$Owner/$RepositoryName/releases/tags/$TagName" }
74 | 'Latest' { "repos/$Owner/$RepositoryName/releases/latest" }
75 | Default { "repos/$Owner/$RepositoryName/releases" }
76 | }
77 |
78 | # set the API call parameter
79 | $apiCall = @{
80 | Uri = $uri
81 | Method = 'Get'
82 | Token = $Token
83 | BaseUri = $BaseUri
84 | }
85 | # invoke the rest api call
86 | Invoke-GitHubApi @apiCall | ForEach-Object { $_ } | ForEach-Object {
87 | $_.PSTypeNames.Insert(0, 'PSGitHub.Release')
88 | $_.Author.PSTypeNames.Insert(0, 'PSGitHub.User')
89 | $_
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/Functions/Public/Releases/Get-GitHubReleaseAsset.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubReleaseAsset {
2 | <#
3 | .SYNOPSIS
4 | This command gets the github
5 |
6 | .DESCRIPTION
7 | This command gets the assets of a release via the following 2 Parameter:
8 | 1. releaseid -- the release id
9 | 2. id -- the asset id
10 |
11 | .PARAMETER Owner
12 | the Owner of the repo to retrieve the releases, defaults to the current authenticated user.
13 |
14 | .PARAMETER Repository
15 | The repo that you want to retrieve the release
16 |
17 | .PARAMETER ReleaseId
18 | the Id of the release to retrieve, optional
19 | (cannot be used together with 'Id')
20 |
21 | .PARAMETER Id
22 | the Id of the asset to retrieve, optional
23 | (cannot be used together with 'ReleaseId')
24 |
25 | .EXAMPLE
26 | # get the all assets for a release from PowerShell/vscode-powershell
27 | C:\PS> Get-GithubReleaseAsset -Owner Powershell -RepositoryName vscode-powershell -ReleaseId 6808217
28 |
29 | # get a specific asset
30 | C:\PS> Get-GithubReleaseAsset -Owner Powershell -RepositoryName vscode-powershell -Id 4163551
31 |
32 | .NOTES
33 | you cannot use parameter 'ReleaseId', 'Id' together
34 |
35 | #>
36 | [CmdletBinding()]
37 | param(
38 | [Parameter(Mandatory, ParameterSetName = 'Release', ValueFromPipeline)]
39 | [ValidateScript( { $null -ne $_.PSObject.Properties['assets_url'] })]
40 | [object] $Release,
41 |
42 | [Parameter(Mandatory, ParameterSetName = 'Id')]
43 | [Parameter(Mandatory, ParameterSetName = 'ReleaseId')]
44 | [String] $Owner,
45 |
46 | [Parameter(Mandatory, ParameterSetName = 'Id')]
47 | [Parameter(Mandatory, ParameterSetName = 'ReleaseId')]
48 | [ValidateNotNullOrEmpty()]
49 | [ValidatePattern('^[\w-\.]+$')]
50 | [Alias('Repository')]
51 | [string] $RepositoryName,
52 |
53 | [Parameter(Mandatory, ParameterSetName = 'Id')]
54 | [String] $Id,
55 |
56 | [Parameter(Mandatory, ParameterSetName = 'ReleaseId')]
57 | [String] $ReleaseId,
58 |
59 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
60 | # Defaults to "https://api.github.com"
61 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
62 | [Security.SecureString] $Token = (Get-GitHubToken)
63 | )
64 |
65 | process {
66 | # set the rest method
67 | $uri = switch ($PSCmdlet.ParameterSetName) {
68 | 'Release' { $Release.assets_url }
69 | 'ReleaseId' { "repos/$Owner/$RepositoryName/releases/$ReleaseId/assets" }
70 | 'Id' { "repos/$Owner/$RepositoryName/releases/assets/$Id" }
71 | Default { "repos/$Owner/$RepositoryName/releases/$ReleaseId/assets" }
72 | }
73 |
74 | # set the API call parameter
75 | $apiCall = @{
76 | Uri = $uri
77 | Method = 'Get'
78 | Token = $Token
79 | BaseUri = $BaseUri
80 | }
81 | Invoke-GitHubApi @apiCall
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Functions/Public/Releases/New-GitHubReleaseAsset.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubReleaseAsset {
2 | <#
3 | .SYNOPSIS
4 | Create a new GitHub release asset
5 |
6 | .DESCRIPTION
7 | Create a GitHub release asset for a given release
8 |
9 | .PARAMETER Owner
10 | Optional, the Owner of the repo that you want to upload the release asset for, default to the authenticated user
11 |
12 | .PARAMETER Repository
13 | Mandatory, the name of the Repository that you want to upload the release asset for.
14 |
15 | .PARAMETER ReleaseId
16 | Mandatory, the name of the tag of this release
17 |
18 | .PARAMETER Path
19 | Optional, specify the branch of the tag, default to the default branch (usually `master`)
20 |
21 | .PARAMETER ContentType
22 | Mandatory, the content type of the file.
23 |
24 | .INPUTS
25 | PSGitHub.Release
26 |
27 | .EXAMPLE
28 | Create a new release asset in release with id 1234567 of project 'test-organization/test-repo'
29 | PS C:\> New-GitHubRelease -Owner 'test-organization' -RepositoryName 'test-repo' -ReleaseId 1234567 -Path .\myasset.zip
30 |
31 | .NOTES
32 | 1. This cmdlet will not help you create a tag, you need to use git to do that.
33 | 2. This cmdlet will not help you to upload assets to the release, you need to use other functions to do that
34 | 3. If both `Branch` and `CommitSHA` are provided, the release will be created based on the `Branch`
35 | 4. If a relase with the same tag already exist and it is not a draft, this method will fail
36 |
37 | #>
38 | [CmdletBinding()]
39 | param(
40 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
41 | # Defaults to "https://api.github.com"
42 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
43 | [Security.SecureString] $Token = (Get-GitHubToken),
44 |
45 | [Parameter(ParameterSetName = 'NoUploadUrl', ValueFromPipelineByPropertyName)]
46 | [string] $Owner = (Get-GitHubUser -Token $Token -BaseUri $BaseUri).login,
47 |
48 | [Parameter(Mandatory, ParameterSetName = 'NoUploadUrl', ValueFromPipelineByPropertyName)]
49 | [ValidateNotNullOrEmpty()]
50 | [ValidatePattern('^[\w-\.]+$')]
51 | [Alias('Repository')]
52 | [string] $RepositoryName,
53 |
54 | [Parameter(Mandatory, ParameterSetName = 'NoUploadUrl')]
55 | [string] $ReleaseId,
56 |
57 | [Parameter(Mandatory, DontShow, ParameterSetName = 'UploadUrl', ValueFromPipelineByPropertyName)]
58 | [string] $UploadUrl,
59 |
60 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
61 | [Alias('FullName')]
62 | [string] $Path,
63 |
64 | [string] $Label,
65 |
66 | [string] $ContentType = 'application/zip' # TODO this is not a good default.
67 | )
68 |
69 | process {
70 | $name = (Get-Item -Path $Path -Force -ErrorAction Stop).Name
71 | if (-not $Label) {
72 | $Label = $name
73 | }
74 |
75 | # Get upload URL from release object
76 | if (-not $UploadUrl) {
77 | $UploadUrl = (Get-GitHubRelease -Owner $Owner -RepositoryName $RepositoryName -Id $ReleaseId -Token $Token -BaseUri $BaseUri -ErrorAction Stop).UploadUrl
78 | }
79 |
80 | Write-Verbose "Expanding upload URL $UploadUrl with name=`"$name`" and label=`"$label`""
81 |
82 | # Expand query parameters in upload URL
83 | if ($UploadUrl -match '\{\?(.+)\}') {
84 | $vars = @{ name = $name; label = $Label }
85 | $allowedVars = $Matches[1] -split ','
86 | $query = '?' + (($allowedVars | ForEach-Object {
87 | if ($vars.ContainsKey($_)) {
88 | $value = [System.Web.HttpUtility]::UrlEncode($vars[$_])
89 | "$_=$value"
90 | }
91 | }) -join '&')
92 | $UploadUrl = $UploadUrl -replace '\{\?.+\}', $query
93 | }
94 |
95 | $apiCall = @{
96 | InFile = $Path
97 | Headers = @{'Content-Type' = $ContentType }
98 | Method = 'post'
99 | Uri = $UploadUrl
100 | Token = $Token
101 | BaseUri = $BaseUri
102 | }
103 |
104 | Invoke-GitHubApi @apiCall
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/Functions/Public/Releases/Remove-GitHubReleaseAsset.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubReleaseAsset {
2 | <#
3 | .Synopsis
4 | This command deletes a GitHub release asset.
5 |
6 | .Description
7 | This command is responsible for deleting a GitHub release asset
8 |
9 | .PARAMETER Owner
10 | Optional, the Owner of the repo that you want to create the release on, default to the authenticated user
11 |
12 | .PARAMETER Repository
13 | Mandatory, the name of the Repository that you want to create the release on.
14 |
15 | .Parameter Id
16 | The Id of the Gist to remove or remove files from.
17 |
18 | .Example
19 | PS C:\> Remove-GitHubRelease -Owner 'test-organization' -RepositoryName 'test-repo' -Id 1234567
20 |
21 | #>
22 |
23 | [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)]
24 | [OutputType([Void])]
25 | Param (
26 | [Parameter(Mandatory)]
27 | [string] $Owner,
28 |
29 | [Parameter(Mandatory)]
30 | [ValidateNotNullOrEmpty()]
31 | [ValidatePattern('^[\w-\.]+$')]
32 | [Alias('Repository')]
33 | [string] $RepositoryName,
34 |
35 | [Parameter(Mandatory)]
36 | [String] $Id,
37 |
38 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
39 | # Defaults to "https://api.github.com"
40 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
41 | [Security.SecureString] $Token = (Get-GitHubToken)
42 | )
43 |
44 | Process {
45 | $ApiCall = @{
46 | Uri = "repos/$Owner/$RepositoryName/releases/assets/$Id"
47 | Method = 'delete'
48 | Token = $Token
49 | BaseUri = $BaseUri
50 | }
51 | }
52 |
53 | end {
54 | if ($PSCmdlet.ShouldProcess($Id)) {
55 | Invoke-GitHubApi @ApiCall
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Functions/Public/Remove-GitHubAssignee.ps1:
--------------------------------------------------------------------------------
1 | function Add-GitHubAssignee {
2 | [CmdletBinding(SupportsShouldProcess)]
3 | [OutputType('PSGitHub.Issue')]
4 | param (
5 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
6 | [Alias('User')]
7 | [string] $Owner,
8 |
9 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
10 | [ValidateNotNullOrEmpty()]
11 | [ValidatePattern('^[\w-\.]+$')]
12 | [Alias('Repository')]
13 | [string] $RepositoryName,
14 |
15 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
16 | [int] $Number,
17 |
18 | # Usernames who will be added as assignees to the issue.
19 | [string[]] $Assignees,
20 |
21 | # Team slugs whose members will be added as assignees to the issue (in addition to Assignees).
22 | [string[]] $TeamAssignees,
23 |
24 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
25 | # Defaults to "https://api.github.com"
26 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
27 | [Security.SecureString] $Token
28 | )
29 |
30 | process {
31 | if ($TeamAssignees) {
32 | $Assignees += $TeamAssignees |
33 | ForEach-Object { Get-GitHubTeam -OrganizationName $Owner -Slug $_ -Token $Token } |
34 | Get-GitHubTeamMember -Token $Token |
35 | ForEach-Object { $_.Login }
36 | }
37 |
38 | $body = @{
39 | assignees = $Assignees
40 | }
41 |
42 | $shouldProcessCaption = "Adding assignee to GitHub issue"
43 | $shouldProcessDescription = "Adding $($Assignees.Count) assignees to GitHub issue `e[1m#$Number`e[0m in repository `e[1m$Owner/$RepositoryName`e[0m."
44 | $shouldProcessWarning = "Do you want to add $($Assignees.Count) assignees the GitHub issue `e[1m#$Number`e[0m in repository `e[1m$Owner/$RepositoryName`e[0m?"
45 |
46 | if ($PSCmdlet.ShouldProcess($shouldProcessDescription, $shouldProcessWarning, $shouldProcessCaption)) {
47 | Invoke-GitHubApi -Method DELETE "repos/$Owner/$RepositoryName/issues/$Number/assignees" `
48 | -Body ($body | ConvertTo-Json) `
49 | -BaseUri $BaseUri `
50 | -Token $Token |
51 | ForEach-Object {
52 | $_.PSTypeNames.Insert(0, 'PSGitHub.Issue')
53 | $_.User.PSTypeNames.Insert(0, 'PSGitHub.User')
54 | foreach ($label in $_.Labels) {
55 | $label.PSTypeNames.Insert(0, 'PSGitHub.Label')
56 | }
57 | foreach ($assignee in $_.Assignees) {
58 | $assignee.PSTypeNames.Insert(0, 'PSGitHub.User')
59 | }
60 | $_
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Functions/Public/Remove-GitHubGist.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubGist {
2 | <#
3 | .Synopsis
4 | This command deletes a GitHub Gist code snippet.
5 |
6 | .Description
7 | This command is responsible for deleting GitHub Gist code snippets or files.
8 |
9 | .Parameter Id
10 | The Id of the Gist to remove or remove files from.
11 |
12 | .Parameter FileName
13 | If this parameter is used, only specified files will be removed from the gist.
14 |
15 | .Example
16 | PS C:\> Get-GitHubGist -Id 265482c76983daedc83f | Remove-GitHubGist -Confirm:$false
17 |
18 |
19 | .Example
20 | PS C:\> Remove-GitHubGist -Id 265482c76983daedc83f -FileName File1.ps1, File2.ps1 -Confirm:$false
21 |
22 |
23 | .Notes
24 | This cmdlet will compliment Get-GitHubGist nicely.
25 |
26 | .Link
27 | https://trevorsullivan.net
28 | http://dotps1.github.io
29 | https://developer.github.com/v3/gists
30 | #>
31 |
32 | [CmdletBinding(ConfirmImpact = 'High', SupportsShouldProcess = $true)]
33 | [OutputType([Void])]
34 | Param (
35 | [Parameter(Mandatory, ValueFromPipelineByPropertyName = $true)]
36 | [String[]] $Id,
37 | [String[]]$FileName,
38 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
39 | # Defaults to "https://api.github.com"
40 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
41 | [Security.SecureString] $Token = (Get-GitHubToken)
42 | )
43 |
44 | Process {
45 | foreach ($item in $Id) {
46 | if ($PSCmdlet.ShouldProcess($item)) {
47 | if ($null -ne $FileName) {
48 | [HashTable]$body = @{
49 | files = @{ }
50 | }
51 | foreach ($file in $FileName) {
52 | $body.files.Add($file, $null)
53 | }
54 | $uri = 'PATCH'
55 | } else {
56 | $body = $null
57 | $uri = 'DELETE'
58 | }
59 |
60 | $ApiCall = @{
61 | Body = ConvertTo-Json -InputObject $body
62 | Uri = 'gists/{0}' -f $item
63 | Method = $uri
64 | Token = $Token
65 | }
66 |
67 | Invoke-GitHubApi @ApiCall
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Functions/Public/Remove-GitHubGitRef.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubGitRef {
2 | <#
3 | .SYNOPSIS
4 | Deletes a GitHub git ref (a branch, a commit, etc.)
5 |
6 | .EXAMPLE
7 | Remove-GitHubGitRef -Owner foo -RepositoryName bar -Ref heads/my-branch
8 | #>
9 | [CmdletBinding(SupportsShouldProcess)]
10 | param (
11 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
12 | [string] $Owner,
13 |
14 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
15 | [ValidateNotNullOrEmpty()]
16 | [ValidatePattern('^[\w-\.]+$')]
17 | [Alias('Repository')]
18 | [string] $RepositoryName,
19 |
20 | [Parameter(Mandatory, ParameterSetName = 'Ref')]
21 | [ValidateNotNullOrEmpty()]
22 | [string] $Ref,
23 |
24 | [Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName = 'HeadRef')]
25 | [ValidateNotNullOrEmpty()]
26 | [Alias('FriendlyName')]
27 | [string] $HeadRef,
28 |
29 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
30 | # Defaults to "https://api.github.com"
31 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
32 | [Security.SecureString] $Token = (Get-GitHubToken)
33 | )
34 | process {
35 | if ($HeadRef) {
36 | $Ref = "heads/$HeadRef"
37 | }
38 |
39 | $shouldProcessCaption = "Deleting GitHub git ref"
40 | $shouldProcessDescription = "Deleting the GitHub git ref `e[1m$Name`e[0m in the repository `e[1m$Owner/$RepositoryName`e[0m."
41 | $shouldProcessWarning = "Do you want to create the GitHub git ref `e[1m$Name`e[0m in the repository `e[1m$Owner/$RepositoryName`e[0m?"
42 |
43 | if ($PSCmdlet.ShouldProcess($shouldProcessDescription, $shouldProcessWarning, $shouldProcessCaption)) {
44 | Invoke-GitHubApi -Method DELETE "repos/$Owner/$RepositoryName/git/refs/$Ref" -BaseUri $BaseUri -Token $Token
45 | Write-Information "Removed GitHub git ref `e[1m$Ref`e[0m"
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Functions/Public/Remove-GitHubLabel.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubLabel {
2 | <#
3 | .SYNOPSIS
4 | Remove a GitHub label.
5 |
6 | .DESCRIPTION
7 | This command removes a GitHub label from the specified repository using
8 | the authenticated user.
9 |
10 | .PARAMETER Owner
11 | The GitHub username of the account or organization that owns the GitHub
12 | repository specified in the parameter -RepositoryName parameter.
13 |
14 | .PARAMETER Repository
15 | The name of the GitHub repository, that is owned by the GitHub username
16 | specified by parameter -Owner.
17 |
18 | .PARAMETER Name
19 | The name of the label to remove from the GitHub repository specified by the
20 | parameters -Owner and -RepositoryName.
21 |
22 | .PARAMETER Force
23 | Forces the execution without confirmation prompts.
24 |
25 | .EXAMPLE
26 | # date the label name.
27 | Remove-GitHubLabel -Owner Mary -RepositoryName WebApps -Name 'Label1'
28 |
29 | #>
30 | [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
31 | param (
32 | [Parameter(Mandatory, ParameterSetName = 'Repository')]
33 | [Alias('User')]
34 | [string] $Owner,
35 |
36 | [Parameter(Mandatory, ParameterSetName = 'Repository')]
37 | [ValidateNotNullOrEmpty()]
38 | [ValidatePattern('^[\w-\.]+$')]
39 | [Alias('Repository')]
40 | [string] $RepositoryName,
41 |
42 | [Parameter(Mandatory, ParameterSetName = 'Repository')]
43 | [string] $Name,
44 |
45 | [switch] $Force,
46 |
47 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
48 | # Defaults to "https://api.github.com"
49 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
50 | [Security.SecureString] $Token = (Get-GitHubToken)
51 | )
52 |
53 | $shouldProcessCaption = 'Remove an existing GitHub label'
54 | $shouldProcessDescription = 'Removing the GitHub label ''{0}'' in the repository ''{1}/{2}''.' -f $Name, $Owner, $RepositoryName
55 | $shouldProcessWarning = 'Do you want to remove the GitHub label ''{0}'' in the repository ''{1}/{2}''?' -f $Name, $Owner, $RepositoryName
56 |
57 | if ($Force -or $PSCmdlet.ShouldProcess($shouldProcessDescription, $shouldProcessWarning, $shouldProcessCaption)) {
58 | $uri = 'repos/{0}/{1}/labels/{2}' -f $Owner, $RepositoryName, $Name
59 |
60 | $apiCall = @{
61 | Headers = @{
62 | Accept = 'application/vnd.github.symmetra-preview+json'
63 | }
64 | Method = 'Delete'
65 | Uri = $uri
66 | Token = $Token
67 | BaseUri = $BaseUri
68 | }
69 |
70 | # Variable scope ensures that parent session remains unchanged
71 | $ConfirmPreference = 'None'
72 |
73 | Invoke-GitHubApi @apiCall
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Functions/Public/Repositories/Get-GitHubRepository.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubRepository {
2 | <#
3 | .SYNOPSIS
4 | This cmdlet will get the information about a GitHub repo.
5 |
6 | .DESCRIPTION
7 | This cmdlet can get the information for one or more github repos you specify with owner and GitHub repo name
8 | See https://developer.github.com/v3/repos/#get for detail
9 |
10 | .PARAMETER Owner
11 | The owner of the repo, default to be the authenticated user. When used by itself, retrieves the information for all (public - unless the authenticated user is specified) repos for the specified owner.
12 | .PARAMETER Repository
13 | The name of the GitHub repository (not full name)
14 |
15 | .PARAMETER License
16 | When this switch is turned on, you will only get the info about the license of the repository. Can be used only when specifying the Respository Parameter.
17 |
18 | .PARAMETER ReadMe
19 | When this switch is turned on, you will only get the info about the README of the repository. Can be used only when specifying hte Repository Parameter.
20 |
21 | .OUTPUTS
22 | Return a PSCustomObject.
23 | See the return in https://developer.github.com/v3/repos/#get for detail
24 |
25 | .EXAMPLE
26 | PS C:\> Get-GitHubRepository -Owner octocat -RepositoryName Hello-World
27 | the return of this statement is shown in https://developer.github.com/v3/repos/#get
28 |
29 | .EXAMPLE
30 | PS C:\> Get-GitHubRepository
31 | Returns all respositories for the authenticated user
32 |
33 | .EXAMPLE
34 | PS C:\> Get-GitHubRepository -Owner exactmike
35 | Returns all respositories for the specified user
36 |
37 | .EXAMPLE
38 | PS C:\> Get-GitHubRepository -Owner exactmike -RepositoryName OutSpeech -License
39 | Returns the license information for the specified owner's repository
40 |
41 | .EXAMPLE
42 | PS C:\> Get-GitHubRepository -Owner exactmike -RepositoryName OutSpeech -ReadMe
43 | Returns the ReadMe information for the specified owner's repository
44 | #>
45 |
46 | [CmdletBinding()]
47 | [OutputType('PSGitHub.Repository')]
48 | param(
49 | [Parameter(ValueFromPipelineByPropertyName)]
50 | [string] $Owner,
51 |
52 | [Parameter(ValueFromPipelineByPropertyName)]
53 | [ValidateNotNullOrEmpty()]
54 | [ValidatePattern('^[\w-\.]+$')]
55 | [Alias('Repository')]
56 | [string] $RepositoryName,
57 |
58 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
59 | # Defaults to "https://api.github.com"
60 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
61 | [Security.SecureString] $Token = (Get-GitHubToken)
62 | )
63 |
64 | process {
65 | $uri = if ($RepositoryName) {
66 | "repos/$Owner/$RepositoryName"
67 | } elseif ($Owner) {
68 | "users/$Owner/repos"
69 | } else {
70 | 'user/repos'
71 | }
72 | $templatePreview = 'application/vnd.github.baptiste-preview+json'
73 | # expand arrays
74 | Invoke-GitHubApi $uri -Accept $templatePreview -BaseUri $BaseUri -Token $Token |
75 | ForEach-Object { $_ } |
76 | ForEach-Object {
77 | $_.PSTypeNames.Insert(0, 'PSGitHub.Repository')
78 | $_.Owner.PSTypeNames.Insert(0, 'PSGitHub.User')
79 | if ($_.License) {
80 | $_.License.PSTypeNames.Insert(0, 'PSGitHub.License')
81 | }
82 | $_
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Functions/Public/Repositories/Get-GitHubRepositoryLanguages.ps1:
--------------------------------------------------------------------------------
1 | function Get-GitHubRepositoryLanguages {
2 | <#
3 | .Synopsis
4 | Retrieves the languages that make up the code in the GitHub repository.
5 | #>
6 | [CmdletBinding()]
7 | param (
8 | [Parameter(Mandatory = $true)]
9 | [string] $Owner,
10 | [Parameter(Mandatory = $true)]
11 | [string] $RepositoryName
12 | )
13 |
14 | $Uri = 'repos/{0}/{1}/languages' -f $Owner, $RepositoryName
15 | Invoke-GitHubApi -Uri $Uri
16 | }
--------------------------------------------------------------------------------
/Functions/Public/Repositories/New-GitHubRepository.ps1:
--------------------------------------------------------------------------------
1 | function New-GitHubRepository {
2 | <#
3 | .Synopsis
4 | Creates a new GitHub Repository, with the specified name.
5 |
6 | .Parameter Organization
7 | The name of the organization in that the GitHub repository will be created. If not given, will create a repository for the current user.
8 |
9 | .Parameter Name
10 | The name of the new GitHub repository that will be created. This is the only required parameter in order to instantiate a new GitHub Repository. The other parameters are optional, but recommended.
11 |
12 | .Parameter Description
13 | A user-friendly "plain English" description to help people understand the purpose of the GitHub repository.
14 |
15 | .Parameter Homepage
16 | The home page for the product or service that the project belongs to (eg. https://mycoolsoftwareproject.com).
17 |
18 | .Parameter IncludeReadme
19 | Indicates that a stub README.MD Markdown file should be generated when the repository is created.
20 |
21 | .Parameter DisableIssues
22 | If this parameter is present, then the GitHub Issue Tracker will be disable for the new GitHub Repository.
23 |
24 | .Parameter Private
25 | If this switch parameter is present, then the repository will be created as a Private (non-public) repository.
26 |
27 | .Notes
28 | Created by Trevor Sullivan
29 | #>
30 | [CmdletBinding(DefaultParameterSetName = 'User')]
31 | [OutputType('PSGitHub.Repository')]
32 | param (
33 | [Parameter(Mandatory, ParameterSetName = 'Org')]
34 | [string] $Organization,
35 |
36 | # The id of the team that will be granted access to this repository.
37 | # This is only valid when creating a repository in an organization.
38 | [Parameter(ParameterSetName = 'Org')]
39 | [int] $TeamId,
40 |
41 | [Parameter(Mandatory, Position = 0)]
42 | [string] $Name,
43 |
44 | [string] $Description,
45 | [string] $Homepage,
46 | [switch] $Private,
47 | [switch] $IncludeReadme,
48 | [string] $GitIgnoreTemplate,
49 | [string] $LicenseTemplate,
50 | [switch] $DisableIssues,
51 | [switch] $DisableProjects,
52 | [switch] $DisableWiki,
53 | [switch] $DisableSquashMerge,
54 | [switch] $DisableMergeCommit,
55 | [switch] $DisableRebaseMerge,
56 | [switch] $DeleteBranchOnMerge,
57 | [switch] $IsTemplate,
58 |
59 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
60 | # Defaults to "https://api.github.com"
61 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
62 | [Security.SecureString] $Token = (Get-GitHubToken)
63 | )
64 |
65 | $Body = @{
66 | name = $Name
67 | description = $Description
68 | homepage = $Homepage
69 | private = [bool]$Private
70 | auto_init = [bool]$IncludeReadme
71 | gitignore_template = $GitIgnoreTemplate
72 | license_template = $LicenseTemplate
73 | has_wiki = -not $DisableWiki
74 | has_issues = -not $DisableIssues
75 | allow_squash_merge = -not $DisableSquashMerge
76 | allow_merge_commit = -not $DisableMergeCommit
77 | allow_rebase_merge = -not $DisableRebaseMerge
78 | delete_branch_on_merge = [bool]$DeleteBranchOnMerge
79 | is_template = [bool]$IsTemplate
80 | }
81 | if ($DisableProjects) {
82 | $Body.has_projects = -not $DisableProjects
83 | }
84 | if ($TeamId) {
85 | $Body.team_id = $TeamId
86 | }
87 |
88 | $uri = if ($Organization) {
89 | "orgs/$Organization/repos"
90 | } else {
91 | "user/repos"
92 | }
93 | $templatePreview = 'application/vnd.github.baptiste-preview+json'
94 | Invoke-GitHubApi -Method POST $uri -Body ($Body | ConvertTo-Json) -Accept $templatePreview -BaseUri $BaseUri -Token $Token | ForEach-Object {
95 | $_.PSTypeNames.Insert(0, 'PSGitHub.Repository')
96 | $_.Owner.Insert(0, 'PSGitHub.User')
97 | $_
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Functions/Public/Repositories/Remove-GitHubRepository.ps1:
--------------------------------------------------------------------------------
1 | function Remove-GitHubRepository {
2 | <#
3 | .Synopsis
4 | Deletes a GitHub repository, using the specified owner and repository name.
5 |
6 | .Notes
7 | Created by Trevor Sullivan
8 | #>
9 | [CmdletBinding()]
10 | param (
11 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
12 | [string] $Owner,
13 |
14 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
15 | [ValidateNotNullOrEmpty()]
16 | [ValidatePattern('^[\w-\.]+$')]
17 | [Alias('Repository', 'Name')]
18 | [string] $RepositoryName,
19 |
20 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
21 | # Defaults to "https://api.github.com"
22 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
23 | [Security.SecureString] $Token
24 | )
25 |
26 | $uri = 'repos/{0}/{1}' -f $Owner, $Name;
27 | Invoke-GitHubApi -Uri $uri -Method Delete -BaseUri $BaseUri -Token $Token;
28 | }
29 |
--------------------------------------------------------------------------------
/Functions/Public/Save-GitHubGist.ps1:
--------------------------------------------------------------------------------
1 | Function Save-GitHubGist {
2 | <#
3 | .Synopsis
4 | This command saves all files from a gist.
5 |
6 | .Description
7 | This command is responsible for saving each file that is associated with a gist to the local machine.
8 |
9 | .Parameter Path
10 | Path to create a parent folder named the 'ID' of the Gist, then places all Gist Content files that that directory.
11 |
12 | .Parameter Gist
13 | The Gist object to be saved. Returned from Get-GitHubGist.
14 |
15 | .Example
16 | Get-GitHubGist -Id 62f8f608bdfec5d08552 | Save-GitHubGist
17 |
18 |
19 | Directory: C:\Users\me\Documents\GitHub\Gists\62f8f608bdfec5d08552
20 |
21 |
22 | Mode LastWriteTime Length Name
23 | ---- ------------- ------ ----
24 | -a---- 3/21/2016 3:11 PM 2080 Register-SophosWebIntelligenceService.ps1
25 |
26 | .Notes
27 | This cmdlet will compliment Get-GitHubGist nicely.
28 |
29 | .Link
30 | https://trevorsullivan.net
31 | http://dotps1.github.io
32 | https://developer.github.com/v3/gists/
33 | #>
34 |
35 | [CmdletBinding()]
36 | [OutputType()]
37 | Param (
38 | [String]$Path = "$env:APPDATA\PSGitHub\Gists",
39 | [Parameter(Mandatory, ValueFromPipeline = $true)]
40 | [System.Object[]]$Gist
41 | )
42 |
43 | Process {
44 | foreach ($item in $Gist) {
45 | $directory = New-Item -Path $Path -Name $item.Id -ItemType Directory -Force
46 | foreach ($file in ($item.files.PSObject.Properties.Value)) {
47 | New-Item -Path $directory -Name $file.filename -ItemType File -Value $file.content
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Functions/Public/Set-GitHubToken.ps1:
--------------------------------------------------------------------------------
1 | function Set-GitHubToken {
2 | <#
3 | .Synopsis
4 | Internal function that obtains the username and Personal Access Token from the user.
5 |
6 | .Notes
7 | Created by Trevor Sullivan
8 | #>
9 | [CmdletBinding()]
10 | [Obsolete('Use $PSDefaultParameterValues to set the -Token parameter for all PSGitHub functions')]
11 | param (
12 | )
13 |
14 | Write-Warning 'Set-GitHubToken is deprecated. Use $PSDefaultParameterValues to set the -Token parameter for all PSGitHub functions'
15 |
16 | ### Invoke the GitHub Personal Access Token screen
17 | Start-Process 'https://github.com/settings/tokens'
18 |
19 | ### TODO: Consider using Read-Host to support non-GUI scenarios
20 | $GitHubCredential = Get-Credential -Message 'Please enter your GitHub username and Personal Access Token. Visit https://github.com/settings/tokens to obtain a Personal Access Token.' -UserName '';
21 |
22 | $TokenPath = '{0}\token.json' -f (Split-Path -Path $MyInvocation.MyCommand.Module.Path -Parent);
23 |
24 | @(@{
25 | Username = $GitHubCredential.UserName;
26 | PersonalAccessToken = $GitHubCredential.Password | ConvertFrom-SecureString;
27 | }) | ConvertTo-Json | Out-File -FilePath $TokenPath;
28 | }
29 |
--------------------------------------------------------------------------------
/Functions/Public/Start-GitHubFork.ps1:
--------------------------------------------------------------------------------
1 | function Start-GitHubFork {
2 | <#
3 | .SYNOPSIS
4 | the cmdlet to create a fork.
5 |
6 | .DESCRIPTION
7 | this cmdlet creates a fork of a other's repo in your account, or an organization that you have access to.
8 | Forking is asynchronous.
9 |
10 | .PARAMETER Owner
11 | the owner of the repo that you want to fork, mandatory
12 |
13 | .PARAMETER Repository
14 | the name of the repo that you want to fork, mandatory
15 |
16 | .PARAMETER Organization
17 | the organization you want to fork the upstream repository to, optional
18 | leave this blank if you want to fork to your account
19 |
20 | .EXAMPLE
21 | fork the repo 'pcgeek86/PSGitHub' to my 'test-orgnization'
22 | PS C:\> New-GitHubFork -Owner pcgeek86 -RepositoryName PSGitHub -Organization test-orgnization -verbose
23 |
24 | fork the repo 'pcgeek86/PSGitHub' to my account
25 | PS C:\> New-GitHubFork -Owner pcgeek86 -RepositoryName PSGitHub
26 |
27 | #>
28 | [CmdletBinding()]
29 | [OutputType('PSGitHub.Repository')]
30 | param(
31 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
32 | [string] $Owner,
33 |
34 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
35 | [ValidateNotNullOrEmpty()]
36 | [ValidatePattern('^[\w-\.]+$')]
37 | [Alias('Repository')]
38 | [string] $RepositoryName,
39 |
40 | [string] $Organization,
41 |
42 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
43 | # Defaults to "https://api.github.com"
44 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
45 | [Security.SecureString] $Token
46 | )
47 |
48 | process {
49 | $body = @{ }
50 | if ($organization) {
51 | $body.organization = $organization
52 | }
53 | Invoke-GitHubApi -Method POST "repos/$Owner/$RepositoryName/forks" -Body ($body | ConvertTo-Json) -BaseUri $BaseUri -Token $Token | ForEach-Object {
54 | $_.PSTypeNames.Insert(0, 'PSGitHub.Repository')
55 | $_
56 | }
57 | }
58 | }
59 |
60 | Export-ModuleMember -Alias (
61 | New-Alias -Name New-GitHubFork -Value Start-GitHubFork -PassThru
62 | )
63 |
--------------------------------------------------------------------------------
/Functions/Public/Submit-GitHubReview.ps1:
--------------------------------------------------------------------------------
1 | function Submit-GitHubReview {
2 | <#
3 | .SYNOPSIS
4 | Submits a review for the given pull request.
5 | #>
6 | [CmdletBinding(DefaultParameterSetName = 'COMMENT')]
7 | [OutputType('PSGitHub.Review')]
8 | param(
9 | # Number of the pull request
10 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
11 | [ValidateRange(1, [int]::MaxValue)]
12 | [int] $Number,
13 |
14 | # The owner of the target repository
15 | [Parameter(ValueFromPipelineByPropertyName)]
16 | [ValidatePattern('^[\w-\.]+$')] # safety check to make sure no owner/repo slug (with slash) was passed
17 | [string] $Owner = (Get-GitHubUser -Token $Token).login, # This doesn't work for org repos.
18 |
19 | # The name of the target repository
20 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
21 | [ValidateNotNullOrEmpty()]
22 | [ValidatePattern('^[\w-\.]+$')]
23 | [Alias('Repository')]
24 | [string] $RepositoryName,
25 |
26 | [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
27 | [int] $ReviewId,
28 |
29 | [Parameter(Mandatory, ParameterSetName = 'REQUEST_CHANGES')]
30 | [switch] $RequestChanges,
31 |
32 | [Parameter(Mandatory, ParameterSetName = 'APPROVE')]
33 | [switch] $Approve,
34 |
35 | # Required when using REQUEST_CHANGES or COMMENT for the event
36 | # parameter. The body text of the pull request review.
37 | [Parameter(Position = 0, ParameterSetName = 'COMMENT')]
38 | [Parameter(Position = 0, ParameterSetName = 'APPROVE')]
39 | [Parameter(Position = 0, Mandatory, ParameterSetName = 'REQUEST_CHANGES')]
40 | [string] $Body,
41 |
42 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
43 | # Defaults to "https://api.github.com"
44 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
45 | [Security.SecureString] $Token
46 | )
47 |
48 | process {
49 | $apiBody = @{
50 | event = $PSCmdlet.ParameterSetName
51 | body = $Body
52 | }
53 |
54 | Invoke-GithubApi -Method POST "repos/$Owner/$RepositoryName/pulls/$Number/reviews/$ReviewId/events" `
55 | -Body ($apiBody | ConvertTo-Json) `
56 | -BaseUri $BaseUri `
57 | -Token $Token |
58 | ForEach-Object {
59 | $_.PSTypeNames.Insert(0, 'PSGitHub.Review')
60 | $_.User.PSTypeNames.Insert(0, 'PSGitHub.User')
61 | $_
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Functions/Public/Update-GitHubGist.ps1:
--------------------------------------------------------------------------------
1 | function Update-GitHubGist {
2 | <#
3 | .Synopsis
4 | This command updates a GitHub Gist code snippet.
5 |
6 | .Description
7 | This command is responsible for updating GitHub Gist code snippets.
8 |
9 | .Notes
10 |
11 | .Link
12 | https://trevorsullivan.net
13 | https://developer.github.com/v3/gists
14 | #>
15 | [CmdletBinding()]
16 | param (
17 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
18 | # Defaults to "https://api.github.com"
19 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
20 | [Security.SecureString] $Token = (Get-GitHubToken)
21 | )
22 |
23 | $ApiCall = @{
24 | Body = '';
25 | Uri = '';
26 | Method = '';
27 | Token = $Token
28 | BaseUri = $BaseUri
29 | }
30 |
31 | Invoke-GitHubApi @ApiCall;
32 | }
33 |
34 | Export-ModuleMember -Alias (
35 | New-Alias -Name Set-GitHubGist -Value Update-GitHubGist -PassThru
36 | )
37 |
--------------------------------------------------------------------------------
/Functions/Public/Update-GitHubUser.ps1:
--------------------------------------------------------------------------------
1 | function Update-GitHubUser {
2 | <#
3 | .Synopsis
4 | Updates information for the authenticated user.
5 |
6 | .Example
7 | ### Update the user's company
8 | Update-GitHubUser -Company Microsoft;
9 |
10 | .Example
11 | ### Update the user's location and hireable status
12 | Update-GitHubUser -Hireable $false -Location 'Denver, Colorado'
13 |
14 | .Notes
15 | Created by Trevor Sullivan
16 | #>
17 | [CmdletBinding()]
18 | param (
19 | [string] $Name,
20 | [string] $Email,
21 | [string] $Blog,
22 | [string] $Company,
23 | [string] $Location,
24 |
25 | [Alias('CanHire')]
26 | [bool] $Hireable,
27 |
28 | [string] $Biography,
29 | # Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
30 | # Defaults to "https://api.github.com"
31 | [Uri] $BaseUri = [Uri]::new('https://api.github.com'),
32 | [Security.SecureString] $Token = (Get-GitHubToken)
33 | )
34 |
35 | $body = @{ }
36 | if ($Name) {
37 | $body.name = $Name
38 | }
39 | if ($Email) {
40 | $body.email = $Email
41 | }
42 | if ($Blog) {
43 | $body.blog = $Blog
44 | }
45 | if ($Company) {
46 | $body.company = $Company
47 | }
48 | if ($Location) {
49 | $body.location = $Location
50 | }
51 | if ($Hireable) {
52 | $body.hireable = [bool]$Hireable
53 | }
54 | if ($Biography) {
55 | $body.biography = $Biography
56 | }
57 |
58 | Invoke-GitHubApi -Method PATCH -Uri user -Body ($body | ConvertTo-Json) -BaseUri $BaseUri -Token $Token;
59 | }
60 |
61 | Export-ModuleMember -Alias @(
62 | (New-Alias -Name Set-GitHubAuthenticatedUser -Value Update-GitHubUser -PassThru),
63 | (New-Alias -Name Update-GitHubAuthenticatedUser -Value Update-GitHubUser -PassThru)
64 | )
65 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2016 Trevor Sullivan
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/PSGitHub.psm1:
--------------------------------------------------------------------------------
1 | ### Created by Trevor Sullivan
2 |
3 | Get-ChildItem $PSScriptRoot/Functions -Recurse -File -Include *.ps1 | ForEach-Object {
4 | . $PSItem.FullName
5 | }
6 |
7 | Get-ChildItem $PSScriptRoot/Completers -Recurse -File -Include *.ps1 | ForEach-Object {
8 | . $PSItem.FullName
9 | }
10 |
11 | ### Export all functions
12 | Export-ModuleMember -Function *
13 |
--------------------------------------------------------------------------------
/PSScriptAnalyzerSettings.psd1:
--------------------------------------------------------------------------------
1 | @{
2 | Severity = @('Error', 'Warning', 'Information')
3 | ExcludeRules = @(
4 | 'PSUseShouldProcessForStateChangingFunctions', # TODO: implement ShouldProcess
5 | 'PSUseConsistentIndentation' # broken
6 | )
7 | Rules = @{
8 | PSPlaceOpenBrace = @{
9 | Enable = $true
10 | OnSameLine = $true
11 | NewLineAfter = $true
12 | IgnoreOneLineBlock = $true
13 | }
14 |
15 | PSPlaceCloseBrace = @{
16 | Enable = $true
17 | NewLineAfter = $false
18 | IgnoreOneLineBlock = $true
19 | NoEmptyLineBefore = $true
20 | }
21 |
22 | PSUseConsistentIndentation = @{
23 | Enable = $true
24 | Kind = 'space'
25 | IndentationSize = 4
26 | }
27 |
28 | PSUseConsistentWhitespace = @{
29 | Enable = $true
30 | CheckOpenBrace = $true
31 | CheckOpenParen = $true
32 | CheckOperator = $true
33 | CheckSeparator = $true
34 | }
35 |
36 | PSAlignAssignmentStatement = @{
37 | Enable = $false
38 | }
39 |
40 | PSUseShouldProcessForStateChangingFunctions = @{
41 | Enable = $true
42 | }
43 |
44 | PSUseCorrectCasing = @{
45 | Enable = $true
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Types/CombinedCommitStatus.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.CombinedCommitStatus
4 |
5 |
6 | TotalCount
7 | total_count
8 |
9 |
10 | Status
11 | State
12 |
13 |
14 | PSStandardMembers
15 |
16 |
17 | DefaultDisplayPropertySet
18 |
19 | Sha
20 | State
21 | TotalCount
22 | Statuses
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Types/Comment.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Comment
4 |
5 |
6 | CreatedAt
7 | created_at
8 |
9 |
10 | UpdatedAt
11 | updated_at
12 |
13 |
14 | HtmlUrl
15 | html_url
16 |
17 |
18 | PSStandardMembers
19 |
20 |
21 | DefaultDisplayPropertySet
22 |
23 | User
24 | CreatedAt
25 | Body
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Types/Commit.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Commit
4 |
5 |
6 | PSStandardMembers
7 |
8 |
9 | DefaultDisplayProperty
10 | Sha
11 |
12 |
13 | DefaultDisplayPropertySet
14 |
15 | Sha
16 | Author
17 | Committer
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Types/CommitStatus.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.CommitStatus
4 |
5 |
6 | TargetUrl
7 | target_url
8 |
9 |
10 | CreatedAt
11 | created_at
12 |
13 |
14 | UpdatedAt
15 | updated_at
16 |
17 |
18 | AvatarUrl
19 | avatar_url
20 |
21 |
22 | PSStandardMembers
23 |
24 |
25 | DefaultDisplayPropertySet
26 |
27 | State
28 | Context
29 | Description
30 | TargetUrl
31 | CreatedAt
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Types/Event.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Event
4 |
5 |
6 | CreatedAt
7 | created_at
8 |
9 |
10 | CommitId
11 | commit_id
12 |
13 |
14 | SubmittedAt
15 | submitted_at
16 |
17 |
18 | RequestedReviewer
19 | requested_reviewer
20 |
21 |
22 | PSStandardMembers
23 |
24 |
25 | DefaultDisplayPropertySet
26 |
27 | Event
28 | CreatedAt
29 |
30 |
31 |
32 | DefaultDisplayProperty
33 | Event
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Types/Gist.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Gist
4 |
5 |
6 | CreatedAt
7 | created_at
8 |
9 |
10 | UpdatedAt
11 | updated_at
12 |
13 |
14 | HtmlUrl
15 | html_url
16 |
17 |
18 | PSStandardMembers
19 |
20 |
21 | DefaultDisplayPropertySet
22 |
23 | Description
24 | Owner
25 | Public
26 | CreatedAt
27 | UpdatedAt
28 | HtmlUrl
29 | Files
30 | Comments
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Types/GistFile.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.GistFile
4 |
5 |
6 | RawUrl
7 | raw_url
8 |
9 |
10 | PSStandardMembers
11 |
12 |
13 | DefaultDisplayPropertySet
14 |
15 | Filename
16 | Type
17 | Language
18 | RawUrl
19 | Size
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Types/Label.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Label
4 |
5 |
6 | ToColoredString
7 |
14 |
15 |
16 | ToString
17 |
20 |
21 |
22 | Owner
23 |
24 | if ($this.url -match '/repos/([^/]+)/([^/]+)/labels') {
25 | $Matches[1]
26 | }
27 |
28 |
29 |
30 | RepositoryName
31 |
32 | if ($this.url -match '/repos/([^/]+)/([^/]+)/labels') {
33 | $Matches[2]
34 | }
35 |
36 |
37 |
38 | PSStandardMembers
39 |
40 |
41 | DefaultDisplayPropertySet
42 |
43 | Name
44 | Color
45 | Default
46 | Description
47 |
48 |
49 |
50 | DefaultDisplayProperty
51 | Name
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/Types/License.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.License
4 |
5 |
6 | SpdxId
7 | spdx_id
8 |
9 |
10 | ToString
11 |
12 |
13 |
14 | PSStandardMembers
15 |
16 |
17 | DefaultDisplayPropertySet
18 |
19 | Key
20 | SpdxId
21 |
22 |
23 |
24 | DefaultDisplayProperty
25 | SpdxId
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Types/Milestone.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Milestone
4 |
5 |
6 | Name
7 | title
8 |
9 |
10 | Owner
11 |
12 | if ($this.url -match '/repos/([^/]+)/([^/]+)/milestones') {
13 | $Matches[1]
14 | }
15 |
16 |
17 |
18 | RepositoryName
19 |
20 | if ($this.url -match '/repos/([^/]+)/([^/]+)/milestones') {
21 | $Matches[2]
22 | }
23 |
24 |
25 |
26 | OpenIssues
27 | open_issues
28 |
29 |
30 | ClosedIssues
31 | closed_issues
32 |
33 |
34 | CreatedAt
35 | created_at
36 |
37 |
38 | DueOn
39 | due_on
40 |
41 |
42 | UpdatedAt
43 | updated_at
44 |
45 |
46 | ClosedAt
47 | closed_at
48 |
49 |
50 | HtmlUrl
51 | html_url
52 |
53 |
54 | PSStandardMembers
55 |
56 |
57 | DefaultDisplayPropertySet
58 |
59 | Number
60 | State
61 | Title
62 | OpenIssues
63 | ClosedIssues
64 | DueOn
65 |
66 |
67 |
68 | DefaultDisplayProperty
69 | Title
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/Types/Organization.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Organization
4 |
5 |
6 | OrganizationName
7 | login
8 |
9 |
10 | IsVerified
11 | is_verified
12 |
13 |
14 | HasOrganizationProjects
15 | has_organization_projects
16 |
17 |
18 | HasRepositoryProjects
19 | has_repository_projects
20 |
21 |
22 | PublicRepos
23 | public_repos
24 |
25 |
26 | PublicGists
27 | public_gists
28 |
29 |
30 | CreatedAt
31 | created_at
32 |
33 |
34 | TotalPrivateRepos
35 | total_private_repos
36 |
37 |
38 | OwnedPrivateRepos
39 | owned_private_repos
40 |
41 |
42 | PrivateGists
43 | private_gists
44 |
45 |
46 | DiskUsage
47 | disk_usage
48 |
49 |
50 | BillingEmail
51 | billing_email
52 |
53 |
54 | DefaultRepositorySettings
55 | default_repository_settings
56 |
57 |
58 | MembersCanCreateRepositories
59 | members_can_create_repositories
60 |
61 |
62 | TwoFactorRequirementEnabled
63 | two_factor_requirement_enabled
64 |
65 |
66 | MembersAllowedRepositoryCreationType
67 | members_allowed_repository_creation_type
68 |
69 |
70 | PSStandardMembers
71 |
72 |
73 | DefaultDisplayPropertySet
74 |
75 | Login
76 | Description
77 | Company
78 | Location
79 | Email
80 |
81 |
82 |
83 | DefaultDisplayProperty
84 | Login
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/Types/Project.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Project
4 |
5 |
6 | ProjectId
7 | id
8 |
9 |
10 | CreatedAt
11 | created_at
12 |
13 |
14 | UpdatedAt
15 | updated_at
16 |
17 |
18 | PSStandardMembers
19 |
20 |
21 | DefaultDisplayPropertySet
22 |
23 | Number
24 | State
25 | Name
26 | Body
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Types/ProjectCard.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.ProjectCard
4 |
5 |
6 | CardId
7 | id
8 |
9 |
10 | CreatedAt
11 | created_at
12 |
13 |
14 | UpdatedAt
15 | updated_at
16 |
17 |
18 | Owner
19 |
20 | if ($this.content_url -match '/([^/]+)/([^/]+)/(issues|pulls)/(\d+)$') {
21 | $Matches[1]
22 | }
23 |
24 |
25 |
26 | RepositoryName
27 |
28 | if ($this.content_url -match '/([^/]+)/([^/]+)/(issues|pulls)/(\d+)$') {
29 | $Matches[2]
30 | }
31 |
32 |
33 |
34 | Number
35 |
36 | if ($this.content_url -match '/([^/]+)/([^/]+)/(issues|pulls)/(\d+)$') {
37 | $Matches[4]
38 | }
39 |
40 |
41 |
42 | PSStandardMembers
43 |
44 |
45 | DefaultDisplayPropertySet
46 |
47 | Note
48 | Owner
49 | RepositoryName
50 | Number
51 | Archived
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/Types/ProjectColumn.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.ProjectColumn
4 |
5 |
6 | ColumnId
7 | id
8 |
9 |
10 | CreatedAt
11 | created_at
12 |
13 |
14 | UpdatedAt
15 | updated_at
16 |
17 |
18 | PSStandardMembers
19 |
20 |
21 | DefaultDisplayPropertySet
22 |
23 | Name
24 | CreatedAt
25 | UpdatedAt
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Types/PullRequest.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.PullRequest
4 |
5 |
6 |
7 | Type
8 | PullRequest
9 |
10 |
11 | Icon
12 | ⎇
13 |
14 |
15 |
16 | HeadRef
17 | $this.head.ref
18 |
19 |
20 | Sha
21 | $this.head.sha
22 |
23 |
24 | MergedAt
25 | merged_at
26 |
27 |
28 | ChangedFiles
29 | changed_files
30 |
31 |
32 | RequestedReviewers
33 | requested_reviewers
34 |
35 |
36 | RequestedTeams
37 | requested_teams
38 |
39 |
40 | PSStandardMembers
41 |
42 |
43 | DefaultDisplayPropertySet
44 |
45 | Title
46 | Number
47 | State
48 | User
49 | CreatedAt
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Types/PullRequestFile.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.PullRequestFile
4 |
5 |
6 | RawUrl
7 | raw_url
8 |
9 |
10 | PSStandardMembers
11 |
12 |
13 | DefaultDisplayPropertySet
14 |
15 | FileName
16 | Status
17 | Sha
18 | Changes
19 | Additions
20 | Deletions
21 | Patch
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Types/RateLimit.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.RateLimit
4 |
5 |
6 | PSStandardMembers
7 |
8 |
9 | DefaultDisplayPropertySet
10 |
11 | Resources
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Types/RateLimitResource.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.RateLimitResource
4 |
5 |
6 | PSStandardMembers
7 |
8 |
9 | DefaultDisplayPropertySet
10 |
11 | Limit
12 | Remaining
13 | Reset
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Types/RateLimitResources.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.RateLimitResources
4 |
5 |
6 | IntegrationManifest
7 | integration_manifest
8 |
9 |
10 | PSStandardMembers
11 |
12 |
13 | DefaultDisplayPropertySet
14 |
15 | Core
16 | Search
17 | GraphQL
18 | IntegrationManifest
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Types/Release.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Release
4 |
5 |
6 | UploadUrl
7 | upload_url
8 |
9 |
10 | AssetsUrl
11 | assets_url
12 |
13 |
14 | TarballUrl
15 | tarball_url
16 |
17 |
18 | ZipballUrl
19 | zipball_url
20 |
21 |
22 | HtmlUrl
23 | html_url
24 |
25 |
26 | TagName
27 | tag_name
28 |
29 |
30 | TargetCommitish
31 | target_commitish
32 |
33 |
34 | CreatedAt
35 | created_at
36 |
37 |
38 | PublishedAt
39 | updated_at
40 |
41 |
42 | PSStandardMembers
43 |
44 |
45 | DefaultDisplayPropertySet
46 |
47 | Name
48 | CreatedAt
49 | Draft
50 | Prerelease
51 | Author
52 | TagName
53 | TargetCommitish
54 | Body
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/Types/Repository.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Repository
4 |
5 |
6 | RepositoryName
7 | Name
8 |
9 |
10 | FullName
11 | full_name
12 |
13 |
14 | HtmlUrl
15 | html_url
16 |
17 |
18 | CloneUrl
19 | clone_url
20 |
21 |
22 | DefaultBranch
23 | default_branch
24 |
25 |
26 | CreatedAt
27 | created_at
28 |
29 |
30 | UpdatedAt
31 | updated_at
32 |
33 |
34 | PushedAt
35 | pushed_at
36 |
37 |
38 | StargazersCount
39 | stargazers_count
40 |
41 |
42 | OpenIssues
43 | open_issues
44 |
45 |
46 | TemplateRepository
47 | template_repository
48 |
49 |
50 | TemplateOwner
51 |
52 | if ($this.is_template) { $this.owner } else { $null }
53 |
54 |
55 |
56 | TemplateRepositoryName
57 |
58 | if ($this.is_template) { $this.name } else { $null }
59 |
60 |
61 |
62 | PSStandardMembers
63 |
64 |
65 | DefaultDisplayPropertySet
66 |
67 | Name
68 | Description
69 | Owner
70 | Private
71 | Fork
72 | HtmlUrl
73 | CreatedAt
74 | UpdatedAt
75 | PushedAt
76 | Language
77 | Forks
78 | StargazersCount
79 | OpenIssues
80 | Archived
81 | Permissions
82 | License
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/Types/Review.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Review
4 |
5 |
6 | ReviewId
7 | id
8 |
9 |
10 | HtmlUrl
11 | html_url
12 |
13 |
14 | CommitId
15 | commit_id
16 |
17 |
18 | SubmittedAt
19 | submitted_at
20 |
21 |
22 | PSStandardMembers
23 |
24 |
25 | DefaultDisplayPropertySet
26 |
27 | User
28 | State
29 | Body
30 | SubmittedAt
31 | CommitId
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/Types/Team.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.Team
4 |
5 |
6 | TeamId
7 | Id
8 |
9 |
10 | OrganizationName
11 | $this.organization.login
12 |
13 |
14 | ReposCount
15 | repos_count
16 |
17 |
18 | MembersCount
19 | members_count
20 |
21 |
22 | CreatedAt
23 | created_at
24 |
25 |
26 | UpdatedAt
27 | updated_at
28 |
29 |
30 | HtmlUrl
31 | html_url
32 |
33 |
34 | PSStandardMembers
35 |
36 |
37 | DefaultDisplayPropertySet
38 |
39 | Name
40 | Slug
41 | Privacy
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Types/User.Types.ps1xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSGitHub.User
4 |
5 |
6 | Username
7 | login
8 |
9 |
10 | CreatedAt
11 | created_at
12 |
13 |
14 | HtmlUrl
15 | html_url
16 |
17 |
18 | ToString
19 |
20 |
21 |
22 | PSStandardMembers
23 |
24 |
25 | DefaultDisplayPropertySet
26 |
27 | Login
28 | Type
29 | HtmlUrl
30 |
31 |
32 |
33 | DefaultDisplayProperty
34 | Login
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------