test: これは違法コミットの一例
This commit is contained in:
parent
c5d6433cb0
commit
7cbce3cb54
|
@ -7,7 +7,6 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// nonAsciiMsg checks for non-ASCII characters in the commit message.
|
// nonAsciiMsg checks for non-ASCII characters in the commit message.
|
||||||
|
@ -28,23 +27,19 @@ func NonAsciiMsg(root string) error {
|
||||||
slog.Error("getting reference", "err", err)
|
slog.Error("getting reference", "err", err)
|
||||||
return fmt.Errorf("error getting reference: %v", err)
|
return fmt.Errorf("error getting reference: %v", err)
|
||||||
}
|
}
|
||||||
commits, err := repo.Log(&git.LogOptions{From: ref.Hash()})
|
|
||||||
|
commit, err := repo.CommitObject(ref.Hash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("getting commits", "err", err)
|
slog.Error("getting latest commit", "err", err)
|
||||||
return fmt.Errorf("error getting commits from reference %s: %v", ref.Hash(), err)
|
return fmt.Errorf("error getting latest commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var msgs []string
|
msg := commit.Message
|
||||||
err = commits.ForEach(func(c *object.Commit) error {
|
if msg == "" {
|
||||||
msgs = append(msgs, c.Message)
|
|
||||||
return nil
|
return nil
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("iterating commits", "err", err)
|
|
||||||
return fmt.Errorf("error iterating commits: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var nonAsciiMsgs []string
|
var isCommitLegal bool = true
|
||||||
// List of prefixes to ignore in the commit message
|
// List of prefixes to ignore in the commit message
|
||||||
ignoredPrefixes := []string{
|
ignoredPrefixes := []string{
|
||||||
"Co-authored-by:",
|
"Co-authored-by:",
|
||||||
|
@ -53,10 +48,6 @@ func NonAsciiMsg(root string) error {
|
||||||
"Reviewed-on:",
|
"Reviewed-on:",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, msg := range msgs {
|
|
||||||
if msg == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Split message by lines and ignore specific lines with prefixes
|
// Split message by lines and ignore specific lines with prefixes
|
||||||
lines := strings.Split(msg, "\n")
|
lines := strings.Split(msg, "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
|
@ -74,14 +65,14 @@ func NonAsciiMsg(root string) error {
|
||||||
// Check for non-ASCII characters in the rest of the lines
|
// Check for non-ASCII characters in the rest of the lines
|
||||||
for _, c := range line {
|
for _, c := range line {
|
||||||
if c > unicode.MaxASCII {
|
if c > unicode.MaxASCII {
|
||||||
nonAsciiMsgs = append(nonAsciiMsgs, msg)
|
isCommitLegal = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if len(nonAsciiMsgs) > 0 {
|
if !isCommitLegal {
|
||||||
return fmt.Errorf("Non-ASCII characters in commit messages:\n%s", strings.Join(nonAsciiMsgs, "\n"))
|
return fmt.Errorf("Non-ASCII characters in commit messages:\n%s", msg)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user