Skip to content

Commit

Permalink
fix(policy): use natural language processing for imperative check
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Rynhard <[email protected]>
  • Loading branch information
andrewrynhard committed Jan 21, 2019
1 parent 5c6620a commit c8391b9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 338 deletions.
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 // indirect
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/fsnotify/fsnotify v1.4.2 // indirect
github.com/gliderlabs/ssh v0.1.1 // indirect
Expand All @@ -12,11 +13,13 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v0.0.0-20170525151105-fa48d7ff1cfb // indirect
github.com/kljensen/snowball v0.6.0
github.com/kr/pretty v0.1.0 // indirect
github.com/magiconair/properties v1.7.2 // indirect
github.com/mingrammer/commonregex v1.0.0 // indirect
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992
github.com/montanaflynn/stats v0.5.0 // indirect
github.com/neurosnap/sentences v1.0.6 // indirect
github.com/pelletier/go-buffruneio v0.2.0 // indirect
github.com/pelletier/go-toml v1.0.0 // indirect
github.com/pkg/errors v0.8.0
Expand All @@ -35,7 +38,11 @@ require (
golang.org/x/net v0.0.0-20170629171032-1f9224279e98 // indirect
golang.org/x/sys v0.0.0-20170703210155-94b76065f2d2 // indirect
golang.org/x/text v0.0.0-20170630100924-2bf8f2a19ec0 // indirect
gonum.org/v1/gonum v0.0.0-20190119014124-d54847ab4dca // indirect
gonum.org/v1/netlib v0.0.0-20190119082159-9be13e02fd56 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/jdkato/prose.v2 v2.0.0-20180825173540-767a23049b9e
gopkg.in/neurosnap/sentences.v1 v1.0.6 // indirect
gopkg.in/src-d/go-billy.v4 v4.0.1 // indirect
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1 // indirect
gopkg.in/src-d/go-git.v4 v4.0.0
Expand Down
21 changes: 19 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fsnotify/fsnotify v1.4.2 h1:v5tKwtf2hNhBV24eNYfQ5UmvFOGlOCmRqk7/P1olxtk=
Expand All @@ -20,19 +22,23 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/kevinburke/ssh_config v0.0.0-20170525151105-fa48d7ff1cfb h1:4qB7kGgjot2tlCOW66sJ+ai5tv81oIDM9t6cvyFTKLM=
github.com/kevinburke/ssh_config v0.0.0-20170525151105-fa48d7ff1cfb/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kljensen/snowball v0.6.0 h1:6DZLCcZeL0cLfodx+Md4/OLC6b/bfurWUOUGs1ydfOU=
github.com/kljensen/snowball v0.6.0/go.mod h1:27N7E8fVU5H68RlUmnWwZCfxgt4POBJfENGMvNRhldw=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.7.2 h1:de14gtQSJmD380aERiT7g/BPsA0iDosrVRaU+EhZAio=
github.com/magiconair/properties v1.7.2/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mingrammer/commonregex v1.0.0 h1:0nTEyFI+CKWog0IWbyP8jFwgdd+JZ30UYfYce/lG/9w=
github.com/mingrammer/commonregex v1.0.0/go.mod h1:GQen+jIfhWmXmDCzNk4ucLO8VUMxJO5QPWZ2RPwrS3A=
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 h1:eQox4Rh4ewJF+mqYPxCkmBAirRnPaHEB26UkNuPyjlk=
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992 h1:W7VHAEVflA5/eTyRvQ53Lz5j8bhRd1myHZlI/IZFvbU=
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/montanaflynn/stats v0.5.0 h1:2EkzeTSqBB4V4bJwWrt5gIIrZmpJBcoIRGS2kWLgzmk=
github.com/montanaflynn/stats v0.5.0/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/neurosnap/sentences v1.0.6 h1:iBVUivNtlwGkYsJblWV8GGVFmXzZzak907Ci8aA0VTE=
github.com/neurosnap/sentences v1.0.6/go.mod h1:pg1IapvYpWCJJm/Etxeh0+gtMf1rI1STY9S7eUCPbDc=
github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/pelletier/go-toml v1.0.0 h1:QFDlmAXZrfPXEF6c9+15fMqhQIS3O0pxszhnk936vg4=
Expand Down Expand Up @@ -63,14 +69,25 @@ github.com/xanzy/ssh-agent v0.1.0 h1:lOhdXLxtmYjaHc76ZtNmJWPg948y/RnT+3N3cvKWFzY
github.com/xanzy/ssh-agent v0.1.0/go.mod h1:0NyE30eGUDliuLEHJgYte/zncp2zdTStcOnWhgSqHD8=
golang.org/x/crypto v0.0.0-20170703161049-69be088f8606 h1:i72l9b8scUpp6IdZyG/amRbdITs8cYMY5HnSypqSt5I=
golang.org/x/crypto v0.0.0-20170703161049-69be088f8606/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de h1:xSjD6HQTqT0H/k60N5yYBtnN1OEkVy7WIo/DYyxKRO0=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/net v0.0.0-20170629171032-1f9224279e98 h1:7wZTjEl3uuLKP9GWY+XYHTXYLUtBChvsVHCNZBouFMA=
golang.org/x/net v0.0.0-20170629171032-1f9224279e98/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20170703210155-94b76065f2d2 h1:t5pPVtKY5FQGuFxgVhQzf4GN4yt7pMhcjKkJ6NIB5Ec=
golang.org/x/sys v0.0.0-20170703210155-94b76065f2d2/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.0.0-20170630100924-2bf8f2a19ec0 h1:M4kywXOhV3F38kTr0IZZYueKhR5dVnpaVmGSeYrklJY=
golang.org/x/text v0.0.0-20170630100924-2bf8f2a19ec0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gonum.org/v1/gonum v0.0.0-20190119014124-d54847ab4dca h1:n0S76j3sXlixKdU/XYIBVb1s3hPsZCiZ+oQmPH+r3gQ=
gonum.org/v1/gonum v0.0.0-20190119014124-d54847ab4dca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/netlib v0.0.0-20190119082159-9be13e02fd56 h1:sWo7pRubEwovyVnbgs3VJpe4ppUGSLbu/zNPyCBXtHE=
gonum.org/v1/netlib v0.0.0-20190119082159-9be13e02fd56/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/jdkato/prose.v2 v2.0.0-20180825173540-767a23049b9e h1:yDDVJ347kU7Ro+H2CRgKmAEbFXfHwjyPuXgVd6H+3N8=
gopkg.in/jdkato/prose.v2 v2.0.0-20180825173540-767a23049b9e/go.mod h1:1uCyb8jSeRMeIfMJgVyxYssmCTAlxLBkueX+Iu2UilA=
gopkg.in/neurosnap/sentences.v1 v1.0.6 h1:v7ElyP020iEZQONyLld3fHILHWOPs+ntzuQTNPkul8E=
gopkg.in/neurosnap/sentences.v1 v1.0.6/go.mod h1:YlK+SN+fLQZj+kY3r8DkGDhDr91+S3JmTb5LSxFRQo0=
gopkg.in/src-d/go-billy.v4 v4.0.1 h1:iMxwQPj2cuKRyaIZ985zxClkcdTtT5VpXYf4PTJc0Ek=
gopkg.in/src-d/go-billy.v4 v4.0.1/go.mod h1:ZHSF0JP+7oD97194otDUCD7Ofbk63+xFcfWP5bT6h+Q=
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1 h1:XWW/s5W18RaJpmo1l0IYGqXKuJITWRFuA45iOf1dKJs=
Expand Down
84 changes: 0 additions & 84 deletions internal/policy/commit/blacklist.go

This file was deleted.

25 changes: 10 additions & 15 deletions internal/policy/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/autonomy/conform/internal/git"
"github.com/autonomy/conform/internal/policy"
"github.com/kljensen/snowball"
"github.com/pkg/errors"
prose "gopkg.in/jdkato/prose.v2"
)

// Commit implements the policy.Policy interface and enforces commit
Expand Down Expand Up @@ -159,23 +159,18 @@ func ValidateGPGSign(report *policy.Report, g *git.Git) {

// ValidateImperative checks the commit message for a GPG signature.
func ValidateImperative(report *policy.Report, word string) {
word = strings.ToLower(word)
for _, good := range WhiteList {
stemmed, err := snowball.Stem(good, "english", true)
if err != nil {
report.Errors = append(report.Errors, errors.Errorf("Error checking for imperative mood: %v", err))
}
if word == stemmed {
return
}
doc, _ := prose.NewDocument("I " + word)
if len(doc.Tokens()) != 2 {
report.Errors = append(report.Errors, errors.Errorf("Expected 2 words, got %d", len(doc.Tokens())))
return
}
for _, bad := range BlackList {
if word == bad {
report.Errors = append(report.Errors, errors.Errorf("Use of blacklisted imperative verb: %s", word))
return
tokens := doc.Tokens()
tok := tokens[1]
for _, tag := range []string{"VBD", "VBG", "VBZ"} {
if tok.Tag == tag {
report.Errors = append(report.Errors, errors.Errorf("First word of commit must be an imperative verb: %q", word))
}
}
report.Errors = append(report.Errors, errors.Errorf("Commit does not have imperative mood"))
}

// ValidateType returns the commit type.
Expand Down
Loading

0 comments on commit c8391b9

Please sign in to comment.