Skip to content

Commit ca7a936

Browse files
authored
Merge pull request cli#594 from alissonbrunosa/pr-list-remove-duplicates
Remove duplicated PRs from GitHub API response.
2 parents 7e3ce60 + 7a0a665 commit ca7a936

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

api/queries_pr.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]
504504
}
505505
}`
506506

507+
var check = make(map[int]struct{})
507508
var prs []PullRequest
508509
pageLimit := min(limit, 100)
509510
variables := map[string]interface{}{}
@@ -576,7 +577,12 @@ loop:
576577
}
577578

578579
for _, edge := range prData.Edges {
580+
if _, exists := check[edge.Node.Number]; exists {
581+
continue
582+
}
583+
579584
prs = append(prs, edge.Node)
585+
check[edge.Node.Number] = struct{}{}
580586
if len(prs) == limit {
581587
break loop
582588
}

command/pr_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,26 @@ No pull requests match your search
240240
eq(t, reqBody.Variables.Labels, []string{"one", "two", "three"})
241241
}
242242

243+
func TestPRList_filteringRemoveDuplicate(t *testing.T) {
244+
initBlankContext("OWNER/REPO", "master")
245+
http := initFakeHTTP()
246+
http.StubRepoResponse("OWNER", "REPO")
247+
248+
jsonFile, _ := os.Open("../test/fixtures/prListWithDuplicates.json")
249+
defer jsonFile.Close()
250+
http.StubResponse(200, jsonFile)
251+
252+
output, err := RunCommand(prListCmd, "pr list -l one,two")
253+
if err != nil {
254+
t.Fatal(err)
255+
}
256+
257+
eq(t, output.String(), `32 New feature feature
258+
29 Fixed bad bug hubot:bug-fix
259+
28 Improve documentation docs
260+
`)
261+
}
262+
243263
func TestPRList_filteringClosed(t *testing.T) {
244264
initBlankContext("OWNER/REPO", "master")
245265
http := initFakeHTTP()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequests": {
5+
"edges": [
6+
{
7+
"node": {
8+
"number": 32,
9+
"title": "New feature",
10+
"url": "https://github.com/monalisa/hello/pull/32",
11+
"headRefName": "feature"
12+
}
13+
},
14+
{
15+
"node": {
16+
"number": 32,
17+
"title": "New feature",
18+
"url": "https://github.com/monalisa/hello/pull/32",
19+
"headRefName": "feature"
20+
}
21+
},
22+
{
23+
"node": {
24+
"number": 29,
25+
"title": "Fixed bad bug",
26+
"url": "https://github.com/monalisa/hello/pull/29",
27+
"headRefName": "bug-fix",
28+
"isCrossRepository": true,
29+
"headRepositoryOwner": {
30+
"login": "hubot"
31+
}
32+
}
33+
},
34+
{
35+
"node": {
36+
"number": 28,
37+
"title": "Improve documentation",
38+
"url": "https://github.com/monalisa/hello/pull/28",
39+
"headRefName": "docs"
40+
}
41+
}
42+
],
43+
"pageInfo": {
44+
"hasNextPage": false,
45+
"endCursor": ""
46+
}
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)