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
7 changes: 7 additions & 0 deletions .changeset/public-bikes-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@naverpay/commithelper-go": patch
---

Modify main.go to handle unchanged commit messages without modification

PR: [Modify main.go to handle unchanged commit messages without modification](https://github.com/NaverPayDev/cli/pull/43)
27 changes: 27 additions & 0 deletions packages/commithelper-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ func main() {
commitMessage = input
}

// Check if commit message is already tagged
if isAlreadyTagged(commitMessage) {
// Do not modify if already tagged
if _, err := os.Stat(input); err == nil {
// Write back unchanged if input was a file
err = ioutil.WriteFile(input, []byte(commitMessage), 0644)
if err != nil {
fmt.Printf("Error writing to commit message file: %v\n", err)
os.Exit(1)
}
} else {
// Print unchanged if input was a direct message
fmt.Println(commitMessage)
}
return
}

branchName := getCurrentBranchName()
config := loadConfig()

Expand Down Expand Up @@ -122,3 +139,13 @@ func generatePrefix(branchName string, config Config) string {

return fmt.Sprintf("%s#%s", *repo, issueNumber)
}

func isAlreadyTagged(commitMessage string) bool {
// Check if commit message already contains issue tag like [#123] or [org/repo#123]
// This pattern matches:
// - [#123] (simple issue number)
// - [Some-Org/Some_Repo#123] (complex repo with special chars)
pattern := regexp.MustCompile(`^\[.*?#\d+\]`)
trimmedMessage := strings.TrimSpace(commitMessage)
return pattern.MatchString(trimmedMessage)
}