Skip to content

Commit e6c6477

Browse files
authored
Merge pull request #43 from NaverPayDev/fix/commithelper-go
Modify main.go to handle unchanged commit messages without modification
2 parents 3beb236 + 7912854 commit e6c6477

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

.changeset/public-bikes-swim.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@naverpay/commithelper-go": patch
3+
---
4+
5+
Modify main.go to handle unchanged commit messages without modification
6+
7+
PR: [Modify main.go to handle unchanged commit messages without modification](https://github.com/NaverPayDev/cli/pull/43)

packages/commithelper-go/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ func main() {
3636
commitMessage = input
3737
}
3838

39+
// Check if commit message is already tagged
40+
if isAlreadyTagged(commitMessage) {
41+
// Do not modify if already tagged
42+
if _, err := os.Stat(input); err == nil {
43+
// Write back unchanged if input was a file
44+
err = ioutil.WriteFile(input, []byte(commitMessage), 0644)
45+
if err != nil {
46+
fmt.Printf("Error writing to commit message file: %v\n", err)
47+
os.Exit(1)
48+
}
49+
} else {
50+
// Print unchanged if input was a direct message
51+
fmt.Println(commitMessage)
52+
}
53+
return
54+
}
55+
3956
branchName := getCurrentBranchName()
4057
config := loadConfig()
4158

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

123140
return fmt.Sprintf("%s#%s", *repo, issueNumber)
124141
}
142+
143+
func isAlreadyTagged(commitMessage string) bool {
144+
// Check if commit message already contains issue tag like [#123] or [org/repo#123]
145+
// This pattern matches:
146+
// - [#123] (simple issue number)
147+
// - [Some-Org/Some_Repo#123] (complex repo with special chars)
148+
pattern := regexp.MustCompile(`^\[.*?#\d+\]`)
149+
trimmedMessage := strings.TrimSpace(commitMessage)
150+
return pattern.MatchString(trimmedMessage)
151+
}

0 commit comments

Comments
 (0)