Repository: seachicken/gh-poi
Pull request #28 (2022-01-31 13:32:57)

Fix index out of bounds error
Maybe related to #27

codecov[bot]: # [Codecov](https://codecov.io/gh/seachicken/gh-poi/pull/28?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka) Report
> Merging [#28](https://codecov.io/gh/seachicken/gh-poi/pull/28?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka) (58700c4) into [main](https://codecov.io/gh/seachicken/gh-poi/commit/6b42a8af2907b331c4cd3703ba3aab6ee676cb29?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka) (6b42a8a) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/seachicken/gh-poi/pull/28/graphs/tree.svg?width=650&height=150&src=pr&token=tcPxPgst2q&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka)](https://codecov.io/gh/seachicken/gh-poi/pull/28?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka)

```diff
@@           Coverage Diff           @@
##             main      #28   +/-   ##
=======================================
  Coverage   89.79%   89.79%           
=======================================
  Files           3        3           
  Lines         578      578           
=======================================
  Hits          519      519           
  Misses         46       46           
  Partials       13       13           
```


| [Impacted Files](https://codecov.io/gh/seachicken/gh-poi/pull/28?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka) | Coverage Δ | |
|---|---|---|
| [poi.go](https://codecov.io/gh/seachicken/gh-poi/pull/28/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka#diff-cG9pLmdv) | `91.32% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/seachicken/gh-poi/pull/28?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/seachicken/gh-poi/pull/28?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka). Last update [6b42a8a...58700c4](https://codecov.io/gh/seachicken/gh-poi/pull/28?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Seito+Tanaka).


Patch:
diff --git a/fixtures/gh/pr_mainMerged.json b/fixtures/gh/pr_mainMerged.json
new file mode 100644
index 0000000..a314ea6
--- /dev/null
+++ b/fixtures/gh/pr_mainMerged.json
@@ -0,0 +1,29 @@
+{
+  "data": {
+    "search": {
+      "issueCount": 1,
+      "edges": [
+        {
+          "node": {
+            "number": 1,
+            "url": "https://github.com/owner/repo/pull/1",
+            "state": "MERGED",
+            "headRefName": "main",
+            "commits": {
+              "nodes": [
+                {
+                  "commit": {
+                    "oid": "b6589fc6ab0dc82cf12099d1c2d40ab994e8410c"
+                  }
+                }
+              ]
+            },
+            "author": {
+              "login": "owner"
+            }
+          }
+        }
+      ]
+    }
+  }
+}
\ No newline at end of file
diff --git a/poi.go b/poi.go
index f752699..90c7624 100644
--- a/poi.go
+++ b/poi.go
@@ -304,7 +304,7 @@ func getDeleteStatus(branch Branch, uncommittedChanges string) BranchState {
 }
 
 func isFullyMerged(branch Branch, pr PullRequest) bool {
-	if pr.State != Merged {
+	if pr.State != Merged || len(branch.Commits) == 0 {
 		return false
 	}
 


Test patch:
diff --git a/poi_test.go b/poi_test.go
index 94f294f..f5da772 100644
--- a/poi_test.go
+++ b/poi_test.go
@@ -437,6 +437,52 @@ func Test_ShouldNotDeletableWhenBranchesAssociatedWithNotFullyMergedPR(t *testin
 	}, actual)
 }
 
+func Test_ShouldNotDeletableWhenDefaultBranchAssociatedWithMergedPR(t *testing.T) {
+	ctrl := gomock.NewController(t)
+	defer ctrl.Finish()
+
+	s := connmock.Setup(ctrl).
+		CheckRepos(nil, nil).
+		GetRepoNames("origin", nil, nil).
+		GetBranchNames("@main_issue1", nil, nil).
+		GetLog([]connmock.LogStub{
+			{"main", "main"}, {"issue1", "issue1"},
+		}, nil, nil).
+		GetAssociatedRefNames([]connmock.AssociatedBranchNamesStub{
+			{"356a192b7913b04c54574d18c28d46e6395428ab", "issue1"},
+			{"b6589fc6ab0dc82cf12099d1c2d40ab994e8410c", "main_issue1"},
+		}, nil, nil).
+		GetPullRequests("mainMerged", nil, nil).
+		GetUncommittedChanges("", nil, nil)
+
+	actual, _ := GetBranches(s.Conn, false)
+
+	assert.Equal(t, []Branch{
+		{
+			false, "issue1",
+			[]string{
+				"356a192b7913b04c54574d18c28d46e6395428ab",
+			},
+			[]PullRequest{},
+			NotDeletable,
+		},
+		{
+			true, "main",
+			[]string{},
+			[]PullRequest{
+				{
+					"main", Merged, 1,
+					[]string{
+						"b6589fc6ab0dc82cf12099d1c2d40ab994e8410c",
+					},
+					"https://github.com/owner/repo/pull/1", "owner",
+				},
+			},
+			NotDeletable,
+		},
+	}, actual)
+}
+
 func Test_ReturnsAnErrorWhenGetRepoNamesFails(t *testing.T) {
 	ctrl := gomock.NewController(t)
 	defer ctrl.Finish()