| 568 | } |
| 569 | |
| 570 | func gitTagInfo(client *git.Client, tagName string) (string, error) { |
| 571 | contentCmd, err := client.Command(context.Background(), "tag", "--list", tagName, "--format=%(contents)") |
| 572 | if err != nil { |
| 573 | return "", err |
| 574 | } |
| 575 | content, err := contentCmd.Output() |
| 576 | if err != nil { |
| 577 | return "", err |
| 578 | } |
| 579 | |
| 580 | // If there is a signature, we should strip it from the end of the content. |
| 581 | // Note that, we can achieve this by looking for markers like "-----BEGIN PGP |
| 582 | // SIGNATURE-----" and cut the remaining text from the content, but this is |
| 583 | // not a safe approach, because, although unlikely, the content can contain |
| 584 | // a signature-like section which we shouldn't leave it as is. So, we need |
| 585 | // to get the tag signature as a whole, if any, and remote it from the content. |
| 586 | signatureCmd, err := client.Command(context.Background(), "tag", "--list", tagName, "--format=%(contents:signature)") |
| 587 | if err != nil { |
| 588 | return "", err |
| 589 | } |
| 590 | signature, err := signatureCmd.Output() |
| 591 | if err != nil { |
| 592 | return "", err |
| 593 | } |
| 594 | |
| 595 | if len(signature) == 0 { |
| 596 | // The tag annotation content has no trailing signature to strip out, |
| 597 | // so we return the entire content. |
| 598 | return string(content), nil |
| 599 | } |
| 600 | |
| 601 | body, _ := strings.CutSuffix(string(content), "\n"+string(signature)) |
| 602 | return body, nil |
| 603 | } |
| 604 | |
| 605 | func detectPreviousTag(client *git.Client, headRef string) (string, error) { |
| 606 | cmd, err := client.Command(context.Background(), "describe", "--tags", "--abbrev=0", fmt.Sprintf("%s^", headRef)) |