Skip to content

Commit

Permalink
gp git-commit-message-helper to use git interpret-trailers
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed Jan 21, 2025
1 parent ec1be43 commit 7ccd1c8
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions components/gitpod-cli/cmd/git-commit-message-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"fmt"
"os"
"strings"
"os/exec"
"time"

"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
Expand All @@ -32,25 +32,22 @@ var gitCommitMessageHelper = &cobra.Command{

wsInfo, err := gitpod.GetWSInfo(ctx)
if err != nil {
return err
log.WithError(err).Fatal("error getting workspace info")
return nil // don't block commit
}

content, err := os.ReadFile(gitCommitMessageHelperOpts.CommitMessageFile)
if err != nil {
log.WithError(err).Fatal("error reading commit message file")
return err
}
trailerCmd := exec.Command("git", "interpret-trailers",
"--if-exists", "addIfDifferent",
"--trailer", fmt.Sprintf("Tool: gitpod/%s", wsInfo.GitpodApi.Host),
gitCommitMessageHelperOpts.CommitMessageFile)

toolAttribution := fmt.Sprintf("Tool: gitpod/%s", wsInfo.GitpodApi.Host)

msg := string(content)
if strings.Contains(msg, toolAttribution) {
return nil
output, err := trailerCmd.Output()
if err != nil {
log.WithError(err).Fatal("error adding trailer")
return nil // don't block commit
}

newMsg := fmt.Sprintf("%s\n\n%s", msg, toolAttribution)

err = os.WriteFile(gitCommitMessageHelperOpts.CommitMessageFile, []byte(newMsg), 0644)
err = os.WriteFile(gitCommitMessageHelperOpts.CommitMessageFile, output, 0644)
if err != nil {
log.WithError(err).Fatal("error writing commit message file")
return err
Expand Down

0 comments on commit 7ccd1c8

Please sign in to comment.