@@ -36,6 +36,23 @@ func main() {
36
36
commitMessage = input
37
37
}
38
38
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
+
39
56
branchName := getCurrentBranchName ()
40
57
config := loadConfig ()
41
58
@@ -122,3 +139,13 @@ func generatePrefix(branchName string, config Config) string {
122
139
123
140
return fmt .Sprintf ("%s#%s" , * repo , issueNumber )
124
141
}
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