55 "encoding/hex"
66 "errors"
77 "fmt"
8- "io/ioutil"
98 "log"
109 "os"
1110 "path"
@@ -15,7 +14,7 @@ import (
1514 "unicode"
1615 "unicode/utf8"
1716
18- "github.com/google/go-github/v35 /github"
17+ "github.com/google/go-github/v56 /github"
1918
2019 "github.com/xanzy/go-gitlab"
2120 "golang.org/x/oauth2"
@@ -244,7 +243,7 @@ func LoadCommitPolicy(filename string) (CommitPolicyConfig, error) {
244243
245244 var config string
246245
247- if data , err := ioutil .ReadFile (filename ); err != nil {
246+ if data , err := os .ReadFile (filename ); err != nil {
248247 log .Printf ("warning: using built-in fallback configuration with HAProxy defaults (%s)" , err )
249248
250249 config = defaultConf
@@ -297,8 +296,18 @@ func getGithubCommitSubjects() ([]string, error) {
297296
298297 subjects := []string {}
299298 for _ , c := range commits {
300- l := strings .SplitN (c .Commit .GetMessage (), "\n " , 2 )
299+ l := strings .SplitN (c .Commit .GetMessage (), "\n " , 3 )
300+ hash := c .Commit .GetSHA ()
301+ if len (hash ) > 8 {
302+ hash = hash [:8 ]
303+ }
304+ if len (l ) > 1 {
305+ if l [1 ] != "" {
306+ return nil , fmt .Errorf ("empty line between subject and body is required: %s %s" , hash , l [0 ])
307+ }
308+ }
301309 if len (l ) > 0 {
310+ log .Printf ("detected message %s from commit %s" , l [0 ], hash )
302311 subjects = append (subjects , l [0 ])
303312 }
304313 }
@@ -335,8 +344,15 @@ func getGitlabCommitSubjects() ([]string, error) {
335344
336345 subjects := []string {}
337346 for _ , c := range commits {
338- l := strings .SplitN (c .Message , "\n " , 2 )
347+ l := strings .SplitN (c .Message , "\n " , 3 )
348+ hash := c .ShortID
339349 if len (l ) > 0 {
350+ if len (l ) > 1 {
351+ if l [1 ] != "" {
352+ return nil , fmt .Errorf ("empty line between subject and body is required: %s %s" , hash , l [0 ])
353+ }
354+ }
355+ log .Printf ("detected message %s from commit %s" , l [0 ], hash )
340356 subjects = append (subjects , l [0 ])
341357 }
342358 }
0 commit comments