Skip to content

Commit b9217d2

Browse files
committed
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.
1 parent 1088e2c commit b9217d2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

out_command.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
4848
}
4949
}
5050

51-
targetCommitish := ""
51+
var targetCommitish string
52+
commitishSpecified := false
5253
if request.Params.CommitishPath != "" {
54+
commitishSpecified = true
5355
targetCommitish, err = c.fileContents(filepath.Join(sourceDir, request.Params.CommitishPath))
5456
if err != nil {
5557
return OutResponse{}, err
@@ -94,10 +96,15 @@ func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, err
9496
}
9597

9698
existingRelease.Name = github.String(name)
97-
existingRelease.TargetCommitish = github.String(targetCommitish)
9899
existingRelease.Draft = github.Bool(draft)
99100
existingRelease.Prerelease = github.Bool(prerelease)
100101

102+
if commitishSpecified {
103+
existingRelease.TargetCommitish = github.String(targetCommitish)
104+
} else {
105+
existingRelease.TargetCommitish = nil
106+
}
107+
101108
if bodySpecified {
102109
existingRelease.Body = github.String(body)
103110
} else {

out_command_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ var _ = Describe("Out Command", func() {
185185
})
186186

187187
Context("when a commitish is not supplied", func() {
188-
It("updates the existing release", func() {
188+
It("does not update the target commitish", func() {
189189
_, err := command.Run(sourcesDir, request)
190190
Ω(err).ShouldNot(HaveOccurred())
191191

@@ -194,7 +194,7 @@ var _ = Describe("Out Command", func() {
194194
updatedRelease := githubClient.UpdateReleaseArgsForCall(0)
195195
Ω(*updatedRelease.Name).Should(Equal("v0.3.12"))
196196
Ω(*updatedRelease.Body).Should(Equal("this is a great release"))
197-
Ω(updatedRelease.TargetCommitish).Should(Equal(github.String("")))
197+
Ω(updatedRelease.TargetCommitish).Should(BeNil())
198198
})
199199
})
200200

0 commit comments

Comments
 (0)