diff --git a/api/queries_pr.go b/api/queries_pr.go index 265378b1e..34884d16f 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -504,6 +504,7 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([] } }` + var check = make(map[int]struct{}) var prs []PullRequest pageLimit := min(limit, 100) variables := map[string]interface{}{} @@ -576,7 +577,12 @@ loop: } for _, edge := range prData.Edges { + if _, exists := check[edge.Node.Number]; exists { + continue + } + prs = append(prs, edge.Node) + check[edge.Node.Number] = struct{}{} if len(prs) == limit { break loop } diff --git a/command/pr_test.go b/command/pr_test.go index 51469342a..395dd4097 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -240,6 +240,26 @@ No pull requests match your search eq(t, reqBody.Variables.Labels, []string{"one", "two", "three"}) } +func TestPRList_filteringRemoveDuplicate(t *testing.T) { + initBlankContext("OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prListWithDuplicates.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prListCmd, "pr list -l one,two") + if err != nil { + t.Fatal(err) + } + + eq(t, output.String(), `32 New feature feature +29 Fixed bad bug hubot:bug-fix +28 Improve documentation docs +`) +} + func TestPRList_filteringClosed(t *testing.T) { initBlankContext("OWNER/REPO", "master") http := initFakeHTTP() diff --git a/test/fixtures/prListWithDuplicates.json b/test/fixtures/prListWithDuplicates.json new file mode 100644 index 000000000..a84800f72 --- /dev/null +++ b/test/fixtures/prListWithDuplicates.json @@ -0,0 +1,50 @@ +{ + "data": { + "repository": { + "pullRequests": { + "edges": [ + { + "node": { + "number": 32, + "title": "New feature", + "url": "https://github.com/monalisa/hello/pull/32", + "headRefName": "feature" + } + }, + { + "node": { + "number": 32, + "title": "New feature", + "url": "https://github.com/monalisa/hello/pull/32", + "headRefName": "feature" + } + }, + { + "node": { + "number": 29, + "title": "Fixed bad bug", + "url": "https://github.com/monalisa/hello/pull/29", + "headRefName": "bug-fix", + "isCrossRepository": true, + "headRepositoryOwner": { + "login": "hubot" + } + } + }, + { + "node": { + "number": 28, + "title": "Improve documentation", + "url": "https://github.com/monalisa/hello/pull/28", + "headRefName": "docs" + } + } + ], + "pageInfo": { + "hasNextPage": false, + "endCursor": "" + } + } + } + } +}