Skip to content

Commit

Permalink
Improve association of local branches with PR (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
seachicken authored Jan 23, 2022
1 parent 50c964d commit f583e8f
Show file tree
Hide file tree
Showing 18 changed files with 572 additions and 59 deletions.
42 changes: 37 additions & 5 deletions connmock/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ type (
Conf struct {
Times *Times
}

AssociatedBranchNamesStub struct {
Oid string
Filename string
}

LogStub struct {
BranchName string
Filename string
}
)

var (
Expand Down Expand Up @@ -74,6 +84,32 @@ func (s *Stub) GetBranchNames(name string, err error, conf *Conf) *Stub {
return s
}

func (s *Stub) GetAssociatedBranchNames(stubs []AssociatedBranchNamesStub, err error, conf *Conf) *Stub {
s.t.Helper()
for _, stub := range stubs {
configure(
s.Conn.EXPECT().
GetAssociatedBranchNames(stub.Oid).
Return(s.readFile("git", "abranch", stub.Filename), err),
conf,
)
}
return s
}

func (s *Stub) GetLog(stubs []LogStub, err error, conf *Conf) *Stub {
s.t.Helper()
for _, stub := range stubs {
configure(
s.Conn.EXPECT().
GetLog(stub.BranchName).
Return(s.readFile("git", "log", stub.Filename), err),
conf,
)
}
return s
}

func (s *Stub) GetPullRequests(path string, err error, conf *Conf) *Stub {
s.t.Helper()
configure(
Expand All @@ -99,11 +135,7 @@ func (s *Stub) DeleteBranches(err error, conf *Conf) *Stub {
}

func configure(call *gomock.Call, conf *Conf) {
if conf == nil {
return
}

if conf.Times == nil {
if conf == nil || conf.Times == nil {
call.AnyTimes()
} else {
call.Times(conf.Times.N)
Expand Down
9 changes: 9 additions & 0 deletions fixtures/gh/pr_issue1Closed.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"url": "https://github.com/owner/repo/pull/1",
"state": "CLOSED",
"headRefName": "issue1",
"commits": {
"nodes": [
{
"commit": {
"oid": "356a192b7913b04c54574d18c28d46e6395428ab"
}
}
]
},
"author": {
"login": "owner"
}
Expand Down
9 changes: 9 additions & 0 deletions fixtures/gh/pr_issue1Merged.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"url": "https://github.com/owner/repo/pull/1",
"state": "MERGED",
"headRefName": "issue1",
"commits": {
"nodes": [
{
"commit": {
"oid": "356a192b7913b04c54574d18c28d46e6395428ab"
}
}
]
},
"author": {
"login": "owner"
}
Expand Down
18 changes: 18 additions & 0 deletions fixtures/gh/pr_issue1Merged_issue1Closed.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"url": "https://github.com/owner/repo/pull/1",
"state": "CLOSED",
"headRefName": "issue1",
"commits": {
"nodes": [
{
"commit": {
"oid": "356a192b7913b04c54574d18c28d46e6395428ab"
}
}
]
},
"author": {
"login": "owner"
}
Expand All @@ -20,6 +29,15 @@
"url": "https://github.com/owner/repo/pull/2",
"state": "MERGED",
"headRefName": "issue1",
"commits": {
"nodes": [
{
"commit": {
"oid": "356a192b7913b04c54574d18c28d46e6395428ab"
}
}
]
},
"author": {
"login": "owner"
}
Expand Down
9 changes: 9 additions & 0 deletions fixtures/gh/pr_issue1UpMerged.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"url": "https://github.com/parent-owner/repo/pull/1",
"state": "MERGED",
"headRefName": "issue1",
"commits": {
"nodes": [
{
"commit": {
"oid": "356a192b7913b04c54574d18c28d46e6395428ab"
}
}
]
},
"author": {
"login": "owner"
}
Expand Down
1 change: 1 addition & 0 deletions fixtures/git/abranch_issue1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
issue1
1 change: 1 addition & 0 deletions fixtures/git/abranch_main.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
2 changes: 2 additions & 0 deletions fixtures/git/abranch_main_issue1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
issue1
main
1 change: 0 additions & 1 deletion fixtures/git/branch_main_@issue1.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*,issue1,356a192b7913b04c54574d18c28d46e6395428ab
,main,b6589fc6ab0dc82cf12099d1c2d40ab994e8410c

2 changes: 2 additions & 0 deletions fixtures/git/log_issue1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
356a192b7913b04c54574d18c28d46e6395428ab
b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
3 changes: 3 additions & 0 deletions fixtures/git/log_issue1CommitAfterMerge.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
b8a2645298053fb62ea03e27feea6c483d3fd27e
356a192b7913b04c54574d18c28d46e6395428ab
b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
1 change: 1 addition & 0 deletions fixtures/git/log_main.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
2 changes: 2 additions & 0 deletions fixtures/git/log_main_issue1Merged.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cb197ba87e4ad323b1008c611212deb7da2a4a49
b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
30 changes: 30 additions & 0 deletions mocks/poi_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f583e8f

Please sign in to comment.