From 6c32a1a3a8cb88d83876ebad5584d3c91fab000f Mon Sep 17 00:00:00 2001 From: Alan Moran Date: Mon, 27 Oct 2025 19:30:37 +0100 Subject: [PATCH 1/2] Fix 422 error when updating release without commitish parameter When updating an existing release without providing a commitish parameter, the resource was setting TargetCommitish to an empty string, which GitHub's API rejects with a 422 "Invalid target_commitish parameter" error. This fix mirrors the behavior of the Body field - when commitish is not specified, TargetCommitish is now set to nil instead of an empty string, allowing GitHub to preserve the existing target commit for the release. Signed-off-by: Alan Moran --- out_command.go | 11 +++++++++-- out_command_test.go | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/out_command.go b/out_command.go index 64ae978..821f2fb 100644 --- a/out_command.go +++ b/out_command.go @@ -48,8 +48,10 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err } } - targetCommitish := "" + var targetCommitish string + commitishSpecified := false if request.Params.CommitishPath != "" { + commitishSpecified = true targetCommitish, err = c.fileContents(filepath.Join(sourceDir, request.Params.CommitishPath)) if err != nil { return OutResponse{}, err @@ -94,10 +96,15 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err } existingRelease.Name = github.String(name) - existingRelease.TargetCommitish = github.String(targetCommitish) existingRelease.Draft = github.Bool(draft) existingRelease.Prerelease = github.Bool(prerelease) + if commitishSpecified { + existingRelease.TargetCommitish = github.String(targetCommitish) + } else { + existingRelease.TargetCommitish = nil + } + if bodySpecified { existingRelease.Body = github.String(body) } else { diff --git a/out_command_test.go b/out_command_test.go index 26c5fbf..4742d30 100644 --- a/out_command_test.go +++ b/out_command_test.go @@ -185,7 +185,7 @@ var _ = Describe("Out Command", func() { }) Context("when a commitish is not supplied", func() { - It("updates the existing release", func() { + It("does not update the target commitish", func() { _, err := command.Run(sourcesDir, request) Ω(err).ShouldNot(HaveOccurred()) @@ -194,7 +194,7 @@ var _ = Describe("Out Command", func() { updatedRelease := githubClient.UpdateReleaseArgsForCall(0) Ω(*updatedRelease.Name).Should(Equal("v0.3.12")) Ω(*updatedRelease.Body).Should(Equal("this is a great release")) - Ω(updatedRelease.TargetCommitish).Should(Equal(github.String(""))) + Ω(updatedRelease.TargetCommitish).Should(BeNil()) }) }) From 51fa4794fc765cc7cff530b91fd681b196a97a7a Mon Sep 17 00:00:00 2001 From: Taylor Silva Date: Mon, 24 Nov 2025 13:03:49 -0500 Subject: [PATCH 2/2] address nitpicks Signed-off-by: Taylor Silva --- out_command.go | 6 +----- out_command_test.go | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/out_command.go b/out_command.go index 821f2fb..58c03eb 100644 --- a/out_command.go +++ b/out_command.go @@ -49,9 +49,7 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err } var targetCommitish string - commitishSpecified := false if request.Params.CommitishPath != "" { - commitishSpecified = true targetCommitish, err = c.fileContents(filepath.Join(sourceDir, request.Params.CommitishPath)) if err != nil { return OutResponse{}, err @@ -99,10 +97,8 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err existingRelease.Draft = github.Bool(draft) existingRelease.Prerelease = github.Bool(prerelease) - if commitishSpecified { + if targetCommitish != "" { existingRelease.TargetCommitish = github.String(targetCommitish) - } else { - existingRelease.TargetCommitish = nil } if bodySpecified { diff --git a/out_command_test.go b/out_command_test.go index 4742d30..0ea351f 100644 --- a/out_command_test.go +++ b/out_command_test.go @@ -185,7 +185,7 @@ var _ = Describe("Out Command", func() { }) Context("when a commitish is not supplied", func() { - It("does not update the target commitish", func() { + It("updates the existing release", func() { _, err := command.Run(sourcesDir, request) Ω(err).ShouldNot(HaveOccurred()) @@ -194,7 +194,7 @@ var _ = Describe("Out Command", func() { updatedRelease := githubClient.UpdateReleaseArgsForCall(0) Ω(*updatedRelease.Name).Should(Equal("v0.3.12")) Ω(*updatedRelease.Body).Should(Equal("this is a great release")) - Ω(updatedRelease.TargetCommitish).Should(BeNil()) + Ω(updatedRelease.TargetCommitish).Should(BeNil(), "does not set the TargetCommitish") }) })