Thanks to visit codestin.com
Credit goes to github.com

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
35 changes: 32 additions & 3 deletions pkg/cmd/release/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
Use release notes from a file
$ gh release create v1.2.3 -F changelog.md

Use annotated tag notes
$ gh release create v1.2.3 --notes-from-tag

Don't mark the release as latest
$ gh release create v1.2.3 --latest=false

Expand Down Expand Up @@ -516,12 +519,38 @@ func createRun(opts *CreateOptions) error {
}

func gitTagInfo(client *git.Client, tagName string) (string, error) {
cmd, err := client.Command(context.Background(), "tag", "--list", tagName, "--format=%(contents:subject)%0a%0a%(contents:body)")
contentCmd, err := client.Command(context.Background(), "tag", "--list", tagName, "--format=%(contents)")
if err != nil {
return "", err
}
b, err := cmd.Output()
return string(b), err
Comment on lines -523 to -524
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating this function to return empty string for the body if an error is raised makes sense. That said, I wonder if that was always the case. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Since it's the result of a command execution, it's possible to have non-nil value for both error and result. But obviously, when there's an error the result value is unreliable. Esepcially, when it's the stdout of a command, which, for example, can be an error message.

Interestingly, the caller of this function, ignores the error which makes it even more risky.

tagDescription, _ = gitTagInfo(opts.GitClient, opts.TagName)

I think we should:

  • Check the error at the caller side and print a proper error message when the tag annotation cannot be extracted.
  • In gitTagInfo, return "", err when there's an error (as it's already done in this PR).

What do you think?

content, err := contentCmd.Output()
if err != nil {
return "", err
}

// If there is a signature, we should strip it from the end of the content.
// Note that, we can achieve this by looking for markers like "-----BEGIN PGP
// SIGNATURE-----" and cut the remaining text from the content, but this is
// not a safe approach, because, although unlikely, the content can contain
// a signature-like section which we shouldn't leave it as is. So, we need
// to get the tag signature as a whole, if any, and remote it from the content.
signatureCmd, err := client.Command(context.Background(), "tag", "--list", tagName, "--format=%(contents:signature)")
if err != nil {
return "", err
}
signature, err := signatureCmd.Output()
if err != nil {
return "", err
}

if len(signature) == 0 {
// The tag annotation content has no trailing signature to strip out,
// so we return the entire content.
return string(content), nil
}

body, _ := strings.CutSuffix(string(content), "\n"+string(signature))
return body, nil
}

func detectPreviousTag(client *git.Client, headRef string) (string, error) {
Expand Down
Loading