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

@ -31,20 +31,36 @@ export default class GitHubClient implements GitClient {
return "noreply@github.com";
}
async getPullRequest(owner: string, repo: string, prNumber: number): Promise<GitPullRequest> {
async getPullRequest(owner: string, repo: string, prNumber: number, squash = true): Promise<GitPullRequest> {
this.logger.info(`Getting pull request ${owner}/${repo}/${prNumber}.`);
const { data } = await this.octokit.rest.pulls.get({
owner: owner,
repo: repo,
pull_number: prNumber
pull_number: prNumber,
});
return this.mapper.mapPullRequest(data as PullRequest);
const commits: string[] = [];
if (!squash) {
// fetch all commits
try {
const { data } = await this.octokit.rest.pulls.listCommits({
owner: owner,
repo: repo,
pull_number: prNumber,
});
commits.push(...data.map(c => c.sha));
} catch(error) {
throw new Error(`Failed to retrieve commits for pull request n. ${prNumber}`);
}
}
return this.mapper.mapPullRequest(data as PullRequest, commits);
}
async getPullRequestFromUrl(prUrl: string): Promise<GitPullRequest> {
async getPullRequestFromUrl(prUrl: string, squash = true): Promise<GitPullRequest> {
const { owner, project, id } = this.extractPullRequestData(prUrl);
return this.getPullRequest(owner, project, id);
return this.getPullRequest(owner, project, id, squash);
}
// WRITE