Skip to content

Commit dcedacd

Browse files
Remove duplicates
1 parent d4cb2d8 commit dcedacd

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

api/queries_pr.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,21 @@ loop:
590590
}
591591
}
592592

593-
return prs, nil
593+
return removeDuplicates(prs), nil
594+
}
595+
596+
func removeDuplicates(prs []PullRequest) []PullRequest {
597+
var check = make(map[int]struct{})
598+
var uniqPRs []PullRequest
599+
600+
for _, pr := range prs {
601+
if _, ok := check[pr.Number]; !ok {
602+
check[pr.Number] = struct{}{}
603+
uniqPRs = append(uniqPRs, pr)
604+
}
605+
}
606+
607+
return uniqPRs
594608
}
595609

596610
func min(a, b int) int {

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)