|
|
|
@ -199,19 +199,19 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com |
|
|
|
|
return nil, fmt.Errorf("ReadFile(%s): %w", headFile, err) |
|
|
|
|
} |
|
|
|
|
commitID := string(commitIDBytes) |
|
|
|
|
if len(commitID) < 40 { |
|
|
|
|
if len(commitID) < git.SHAFullLength { |
|
|
|
|
return nil, fmt.Errorf(`ReadFile(%s): invalid commit-ID "%s"`, headFile, commitID) |
|
|
|
|
} |
|
|
|
|
cmd := commitID[:40] + ".." + pr.BaseBranch |
|
|
|
|
cmd := commitID[:git.SHAFullLength] + ".." + pr.BaseBranch |
|
|
|
|
|
|
|
|
|
// Get the commit from BaseBranch where the pull request got merged
|
|
|
|
|
mergeCommit, _, err := git.NewCommand(ctx, "rev-list", "--ancestry-path", "--merges", "--reverse").AddDynamicArguments(cmd). |
|
|
|
|
RunStdString(&git.RunOpts{Dir: "", Env: []string{"GIT_INDEX_FILE=" + indexTmpPath, "GIT_DIR=" + pr.BaseRepo.RepoPath()}}) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %w", err) |
|
|
|
|
} else if len(mergeCommit) < 40 { |
|
|
|
|
} else if len(mergeCommit) < git.SHAFullLength { |
|
|
|
|
// PR was maybe fast-forwarded, so just use last commit of PR
|
|
|
|
|
mergeCommit = commitID[:40] |
|
|
|
|
mergeCommit = commitID[:git.SHAFullLength] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) |
|
|
|
@ -220,9 +220,9 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com |
|
|
|
|
} |
|
|
|
|
defer gitRepo.Close() |
|
|
|
|
|
|
|
|
|
commit, err := gitRepo.GetCommit(mergeCommit[:40]) |
|
|
|
|
commit, err := gitRepo.GetCommit(mergeCommit[:git.SHAFullLength]) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, fmt.Errorf("GetMergeCommit[%v]: %w", mergeCommit[:40], err) |
|
|
|
|
return nil, fmt.Errorf("GetMergeCommit[%v]: %w", mergeCommit[:git.SHAFullLength], err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return commit, nil |
|
|
|
|