Skip to content

Commit 41c7b99

Browse files
[Feature] Releases - Releases - Manage releases (#67)
- Fixes #58 - Get-GitHubRelease - New-GitHubRelease - New-GitHubReleaseNotes (Generate-GitHubReleaseNotes) - Remove-GitHubRelease - Set-GitHubRelease
1 parent 9e5ae3e commit 41c7b99

File tree

11 files changed

+596
-2
lines changed

11 files changed

+596
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
filter Get-GitHubReleaseAll {
2+
<#
3+
.SYNOPSIS
4+
List releases
5+
6+
.DESCRIPTION
7+
This returns a list of releases, which does not include regular Git tags that have not been associated with a release.
8+
To get a list of Git tags, use the [Repository Tags API](https://docs.github.com/rest/repos/repos#list-repository-tags).
9+
Information about published releases are available to everyone. Only users with push access will receive listings for draft releases.
10+
11+
.EXAMPLE
12+
Get-GitHubReleaseAll -Owner 'octocat' -Repo 'hello-world'
13+
14+
Gets all the releases for the repository 'hello-world' owned by 'octocat'.
15+
16+
.NOTES
17+
https://docs.github.com/rest/releases/releases#list-releases
18+
19+
#>
20+
[CmdletBinding()]
21+
param (
22+
# The account owner of the repository. The name is not case sensitive.
23+
[Parameter()]
24+
[string] $Owner = (Get-GitHubConfig -Name Owner),
25+
26+
# The name of the repository without the .git extension. The name is not case sensitive.
27+
[Parameter()]
28+
[string] $Repo = (Get-GitHubConfig -Name Repo),
29+
30+
# The number of results per page (max 100).
31+
[Parameter(ParameterSetName = 'AllUsers')]
32+
[int] $PerPage = 30
33+
)
34+
35+
$body = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
36+
Remove-HashtableEntries -Hashtable $body -RemoveNames 'Owner', 'Repo'
37+
38+
$inputObject = @{
39+
APIEndpoint = "/repos/$Owner/$Repo/releases"
40+
Method = 'GET'
41+
Body = $body
42+
}
43+
44+
(Invoke-GitHubAPI @inputObject).Response
45+
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
filter Get-GitHubReleaseByID {
2+
<#
3+
.SYNOPSIS
4+
Get a release
5+
6+
.DESCRIPTION
7+
**Note:** This returns an `upload_url` key corresponding to the endpoint for uploading release assets.
8+
This key is a [hypermedia resource](https://docs.github.com/rest/overview/resources-in-the-rest-api#hypermedia).
9+
10+
.EXAMPLE
11+
Get-GitHubReleaseById -Owner 'octocat' -Repo 'hello-world' -ID '1234567'
12+
13+
Gets the release with the id '1234567' for the repository 'hello-world' owned by 'octocat'.
14+
15+
.NOTES
16+
https://docs.github.com/rest/releases/releases#get-a-release
17+
18+
#>
19+
[CmdletBinding()]
20+
param (
21+
# The account owner of the repository. The name is not case sensitive.
22+
[Parameter()]
23+
[string] $Owner = (Get-GitHubConfig -Name Owner),
24+
25+
# The name of the repository without the .git extension. The name is not case sensitive.
26+
[Parameter()]
27+
[string] $Repo = (Get-GitHubConfig -Name Repo),
28+
29+
# The unique identifier of the release.
30+
[Parameter(
31+
Mandatory
32+
)]
33+
[Alias('release_id')]
34+
[string] $ID
35+
)
36+
37+
$inputObject = @{
38+
APIEndpoint = "/repos/$Owner/$Repo/releases/$ID"
39+
Method = 'GET'
40+
}
41+
42+
(Invoke-GitHubAPI @inputObject).Response
43+
44+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
filter Get-GitHubReleaseByTagName {
2+
<#
3+
.SYNOPSIS
4+
Get a release by tag name
5+
6+
.DESCRIPTION
7+
Get a published release with the specified tag.
8+
9+
.EXAMPLE
10+
Get-GitHubReleaseByTagName -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0'
11+
12+
Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'.
13+
14+
.NOTES
15+
https://docs.github.com/rest/releases/releases#get-a-release-by-tag-name
16+
17+
#>
18+
[CmdletBinding()]
19+
param (
20+
# The account owner of the repository. The name is not case sensitive.
21+
[Parameter()]
22+
[string] $Owner = (Get-GitHubConfig -Name Owner),
23+
24+
# The name of the repository without the .git extension. The name is not case sensitive.
25+
[Parameter()]
26+
[string] $Repo = (Get-GitHubConfig -Name Repo),
27+
28+
# The name of the tag to get a release from.
29+
[Parameter(
30+
Mandatory
31+
)]
32+
[string] $Tag
33+
)
34+
35+
$inputObject = @{
36+
APIEndpoint = "/repos/$Owner/$Repo/releases/tags/$Tag"
37+
Method = 'GET'
38+
}
39+
40+
(Invoke-GitHubAPI @inputObject).Response
41+
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
filter Get-GitHubReleaseLatest {
2+
<#
3+
.SYNOPSIS
4+
Get the latest release
5+
6+
.DESCRIPTION
7+
View the latest published full release for the repository.
8+
The latest release is the most recent non-prerelease, non-draft release, sorted by the `created_at` attribute.
9+
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.
10+
11+
.EXAMPLE
12+
Get-GitHubReleaseLatest -Owner 'octocat' -Repo 'hello-world'
13+
14+
Gets the latest releases for the repository 'hello-world' owned by 'octocat'.
15+
16+
.NOTES
17+
https://docs.github.com/rest/releases/releases#get-the-latest-release
18+
19+
#>
20+
[CmdletBinding()]
21+
param (
22+
# The account owner of the repository. The name is not case sensitive.
23+
[Parameter()]
24+
[string] $Owner = (Get-GitHubConfig -Name Owner),
25+
26+
# The name of the repository without the .git extension. The name is not case sensitive.
27+
[Parameter()]
28+
[string] $Repo = (Get-GitHubConfig -Name Repo)
29+
30+
)
31+
32+
$inputObject = @{
33+
APIEndpoint = "/repos/$Owner/$Repo/releases/latest"
34+
Method = 'GET'
35+
}
36+
37+
(Invoke-GitHubAPI @inputObject).Response
38+
39+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
filter Get-GitHubRelease {
2+
<#
3+
.SYNOPSIS
4+
List releases
5+
6+
.DESCRIPTION
7+
This returns a list of releases, which does not include regular Git tags that have not been associated with a release.
8+
To get a list of Git tags, use the [Repository Tags API](https://docs.github.com/rest/repos/repos#list-repository-tags).
9+
Information about published releases are available to everyone. Only users with push access will receive listings for draft releases.
10+
11+
.EXAMPLE
12+
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world'
13+
14+
Gets the releases for the repository 'hello-world' owned by 'octocat'.
15+
16+
.EXAMPLE
17+
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -Latest
18+
19+
Gets the latest releases for the repository 'hello-world' owned by 'octocat'.
20+
21+
.EXAMPLE
22+
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -Tag 'v1.0.0'
23+
24+
Gets the release with the tag 'v1.0.0' for the repository 'hello-world' owned by 'octocat'.
25+
26+
.EXAMPLE
27+
Get-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -ID '1234567'
28+
29+
Gets the release with the id '1234567' for the repository 'hello-world' owned by 'octocat'.
30+
31+
.NOTES
32+
https://docs.github.com/rest/releases/releases#list-releases
33+
https://docs.github.com/rest/releases/releases#get-the-latest-release
34+
35+
#>
36+
[CmdletBinding(DefaultParameterSetName = 'All')]
37+
param (
38+
# The account owner of the repository. The name is not case sensitive.
39+
[Parameter()]
40+
[string] $Owner = (Get-GitHubConfig -Name Owner),
41+
42+
# The name of the repository without the .git extension. The name is not case sensitive.
43+
[Parameter()]
44+
[string] $Repo = (Get-GitHubConfig -Name Repo),
45+
46+
# The number of results per page (max 100).
47+
[Parameter(ParameterSetName = 'All')]
48+
[int] $PerPage = 30,
49+
50+
# Get the latest release only
51+
[Parameter(
52+
Mandatory,
53+
ParameterSetName = 'Latest'
54+
)]
55+
[switch] $Latest,
56+
57+
# The name of the tag to get a release from.
58+
[Parameter(
59+
Mandatory,
60+
ParameterSetName = 'Tag'
61+
)]
62+
[switch] $Tag,
63+
64+
# The unique identifier of the release.
65+
[Parameter(
66+
Mandatory,
67+
ParameterSetName = 'Id'
68+
)]
69+
[Alias('release_id')]
70+
[string] $ID
71+
)
72+
73+
switch ($PSCmdlet.ParameterSetName) {
74+
'All' { Get-GitHubReleaseAll -Owner $Owner -Repo $Repo -PerPage $PerPage }
75+
'Latest' { Get-GitHubReleaseLatest -Owner $Owner -Repo $Repo }
76+
'Tag' { Get-GitHubReleaseByTagName -Owner $Owner -Repo $Repo -Tag $Tag }
77+
'Id' { Get-GitHubReleaseByID -Owner $Owner -Repo $Repo -ID $ID }
78+
}
79+
80+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
filter New-GitHubRelease {
2+
<#
3+
.SYNOPSIS
4+
Create a release
5+
6+
.DESCRIPTION
7+
Users with push access to the repository can create a release.
8+
This endpoint triggers [notifications](https://docs.github.com/github/managing-subscriptions-and-notifications-on-github/about-notifications).
9+
Creating content too quickly using this endpoint may result in secondary rate limiting.
10+
See "[Secondary rate limits](https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits)"
11+
and "[Dealing with secondary rate limits](https://docs.github.com/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)" for details.
12+
13+
.EXAMPLE
14+
New-GitHubRelease -Owner 'octocat' -Repo 'hello-world' -TagName 'v1.0.0' -TargetCommitish 'main' -Body 'Release notes'
15+
16+
Creates a release for the repository 'octocat/hello-world' with the tag 'v1.0.0' and the target commitish 'main'.
17+
18+
.NOTES
19+
https://docs.github.com/rest/releases/releases#create-a-release
20+
21+
#>
22+
[OutputType([pscustomobject])]
23+
[CmdletBinding()]
24+
param (
25+
# The account owner of the repository. The name is not case sensitive.
26+
[Parameter()]
27+
[string] $Owner = (Get-GitHubConfig -Name Owner),
28+
29+
# The name of the repository without the .git extension. The name is not case sensitive.
30+
[Parameter()]
31+
[string] $Repo = (Get-GitHubConfig -Name Repo),
32+
33+
# The name of the tag.
34+
[Parameter(Mandatory)]
35+
[Alias('tag_name')]
36+
[string] $TagName,
37+
38+
# Specifies the commitish value that determines where the Git tag is created from.
39+
# Can be any branch or commit SHA. Unused if the Git tag already exists.
40+
# API Default: the repository's default branch.
41+
[Parameter()]
42+
[Alias('target_commitish')]
43+
[string] $TargetCommitish,
44+
45+
# The name of the release.
46+
[Parameter()]
47+
[string] $Name,
48+
49+
# Text describing the contents of the tag.
50+
[Parameter()]
51+
[string] $Body,
52+
53+
# Whether the release is a draft.
54+
[Parameter()]
55+
[switch] $Draft,
56+
57+
# Whether to identify the release as a prerelease.
58+
[Parameter()]
59+
[switch] $Prerelease,
60+
61+
# If specified, a discussion of the specified category is created and linked to the release.
62+
# The value must be a category that already exists in the repository.
63+
# 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).
64+
[Parameter()]
65+
[Alias('discussion_category_name')]
66+
[string] $DiscussionCategoryName,
67+
68+
# 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.
69+
[Parameter()]
70+
[Alias('generate_release_notes')]
71+
[switch] $GenerateReleaseNotes,
72+
73+
# 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.
74+
[Parameter()]
75+
[Alias('make_latest')]
76+
[ValidateSet('true', 'false', 'legacy')]
77+
[string] $MakeLatest = 'true'
78+
)
79+
80+
$requestBody = $PSBoundParameters | ConvertFrom-HashTable | ConvertTo-HashTable -NameCasingStyle snake_case
81+
Remove-HashtableEntries -Hashtable $requestBody -RemoveNames 'Owner', 'Repo', 'GenerateReleaseNotes', 'Draft', 'Prerelease'
82+
$requestBody = Join-Object -AsHashtable -Main $requestBody -Overrides @{
83+
generate_release_notes = $GenerateReleaseNotes.IsPresent
84+
draft = $Draft.IsPresent
85+
prerelease = $Prerelease.IsPresent
86+
}
87+
Remove-HashtableEntries -Hashtable $requestBody -NullOrEmptyValues
88+
89+
$inputObject = @{
90+
APIEndpoint = "/repos/$Owner/$Repo/releases"
91+
Method = 'POST'
92+
Body = $requestBody
93+
}
94+
95+
(Invoke-GitHubAPI @inputObject).Response
96+
97+
}

0 commit comments

Comments
 (0)