Skip to content

Commit 76e8cce

Browse files
committed
Able to detect get PR info for same repository
1 parent a244fe9 commit 76e8cce

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

git.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.2.8"
13+
const _VERSION = "0.2.9"
1414

1515
func Version() string {
1616
return _VERSION

repo_pull.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,22 @@ func (repo *Repository) GetMergeBase(base, head string) (string, error) {
2828
// GetPullRequestInfo generates and returns pull request information
2929
// between base and head branches of repositories.
3030
func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error) {
31-
// Add a temporary remote
32-
tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10)
33-
if err = repo.AddRemote(tmpRemote, basePath, true); err != nil {
34-
return nil, fmt.Errorf("AddRemote: %v", err)
31+
var remoteBranch string
32+
33+
// We don't need a temporary remote for same repository.
34+
if repo.Path != basePath {
35+
// Add a temporary remote
36+
tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10)
37+
if err = repo.AddRemote(tmpRemote, basePath, true); err != nil {
38+
return nil, fmt.Errorf("AddRemote: %v", err)
39+
}
40+
defer repo.RemoveRemote(tmpRemote)
41+
42+
remoteBranch = "remotes/" + tmpRemote + "/" + baseBranch
43+
} else {
44+
remoteBranch = baseBranch
3545
}
36-
defer func() {
37-
repo.RemoveRemote(tmpRemote)
38-
}()
3946

40-
remoteBranch := "remotes/" + tmpRemote + "/" + baseBranch
4147
prInfo := new(PullRequestInfo)
4248
prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch)
4349
if err != nil {

0 commit comments

Comments
 (0)