From e0b979a10dcb36e3802196d159655f032567e6ca Mon Sep 17 00:00:00 2001 From: Robin Breathe Date: Fri, 20 Sep 2024 16:44:26 +0200 Subject: [PATCH] fix(tag): directly update refs rather than delete+create (#52) --- cmd/tag.go | 24 ++++++++++++------------ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/tag.go b/cmd/tag.go index 08ba8a3..511b75e 100644 --- a/cmd/tag.go +++ b/cmd/tag.go @@ -78,7 +78,6 @@ func runTagCmd(cmd *cobra.Command, args []string) (err error) { annotatedTag := &github.Tag{ Tag: &tagName, Message: &message, - // Message: github.String("hard-coded message"), Object: &github.GitObject{ Type: github.String("commit"), SHA: github.String(branchRef.Object.GetSHA()), @@ -95,13 +94,6 @@ func runTagCmd(cmd *cobra.Command, args []string) (err error) { tagRefObject = branchRef.Object.GetSHA() } - if existingTagRef != nil { - log.Infof("deleting existing tag reference") - if _, err := client.V3.Git.DeleteRef(ctx, owner, repo, existingTagRef.GetRef()); err != nil { - return errors.Wrap(err, "DeleteRef") - } - } - tagRef := &github.Reference{ Ref: &tagRefName, Object: &github.GitObject{ @@ -109,10 +101,18 @@ func runTagCmd(cmd *cobra.Command, args []string) (err error) { }, } - log.Infof("creating tag reference") - _, _, err = client.V3.Git.CreateRef(ctx, owner, repo, tagRef) - if err != nil { - return errors.Wrap(err, "CreateRef") + if existingTagRef == nil { + log.Infof("creating tag reference") + _, _, err = client.V3.Git.CreateRef(ctx, owner, repo, tagRef) + if err != nil { + return errors.Wrap(err, "CreateRef") + } + } else { + log.Infof("updating tag reference") + _, _, err = client.V3.Git.UpdateRef(ctx, owner, repo, tagRef, true) + if err != nil { + return errors.Wrap(err, "UpdateRef") + } } fmt.Printf("https://github.com/%s/%s/releases/tag/%s\n", owner, repo, tagName) diff --git a/go.mod b/go.mod index 30a72d5..d34b6c8 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/Microsoft/go-winio v0.6.2 // indirect github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/cloudflare/circl v1.4.0 // indirect - github.com/cyphar/filepath-securejoin v0.3.1 // indirect + github.com/cyphar/filepath-securejoin v0.3.2 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.17.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect diff --git a/go.sum b/go.sum index dcf1c11..d872271 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUK github.com/cloudflare/circl v1.4.0 h1:BV7h5MgrktNzytKmWjpOtdYrf0lkkbF8YMlBGPhJQrY= github.com/cloudflare/circl v1.4.0/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/cyphar/filepath-securejoin v0.3.1 h1:1V7cHiaW+C+39wEfpH6XlLBQo3j/PciWFrgfCLS8XrE= -github.com/cyphar/filepath-securejoin v0.3.1/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc= +github.com/cyphar/filepath-securejoin v0.3.2 h1:QhZu5AxQ+o1XZH0Ye05YzvJ0kAdK6VQc0z9NNMek7gc= +github.com/cyphar/filepath-securejoin v0.3.2/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=