feat(issue-54): backport pr commits without squash (#55)

* feat(issue-54): backport pr commits without squash

fix https://github.com/kiegroup/git-backporting/issues/54

* feat(issue-54): fixed readme
This commit is contained in:
Andrea Lamparelli 2023-07-11 11:22:01 +02:00 committed by GitHub
parent a737aa7c4c
commit c4dbb26c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 990 additions and 145 deletions

View file

@ -13,7 +13,7 @@ export default class GitHubMapper implements GitResponseMapper<PullRequest, "ope
}
}
async mapPullRequest(pr: PullRequest): Promise<GitPullRequest> {
async mapPullRequest(pr: PullRequest, commits?: string[]): Promise<GitPullRequest> {
return {
number: pr.number,
author: pr.user.login,
@ -30,11 +30,16 @@ export default class GitHubMapper implements GitResponseMapper<PullRequest, "ope
sourceRepo: await this.mapSourceRepo(pr),
targetRepo: await this.mapTargetRepo(pr),
nCommits: pr.commits,
// if pr is open use latest commit sha otherwise use merge_commit_sha
commits: pr.state === "open" ? [pr.head.sha] : [pr.merge_commit_sha as string]
// if commits is provided use them, otherwise fetch the single sha representing the whole pr
commits: (commits && commits.length > 0) ? commits : this.getSha(pr),
};
}
private getSha(pr: PullRequest) {
// if pr is open use latest commit sha otherwise use merge_commit_sha
return pr.state === "open" ? [pr.head.sha] : [pr.merge_commit_sha as string];
}
async mapSourceRepo(pr: PullRequest): Promise<GitRepository> {
return Promise.resolve({
owner: pr.head.repo.full_name.split("/")[0],