Repository: seachicken/gh-poi (go)

Issue:
Duplicate PRs related to the branch
**Describe the bug**
Sometimes it will look like this.

e.g.
```sh
Deleted branches
  issue1
    ├─ #1  https://github.com/owner/repo/pull/1 seito-tanaka
    └─ #1  https://github.com/owner/repo/pull/1 seito-tanaka
```

**Your Environment**
 - OS: macOS Catalina
 - gh --version: 2.2.0



Pull request:
Fix the fetched PRs duplication
Fixes #15 

Patch:
diff --git a/fixtures/gh/repo_origin.json b/fixtures/gh/repo_origin.json
index c4a7d13..1ae934f 100644
--- a/fixtures/gh/repo_origin.json
+++ b/fixtures/gh/repo_origin.json
@@ -1,4 +1,7 @@
 {
+  "defaultBranchRef": {
+    "name": "main"
+  },
   "name": "repo",
   "owner": {
     "id": "1",
@@ -6,4 +9,4 @@
   },
   "parent": null,
   "url": "https://github.com/owner/repo"
-}
\ No newline at end of file
+}
diff --git a/fixtures/gh/repo_origin_upstream.json b/fixtures/gh/repo_origin_upstream.json
index 610176c..10dd8f9 100644
--- a/fixtures/gh/repo_origin_upstream.json
+++ b/fixtures/gh/repo_origin_upstream.json
@@ -1,4 +1,7 @@
 {
+  "defaultBranchRef": {
+    "name": "main"
+  },
   "name": "repo",
   "owner": {
     "id": "1",
@@ -13,4 +16,4 @@
     }
   },
   "url": "https://github.com/owner/repo"
-}
\ No newline at end of file
+}
diff --git a/poi.go b/poi.go
index 8c81f3a..18362ec 100644
--- a/poi.go
+++ b/poi.go
@@ -69,8 +69,9 @@ var ErrNotFound = errors.New("not found")
 func GetBranches(conn Connection) ([]Branch, error) {
 	var hostname string
 	var repoNames []string
+	var defaultBranchName string
 	if json, err := conn.GetRepoNames(); err == nil {
-		hostname, repoNames, _ = getRepo(json)
+		hostname, repoNames, defaultBranchName, _ = getRepo(json)
 	} else {
 		return nil, err
 	}
@@ -88,7 +89,7 @@ func GetBranches(conn Connection) ([]Branch, error) {
 	}
 
 	prs := []PullRequest{}
-	for _, queryHashes := range GetQueryHashes(branches) {
+	for _, queryHashes := range GetQueryHashes(branches, defaultBranchName) {
 		json, err := conn.GetPullRequests(hostname, repoNames, queryHashes)
 		if err != nil {
 			return nil, err
@@ -180,8 +181,11 @@ func toBranch(branchNames []string) []Branch {
 	return results
 }
 
-func getRepo(jsonResp string) (string, []string, error) {
+func getRepo(jsonResp string) (string, []string, string, error) {
 	type response struct {
+		DefaultBranchRef struct {
+			Name string
+		}
 		Name  string
 		Owner struct {
 			Login string
@@ -191,13 +195,14 @@ func getRepo(jsonResp string) (string, []string, error) {
 			Owner struct {
 				Login string
 			}
+			DefaultBranchName string
 		}
 		Url string
 	}
 
 	var resp response
 	if err := json.Unmarshal([]byte(jsonResp), &resp); err != nil {
-		return "", nil, fmt.Errorf("error unmarshaling response: %w", err)
+		return "", nil, "", fmt.Errorf("error unmarshaling response: %w", err)
 	}
 
 	repoNames := []string{
@@ -207,7 +212,7 @@ func getRepo(jsonResp string) (string, []string, error) {
 		repoNames = append(repoNames, resp.Parent.Owner.Login+"/"+resp.Parent.Name)
 	}
 
-	return getHostname(resp.Url), repoNames, nil
+	return getHostname(resp.Url), repoNames, resp.DefaultBranchRef.Name, nil
 }
 
 func getHostname(url string) string {
@@ -342,6 +347,7 @@ func (conn *ConnectionImpl) GetRepoNames() (string, error) {
 		"--json", "owner",
 		"--json", "name",
 		"--json", "parent",
+		"--json", "defaultBranchRef",
 	}
 	return run("gh", args)
 }
diff --git a/querygen.go b/querygen.go
index 156f3de..457ae81 100644
--- a/querygen.go
+++ b/querygen.go
@@ -5,11 +5,15 @@ import (
 	"strings"
 )
 
-func GetQueryHashes(branches []Branch) []string {
+func GetQueryHashes(branches []Branch, defaultBranchName string) []string {
 	results := []string{}
 
 	var hashes strings.Builder
 	for i, branch := range branches {
+		if branch.Name == defaultBranchName {
+			continue
+		}
+
 		separator := " "
 		if i == len(branches)-1 {
 			separator = ""


Test patch:
diff --git a/querygen_test.go b/querygen_test.go
index a6725cb..b8a5380 100644
--- a/querygen_test.go
+++ b/querygen_test.go
@@ -17,11 +17,12 @@ func Test_GetQueryHashes(t *testing.T) {
 			"hash:c1dfd96eea8cc2b62785275bca38ac261256e278",
 		},
 		GetQueryHashes([]Branch{
-			{false, "issue1", "356a192b7913b04c54574d18c28d46e6395428ab", []PullRequest{}, Unknown},
+			{false, "main", "b28b7af69320201d1cf206ebf28373980add1451", []PullRequest{}, Unknown},
+			{true, "issue1", "356a192b7913b04c54574d18c28d46e6395428ab", []PullRequest{}, Unknown},
 			{false, "issue2", "da4b9237bacccdf19c0760cab7aec4a8359010b0", []PullRequest{}, Unknown},
 			{false, "issue3", "77de68daecd823babbb58edb1c8e14d7106e83bb", []PullRequest{}, Unknown},
 			{false, "issue4", "1b6453892473a467d07372d45eb05abc2031647a", []PullRequest{}, Unknown},
 			{false, "issue5", "ac3478d69a3c81fa62e60f5c3696165a4e5e6ac4", []PullRequest{}, Unknown},
 			{false, "issue6", "c1dfd96eea8cc2b62785275bca38ac261256e278", []PullRequest{}, Unknown},
-		}))
+		}, "main"))
 }