Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/GitHub/private/Releases/Releases/Get-GitHubReleaseAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
filter Get-GitHubReleaseAll {
<#
.SYNOPSIS
List releases

.DESCRIPTION
This returns a list of releases, which does not include regular Git tags that have not been associated with a release.
To get a list of Git tags, use the [Repository Tags API](https://docs.github.com/rest/repos/repos#list-repository-tags).
Information about published releases are available to everyone. Only users with push access will receive listings for draft releases.

.EXAMPLE
Get-GitHubReleaseAll -Owner 'octocat' -Repo 'hello-world'

Gets all the releases for the repository 'hello-world' owned by 'octocat'.

.NOTES
https://docs.github.com/rest/releases/releases#list-releases

#>
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubConfig -Name Owner),

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubConfig -Name Repo),

# The number of results per page (max 100).
[Parameter(ParameterSetName = 'AllUsers')]
[int] $PerPage = 30
)

$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo'

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/releases"
Method = 'GET'
Body = $body
}

(Invoke-GitHubAPI @inputObject).Response

}
44 changes: 44 additions & 0 deletions src/GitHub/private/Releases/Releases/Get-GitHubReleaseByID.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
filter Get-GitHubReleaseByID {
<#
.SYNOPSIS
Get a release

.DESCRIPTION
**Note:** This returns an `upload_url` key corresponding to the endpoint for uploading release assets.
This key is a [hypermedia resource](https://docs.github.com/rest/overview/resources-in-the-rest-api#hypermedia).

.EXAMPLE
Get-GitHubReleaseById -Owner 'octocat' -Repo 'hello-world' -ID '1234567'

Gets the release with the id '1234567' for the repository 'hello-world' owned by 'octocat'.

.NOTES
https://docs.github.com/rest/releases/releases#get-a-release

#>
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubConfig -Name Owner),

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubConfig -Name Repo),

# The unique identifier of the release.
[Parameter(
Mandatory
)]
[Alias('release_id')]
[string] $ID
)

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/releases/$ID"
Method = 'GET'
}

(Invoke-GitHubAPI @inputObject).Response

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
filter Get-GitHubReleaseByTagName {
<#
.SYNOPSIS
Get a release by tag name

.DESCRIPTION
Get a published release with the specified tag.

.EXAMPLE
Get-GitHubReleaseByTagName -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0'

Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'.

.NOTES
https://docs.github.com/rest/releases/releases#get-a-release-by-tag-name

#>
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubConfig -Name Owner),

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubConfig -Name Repo),

# The name of the tag to get a release from.
[Parameter(
Mandatory
)]
[string] $Tag
)

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/releases/tags/$Tag"
Method = 'GET'
}

(Invoke-GitHubAPI @inputObject).Response

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
filter Get-GitHubReleaseLatest {
<#
.SYNOPSIS
Get the latest release

.DESCRIPTION
View the latest published full release for the repository.
The latest release is the most recent non-prerelease, non-draft release, sorted by the `created_at` attribute.
The `created_at` attribute is the date of the commit used for the release, and not the date when the release was drafted or published.

.EXAMPLE
Get-GitHubReleaseLatest -Owner 'octocat' -Repo 'hello-world'

Gets the latest releases for the repository 'hello-world' owned by 'octocat'.

.NOTES
https://docs.github.com/rest/releases/releases#get-the-latest-release

#>
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubConfig -Name Owner),

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubConfig -Name Repo)

)

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/releases/latest"
Method = 'GET'
}

(Invoke-GitHubAPI @inputObject).Response

}
80 changes: 80 additions & 0 deletions src/GitHub/public/Releases/Releases/Get-GitHubRelease.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
filter Get-GitHubRelease {
<#
.SYNOPSIS
List releases

.DESCRIPTION
This returns a list of releases, which does not include regular Git tags that have not been associated with a release.
To get a list of Git tags, use the [Repository Tags API](https://docs.github.com/rest/repos/repos#list-repository-tags).
Information about published releases are available to everyone. Only users with push access will receive listings for draft releases.

.EXAMPLE
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world'

Gets the releases for the repository 'hello-world' owned by 'octocat'.

.EXAMPLE
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -Latest

Gets the latest releases for the repository 'hello-world' owned by 'octocat'.

.EXAMPLE
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0'

Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'.

.EXAMPLE
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -ID '1234567'

Gets the release with the id '1234567' for the repository 'hello-world' owned by 'octocat'.

.NOTES
https://docs.github.com/rest/releases/releases#list-releases
https://docs.github.com/rest/releases/releases#get-the-latest-release

#>
[CmdletBinding(DefaultParameterSetName = 'All')]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubConfig -Name Owner),

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubConfig -Name Repo),

# The number of results per page (max 100).
[Parameter(ParameterSetName = 'All')]
[int] $PerPage = 30,

# Get the latest release only
[Parameter(
Mandatory,
ParameterSetName = 'Latest'
)]
[switch] $Latest,

# The name of the tag to get a release from.
[Parameter(
Mandatory,
ParameterSetName = 'Tag'
)]
[switch] $Tag,

# The unique identifier of the release.
[Parameter(
Mandatory,
ParameterSetName = 'Id'
)]
[Alias('release_id')]
[string] $ID
)

switch ($PSCmdlet.ParameterSetName) {
'All' { Get-GitHubReleaseAll -Owner $Owner -Repo $Repo -PerPage $PerPage }
'Latest' { Get-GitHubReleaseLatest -Owner $Owner -Repo $Repo }
'Tag' { Get-GitHubReleaseByTagName -Owner $Owner -Repo $Repo -Tag $Tag }
'Id' { Get-GitHubReleaseByID -Owner $Owner -Repo $Repo -ID $ID }
}

}
97 changes: 97 additions & 0 deletions src/GitHub/public/Releases/Releases/New-GitHubRelease.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
filter New-GitHubRelease {
<#
.SYNOPSIS
Create a release

.DESCRIPTION
Users with push access to the repository can create a release.
This endpoint triggers [notifications](https://docs.github.com/github/managing-subscriptions-and-notifications-on-github/about-notifications).
Creating content too quickly using this endpoint may result in secondary rate limiting.
See "[Secondary rate limits](https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits)"
and "[Dealing with secondary rate limits](https://docs.github.com/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)" for details.

.EXAMPLE
New-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -TagName 'v1.0.0' -TargetCommitish 'main' -Body 'Release notes'

Creates a release for the repository 'octocat/hello-world' with the tag 'v1.0.0' and the target commitish 'main'.

.NOTES
https://docs.github.com/rest/releases/releases#create-a-release

#>
[OutputType([pscustomobject])]
[CmdletBinding()]
param (
# The account owner of the repository. The name is not case sensitive.
[Parameter()]
[string] $Owner = (Get-GitHubConfig -Name Owner),

# The name of the repository without the .git extension. The name is not case sensitive.
[Parameter()]
[string] $Repo = (Get-GitHubConfig -Name Repo),

# The name of the tag.
[Parameter(Mandatory)]
[Alias('tag_name')]
[string] $TagName,

# Specifies the commitish value that determines where the Git tag is created from.
# Can be any branch or commit SHA. Unused if the Git tag already exists.
# API Default: the repository's default branch.
[Parameter()]
[Alias('target_commitish')]
[string] $TargetCommitish,

# The name of the release.
[Parameter()]
[string] $Name,

# Text describing the contents of the tag.
[Parameter()]
[string] $Body,

# Whether the release is a draft.
[Parameter()]
[switch] $Draft,

# Whether to identify the release as a prerelease.
[Parameter()]
[switch] $Prerelease,

# If specified, a discussion of the specified category is created and linked to the release.
# The value must be a category that already exists in the repository.
# For more information, see [Managing categories for discussions in your repository](https://docs.github.com/discussions/managing-discussions-for-your-community/managing-categories-for-discussions-in-your-repository).
[Parameter()]
[Alias('discussion_category_name')]
[string] $DiscussionCategoryName,

# Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise,a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes.
[Parameter()]
[Alias('generate_release_notes')]
[switch] $GenerateReleaseNotes,

# Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Defaults to true for newly published releases. legacy specifies that the latest release should be determined based on the release creation date and higher semantic version.
[Parameter()]
[Alias('make_latest')]
[ValidateSet('true', 'false', 'legacy')]
[string] $MakeLatest = 'true'
)

$requestBody = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
Remove-HashtableEntries -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'GenerateReleaseNotes', 'Draft', 'Prerelease'
$requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{
generate_release_notes = $GenerateReleaseNotes.IsPresent
draft = $Draft.IsPresent
prerelease = $Prerelease.IsPresent
}
Remove-HashtableEntries -Hashtable $requestBody -NullOrEmptyValues

$inputObject = @{
APIEndpoint = "/repos/$Owner/$Repo/releases"
Method = 'POST'
Body = $requestBody
}

(Invoke-GitHubAPI @inputObject).Response

}
Loading