-
Notifications
You must be signed in to change notification settings - Fork 36
Fix GetChanges issue with changes in both sides #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
// +build integration | ||
|
||
package server_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
fixtures "github.com/src-d/lookout-test-fixtures" | ||
"gopkg.in/src-d/lookout-sdk.v0/pb" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
func TestReviewOnlyPrChangesIntegrationSuite(t *testing.T) { | ||
suite.Run(t, new(reviewOnlyPrChangesIntegrationSuite)) | ||
} | ||
|
||
type reviewOnlyPrChangesIntegrationSuite struct { | ||
IntegrationSuite | ||
} | ||
|
||
func (suite *reviewOnlyPrChangesIntegrationSuite) SetupTest() { | ||
suite.ResetDB() | ||
|
||
suite.StoppableCtx() | ||
suite.r, suite.w = suite.StartLookoutd(dummyConfigFile) | ||
|
||
suite.StartDummy("--files") | ||
suite.GrepTrue(suite.r, `msg="connection state changed to 'READY'" addr="ipv4://localhost:9930" analyzer=Dummy`) | ||
} | ||
|
||
func (suite *reviewOnlyPrChangesIntegrationSuite) TearDownTest() { | ||
// TODO: for integration tests with RabbitMQ we wait a bit so the queue | ||
// is depleted. Ideally this would be done with something similar to ResetDB | ||
time.Sleep(5 * time.Second) | ||
suite.Stop() | ||
} | ||
|
||
func (suite *reviewOnlyPrChangesIntegrationSuite) TestAnalyzerErr() { | ||
fixtures := fixtures.GetByName("get-changes-from-outdated-pr") | ||
jsonReviewEvent := &jsonReviewEvent{ | ||
ReviewEvent: &pb.ReviewEvent{ | ||
InternalID: "1", | ||
Number: 1, | ||
CommitRevision: *fixtures.GetCommitRevision(), | ||
}, | ||
} | ||
|
||
expectedComments := []string{ | ||
`{"analyzer-name":"Dummy","file":"javascript.js",`, | ||
`status=success`, | ||
} | ||
notExpectedComments := []string{ | ||
`{"analyzer-name":"Dummy","file":"golang.go",`, | ||
} | ||
|
||
suite.sendEvent(jsonReviewEvent.String()) | ||
suite.GrepAndNotAll(suite.r, expectedComments, notExpectedComments) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,181 @@ | ||
package merge_base | ||
dpordomingo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"io" | ||
|
||
"gopkg.in/src-d/go-git.v4/plumbing" | ||
"gopkg.in/src-d/go-git.v4/plumbing/object" | ||
"gopkg.in/src-d/go-git.v4/plumbing/storer" | ||
) | ||
|
||
// NewFilterCommitIter returns a CommitIter that walks the commit history, | ||
// starting at the passed commit and visiting its parents in Breadth-first order. | ||
// The commits returned by the CommitIter will validate the passed CommitFilter. | ||
// The history won't be transversed beyond a commit if isLimit is true for it. | ||
// Each commit will be visited only once. | ||
// If the commit history can not be traversed, or the Close() method is called, | ||
// the CommitIter won't return more commits. | ||
// If no isValid is passed, all ancestors of from commit will be valid. | ||
// If no isLimit is limmit, all ancestors of all commits will be visited. | ||
func NewFilterCommitIter( | ||
// REVIEWER: store argument wouldn't be needed if this were part of go-git/plumbing/object package | ||
store storer.EncodedObjectStorer, | ||
from *object.Commit, | ||
isValid *CommitFilter, | ||
isLimit *CommitFilter, | ||
) object.CommitIter { | ||
var validFilter CommitFilter | ||
if isValid == nil { | ||
validFilter = func(_ *object.Commit) bool { | ||
return true | ||
} | ||
} else { | ||
validFilter = *isValid | ||
} | ||
|
||
var limitFilter CommitFilter | ||
if isLimit == nil { | ||
limitFilter = func(_ *object.Commit) bool { | ||
return false | ||
} | ||
} else { | ||
limitFilter = *isLimit | ||
} | ||
|
||
return &filterCommitIter{ | ||
// REVIEWER: store wouldn't be needed if this were part of go-git/plumbing/object package | ||
store: store, | ||
isValid: validFilter, | ||
isLimit: limitFilter, | ||
visited: map[plumbing.Hash]bool{}, | ||
queue: []*object.Commit{from}, | ||
} | ||
} | ||
|
||
// CommitFilter returns a boolean for the passed Commit | ||
type CommitFilter func(*object.Commit) bool | ||
|
||
// filterCommitIter implments object.CommitIter | ||
type filterCommitIter struct { | ||
// REVIEWER: store wouldn't be needed if this were part of go-git/plumbing/object package | ||
store storer.EncodedObjectStorer | ||
isValid CommitFilter | ||
isLimit CommitFilter | ||
visited map[plumbing.Hash]bool | ||
queue []*object.Commit | ||
lastErr error | ||
} | ||
|
||
// Next returns the next commit of the CommitIter. | ||
// It will return io.EOF if there are no more commits to visit, | ||
// or an error if the history could not be traversed. | ||
func (w *filterCommitIter) Next() (*object.Commit, error) { | ||
var commit *object.Commit | ||
var err error | ||
for { | ||
commit, err = w.popNewFromQueue() | ||
if err != nil { | ||
return nil, w.close(err) | ||
} | ||
|
||
w.visited[commit.Hash] = true | ||
|
||
if !w.isLimit(commit) { | ||
// REVIEWER: first argument would be commit.s if this were part of object.Commit | ||
err = w.addToQueue(w.store, commit.ParentHashes...) | ||
if err != nil { | ||
return nil, w.close(err) | ||
} | ||
} | ||
|
||
if w.isValid(commit) { | ||
return commit, nil | ||
} | ||
} | ||
} | ||
|
||
// ForEach runs the passed callback over each Commit returned by the CommitIter | ||
// until the callback returns an error or there is no more commits to traverse. | ||
func (w *filterCommitIter) ForEach(cb func(*object.Commit) error) error { | ||
for { | ||
commit, err := w.Next() | ||
if err == io.EOF { | ||
break | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := cb(commit); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Error returns the error that caused that the CommitIter is no longer returning commits | ||
func (w *filterCommitIter) Error() error { | ||
return w.lastErr | ||
} | ||
|
||
// Close closes the CommitIter | ||
func (w *filterCommitIter) Close() { | ||
w.visited = map[plumbing.Hash]bool{} | ||
w.queue = []*object.Commit{} | ||
w.isLimit = nil | ||
w.isValid = nil | ||
} | ||
|
||
// close closes the CommitIter with an error | ||
func (w *filterCommitIter) close(err error) error { | ||
w.Close() | ||
w.lastErr = err | ||
return err | ||
} | ||
|
||
// popNewFromQueue returns the first new commit from the internal fifo queue, or | ||
// an io.EOF error if the queue is empty | ||
func (w *filterCommitIter) popNewFromQueue() (*object.Commit, error) { | ||
var first *object.Commit | ||
for { | ||
if len(w.queue) == 0 { | ||
if w.lastErr != nil { | ||
return nil, w.lastErr | ||
} | ||
|
||
return nil, io.EOF | ||
} | ||
|
||
first = w.queue[0] | ||
w.queue = w.queue[1:] | ||
if w.visited[first.Hash] { | ||
continue | ||
} | ||
|
||
return first, nil | ||
} | ||
} | ||
|
||
// addToQueue adds the passed commits to the internal fifo queue if they weren'r already seen | ||
// or returns an error if the passed hashes could not be used to get valid commits | ||
func (w *filterCommitIter) addToQueue( | ||
store storer.EncodedObjectStorer, | ||
hashes ...plumbing.Hash, | ||
) error { | ||
for _, hash := range hashes { | ||
if w.visited[hash] { | ||
continue | ||
} | ||
|
||
commit, err := object.GetCommit(store, hash) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
w.queue = append(w.queue, commit) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.