-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
361 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/llorllale/go-gitlint/internal/commits" | ||
"github.com/llorllale/go-gitlint/internal/repo" | ||
) | ||
|
||
// @todo #4 The path should be passed in as a command line | ||
// flag instead of being hard coded. All other configuration | ||
// options should be passed in through CLI as well. | ||
func main() { | ||
panic("not yet implemented") | ||
commits.Printed( | ||
commits.In( | ||
repo.Filesystem("."), | ||
), | ||
os.Stdout, | ||
"\n", | ||
)() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
module github.com/llorllale/go-gitlint | ||
|
||
require ( | ||
github.com/google/uuid v1.1.0 | ||
github.com/stretchr/testify v1.2.2 | ||
gopkg.in/src-d/go-git.v4 v4.10.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= | ||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= | ||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= | ||
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/emirpasic/gods v1.9.0 h1:rUF4PuzEjMChMiNsVjdI+SyLu7rEqpQ5reNFnhC7oFo= | ||
github.com/emirpasic/gods v1.9.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= | ||
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/gliderlabs/ssh v0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw= | ||
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= | ||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= | ||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= | ||
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s= | ||
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= | ||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= | ||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= | ||
github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e h1:RgQk53JHp/Cjunrr1WlsXSZpqXn+uREuHvUVcK82CV8= | ||
github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= | ||
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/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= | ||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= | ||
github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA= | ||
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= | ||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= | ||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= | ||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= | ||
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= | ||
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= | ||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
github.com/xanzy/ssh-agent v0.2.0 h1:Adglfbi5p9Z0BmK2oKU9nTG+zKfniSfnaMYB+ULd+Ro= | ||
github.com/xanzy/ssh-agent v0.2.0/go.mod h1:0NyE30eGUDliuLEHJgYte/zncp2zdTStcOnWhgSqHD8= | ||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= | ||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | ||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= | ||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9 h1:lkiLiLBHGoH3XnqSLUIaBsilGMUjI+Uy2Xu2JLUtTas= | ||
golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
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/src-d/go-billy.v4 v4.2.1 h1:omN5CrMrMcQ+4I8bJ0wEhOBPanIRWzFC953IiXKdYzo= | ||
gopkg.in/src-d/go-billy.v4 v4.2.1/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk= | ||
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1 h1:XWW/s5W18RaJpmo1l0IYGqXKuJITWRFuA45iOf1dKJs= | ||
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= | ||
gopkg.in/src-d/go-git.v4 v4.10.0 h1:NWjTJTQnk8UpIGlssuefyDZ6JruEjo5s88vm88uASbw= | ||
gopkg.in/src-d/go-git.v4 v4.10.0/go.mod h1:Vtut8izDyrM8BUVQnzJ+YvmNcem2J89EmfZYCkLokZk= | ||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= | ||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package commits | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"github.com/llorllale/go-gitlint/internal/repo" | ||
git "gopkg.in/src-d/go-git.v4" | ||
"gopkg.in/src-d/go-git.v4/plumbing/object" | ||
) | ||
|
||
// Commits returns commits. | ||
// @todo #4 Figure out how to disable the golint check that | ||
// forces us to write redundant comments of the form | ||
// 'comment on exported type Commits should be of the form | ||
// "Commits ..." (with optional leading article)' and rewrite | ||
// all comments. | ||
type Commits func() []*Commit | ||
|
||
// Commit holds data for a single git commit. | ||
type Commit struct { | ||
Hash string | ||
Subject string | ||
Body string | ||
} | ||
|
||
// In returns the commits in the repo. | ||
// @todo #4 These err checks are extremely annoying. Figure out | ||
// how to handle them elegantly and reduce the cyclo complexity | ||
// of this function (currently at 4). | ||
func In(repository repo.Repo) Commits { | ||
return func() []*Commit { | ||
r := repository() | ||
ref, err := r.Head() | ||
if err != nil { | ||
panic(err) | ||
} | ||
iter, err := r.Log(&git.LogOptions{From: ref.Hash()}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
commits := make([]*Commit, 0) | ||
_ = iter.ForEach(func(c *object.Commit) error { //nolint[errcheck] | ||
commits = append( | ||
commits, | ||
&Commit{ | ||
Hash: c.Hash.String(), | ||
// @todo #4 Figure out how to split the commit's message into a subject | ||
// and a body. I believe the separator is the first instance of the | ||
// CRLFCRLF sequence. | ||
Subject: "don't know", | ||
Body: c.Message, | ||
}, | ||
) | ||
return nil | ||
}) | ||
return commits | ||
} | ||
} | ||
|
||
// Printed prints the commits to the file. | ||
func Printed(commits Commits, writer io.Writer, sep string) Commits { | ||
return func() []*Commit { | ||
input := commits() | ||
for _, c := range input { | ||
_, err := writer.Write( | ||
[]byte(fmt.Sprintf("%s%s", &pretty{c}, sep)), | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
return input | ||
} | ||
} | ||
|
||
// a Stringer for pretty-printing the commit. | ||
type pretty struct { | ||
*Commit | ||
} | ||
|
||
func (p *pretty) String() string { | ||
return fmt.Sprintf( | ||
"hash: %s subject=%s body=%s", | ||
p.Commit.Hash, p.Commit.Subject, p.Commit.Body, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package commits | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/llorllale/go-gitlint/internal/repo" | ||
"github.com/stretchr/testify/assert" | ||
git "gopkg.in/src-d/go-git.v4" | ||
"gopkg.in/src-d/go-git.v4/plumbing/object" | ||
) | ||
|
||
func TestIn(t *testing.T) { | ||
msgs := []string{"commit1", "commit2", "commit3"} | ||
r, cleanup := tmpRepo(msgs...) | ||
defer cleanup() | ||
commits := In(r)() | ||
assert.Len(t, commits, len(msgs), | ||
"commits.In() did not return the correct number of commits") | ||
for i, msg := range msgs { | ||
assert.Equal(t, msg, commits[len(commits)-i-1].Body, | ||
"commits.In() returned commits with incorrect body messages") | ||
} | ||
} | ||
|
||
func TestPrinted(t *testing.T) { | ||
commit := &Commit{ | ||
Hash: "abc123", | ||
Subject: "subject", | ||
Body: "body", | ||
} | ||
const sep = " " | ||
buffer := &bytes.Buffer{} | ||
_ = Printed( | ||
func() []*Commit { return []*Commit{commit} }, | ||
buffer, | ||
sep, | ||
)() | ||
assert.Equal(t, (&pretty{commit}).String()+sep, string(buffer.Bytes()), | ||
"commits.Printed() did not pretty-print the commit correctly") | ||
} | ||
|
||
// A git repo initialized and with one commit per each of the messages provided. | ||
// This repo is created in a temporary directory; use the cleanup function | ||
// to delete it afterwards. | ||
func tmpRepo(msgs ...string) (r repo.Repo, cleanup func()) { | ||
folder, err := ioutil.TempDir( | ||
"", | ||
strings.Replace(uuid.New().String(), "-", "", -1), //nolint[gocritic] | ||
) | ||
panicIf(err) | ||
cleanup = func() { | ||
panicIf(os.RemoveAll(folder)) | ||
} | ||
r = func() *git.Repository { | ||
r, err := git.PlainInit(folder, false) | ||
panicIf(err) | ||
wt, err := r.Worktree() | ||
panicIf(err) | ||
for i, msg := range msgs { | ||
file := fmt.Sprintf("msg%d.txt", i) | ||
panicIf(ioutil.WriteFile(filepath.Join(folder, file), []byte(msg), 0644)) | ||
_, err = wt.Add(file) | ||
panicIf(err) | ||
_, err = wt.Commit(msg, &git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: "John Doe", | ||
Email: "[email protected]", | ||
When: time.Now(), | ||
}, | ||
}) | ||
panicIf(err) | ||
} | ||
return r | ||
} | ||
return r, cleanup | ||
} | ||
|
||
// panics if err is not nil. | ||
func panicIf(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package repo | ||
|
||
import ( | ||
git "gopkg.in/src-d/go-git.v4" | ||
) | ||
|
||
// Repo is an initialized git repository. | ||
type Repo func() *git.Repository | ||
|
||
// Filesystem is a pre-existing git repository on the filesystem | ||
// with directory as root. | ||
func Filesystem(directory string) Repo { | ||
return func() *git.Repository { | ||
repo, err := git.PlainOpen(directory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return repo | ||
} | ||
} |
Oops, something went wrong.
2738cc2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
4-2f6700f4
discovered incmd/go-gitlint/main.go
and submitted as #9. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.2738cc2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
4-dc893088
discovered ininternal/commits/commits.go
and submitted as #10. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.2738cc2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
4-faa799fb
discovered ininternal/commits/commits.go
and submitted as #11. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.2738cc2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
4-03485093
discovered ininternal/commits/commits.go
and submitted as #12. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.